1

Based on the user's location I want to draw a circle that passes a given coordinate X (so the radius will be the distance from the user location to X).

Based on this https://smilebasicsource.com/forum?fpid=7022

I managed to get a solution that works, but when I check the points I get a ellipse and not a circle.

Can anyone tell me why?

//The following code rotates with 1 degree each time its run. after 360 times I get the circle (ellipse) below.

var R = 0.0174533; //1 degree
var X = World.obj.locations[0].longitude;
var Y = World.obj.locations[0].latitude;
var CX =  World.userLocation.lon;
var CY =  World.userLocation.lat;


var C = Math.cos(R);
var S = Math.sin(R);

var DX = X - CX;
var DY = Y - CY;

var NX = CX+DX*C-DY*S;
var NY = CY+DX*S+DY*C;

World.obj.locations[0].latitude = NY;
World.obj.locations[0].longitude = NX;

google map with generated points

  • Welcome to GIS SE! As a new user be sure to take the Tour to learn about our focussed Q&A format. You appear to have created two accounts which inevitably leads to a frustrating experience for you, potential answerers and reviewers so please follow these instructions ASAP to merge your accounts. – PolyGeo Aug 12 '16 at 5:36
1

You are calculating the circle points with longitude and latitude. This will work near the equator only. Closer to the poles, the length of one degree of longitude decreases down to zero.

You should better do the same in meters, e.g. the Google Mercator projection that your basemap is projected in.

As a workaround, you could multiply the longitudes X and CX with the cosinus of latitude, and divide NX by it to get back to real longitudes, as mentioned here: Calculating longitude length in miles?

  • Web Mercator is terribly distorted. Using a local projected coordinate system, even UTM, will be better, but not perfect. – mkennedy Aug 11 '16 at 19:16
  • hmm do you have some hints in the right directions about how this can be implemented (what do I need to change)? The two points will never be far from each other. We are talking 10-200 meter in range. So I would think the distortion would not be that bad or? – user80643 Aug 11 '16 at 19:58
  • @mkennedy I know that, but sticking to the basemaps CRS isn't a bad idea. – AndreJ Aug 12 '16 at 5:33
  • @user80643 See my extended answer. – AndreJ Aug 12 '16 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.