iosdevnyc
iosdevnyc

Reputation: 1871

Calculating Coordinates of Circle provided radius and center

I am looking to calculate lat and lng points of a circular provided a center point and radius. The code I currently have is below, the result is always an oval looking shape and not a circle.

            double val = 2 * Math.PI / points;
            for (int i = 0; i < points; i++)
            {
                double angle = val * i;
                double newX = (dCenterX  + radius * Math.Cos(angle));
                double newY = (dCenterY + radius * Math.Sin(angle));
            }

Upvotes: 0

Views: 150

Answers (1)

MBo
MBo

Reputation: 80187

You can calculate these points using formula for Destination point given distance and bearing from start point

JavaScript:     (all angles  in radians) 

var φ2 = Math.asin( Math.sin(φ1)*Math.cos(d/R) +
                    Math.cos(φ1)*Math.sin(d/R)*Math.cos(brng) );

var λ2 = λ1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(φ1),
                         Math.cos(d/R)-Math.sin(φ1)*Math.sin(φ2));

where φ is latitude, λ is longitude, θ is the bearing (clockwise from north), δ is the angular distance d/R; d being the distance travelled, R the earth’s radius

Upvotes: 1

Related Questions