Tuesday, May 29, 2007

Algorithm for drawing a circle

A starting location with longitude, clong, and latitude, clat all in decimal degrees.
The radius, r, in km of the final circle.
Points that define the circle are 0, pi/10, 2pi/10, 3pi/10, 4pi/10, 5pi/10, 6pi/10, 7pi/10, 8pi/10, 9pi/10, pi, 11pi/10, 12pi/10, 13pi/10, 14pi/10, 15pi/10, 16pi/10, 17pi/10, 18pi/10, 19pi/10, angles from the central point with radius, r.

For each of 20 points that define the circle:
theta, the angle in radians, that changes from the horizontal for each point.

1. Calculate (x, y), the cartesian point that is x km east, y km north relative to the central point.
*a. x = r*cos(theta)
*b. y = r*sin(theta)

2. Calculate y'', the latitude of the point in decimal degrees.
*a. y' = y/111.12km/degree
*b. y'' = clat + y'

3. Calculate x'', the longitude of the point in decimal degrees.
*a. x' = x/[(111.320 + .373*sin(y''))*cos(y'')]/degree
*b. x'' = clong + x'

--tested this --
This doesn't quite work. The 'circle' isn't so much a circle but a flat heart shaped thing. If I use clat instead of y'' in the calculation of x', it looks more symmetrical, but it is still a bit stretched in the vertical direction. Here's the KML. Hmmm...

No comments: