![]() |
|
|
|
|
|
|
4
16th October 22:00
External User
Posts: 1
|
First of all, I'd clean up the conversion a bit. There's a mess of
"degtorads" everywhere now. Something like this: procedure PolyconicLLtoXY(Lat, Lon: double; var X, Y: double); var LonR, LatR, LatShiftR, SinLat, CotLat: double; begin // Avoid wraparound for longitude while Lon < LonShift - 180 do Lon := Lon + 360; while Lon > LonShift + 180 do Lon := Lon - 360; // Degree to radian conversion LonR := DegToRad(Lon - LonShift); LatR := DegToRad(Lat); LatShiftR := DegToRad(LatShift); // Polyconic projection SinLat := sin(LatR); if abs(LatR) > 1E-6 then begin CotLat := Cotan(LatR); X := CotLat * Sin(LonR * SinLat); end else begin CotLat := 1E-6; X := LonR; end; Y := LatR - LatShiftR + CotLat * (1 - cos(LonR * SinLat)); end; After obtaining X,Y (double precision), you can multiply them by some constant to make them suitable for screen coordinates. Going backwards (XY to LL) is much more difficult because the formula is not linear. You'll have to estimate the LL from XY by making an educated guess using the slopes of the function, then iterate until you're at the exact position. This process is called "Newton-Rhapson approximation with linearization". Consult e.g. Numerical Recipes or other literature to find out exactly how it's done. Here's an idea: procedure PolyconicXYtoLLEst(X, Y, LatBase, LonBase: double; var Lat, Lon, Err: double); var X0, Y0, X1, Y1, T, dFX, dFY, Xest, Yest, Delta: double; begin // Linearization Delta := 1E-3; PolyconicLLtoXY(LatBase, LonBase, X0, Y0); PolyconicLLtoXY(LatBase + Delta, LonBase, X1, T); PolyconicLLtoXY(LatBase, LonBase + Delta, T, Y1); // Estimate based on f(L) ~ F(L0) + dF/dL * (L-L0) dFX := (X1 - X0)/Delta; dFY := (Y1 - Y0)/Delta; Lat := LatBase + dFX * (X - X0); Lon := LonBase + dFY * (Y - Y0); // Error PolyconicLLtoXY(Lat, Lon, Xest, Yest); Err := sqrt(sqr(Xest - X) + sqr(Yest - Y)); end; procedure PolyconicXYtoLL(X, Y: double; var Lat, Lon: double); var LatBase, LonBase, Err: double; begin LatBase := LatShift; LonBase := LonShift; repeat PolyconicXYtoLLEst(X, Y, LatBase, LonBase, Lat, Lon, Err); LatBase := Lat; LonBase := Lon; until Err < 1E-8; end; I didn't test this so there might be (huge) bugs, but this is the general idea. Also note that X,Y is *not* the same yet as the MouseX, MouseY. You'll have to do an additional conversion (linear) for these first. Hope that helps, Nils Haeck www.simdesign.nl |
|
|
6
20th October 13:26
External User
Posts: 1
|
He may be referring to the US Geological Survey Bulletin 1395 by John P.
Snyder. http://pubs.er.usgs.gov/usgspubs/pp/pp1395 This supersedes the old 1532 bulletin that I used for years when I worked for the Survey. It has not only the algorithms but worked examples and even the history of the various projections. Regards, Jim Dodd Onset Computer Corp. |
|
|
|