2
$\begingroup$

I'm a developer, and I'm developing an app on Google Maps. At the moment, I'm trying to draw a circle on the map.

For getting all the points I need, I'm using the following formula:

\begin{equation} y=y_c\pm\sqrt{r^2-(x-x_c)^2} \end{equation}

but I get an ellipse, not a circle.

enter image description here

Did I mistake the formula?

Or I need to search the error in my code?

Thanks in advance.

UPDATE I found that I have to draw an ellipse, because of the different axis scale. At the moment I can find four correct points (north, east, south, west).

$\endgroup$
  • 1
    $\begingroup$ At 45 degrees north longitude lines are much closer together than latitude lines. Perhaps this is what is compressing your circle horizontally. $\endgroup$ – jbuddenh Jul 21 '15 at 15:36
  • $\begingroup$ A problem that also Andreas Blass noticed. I suppose that now I need to work with an ellipse. I have an update: I can get four points (north, south, east, west) and they are all correct. Now, can I get the right equation of the ellipse, by using these four points? Do I need more or less points? $\endgroup$ – studente100 Jul 21 '15 at 15:54
  • $\begingroup$ You have enough with three points, giving the center and the half-axis lengths. $\frac1{a^2}(x-x_c)^2+\frac1{b^2}(y-y_c)^2=1$. $\endgroup$ – Yves Daoust Jul 21 '15 at 16:23
  • $\begingroup$ This is also relevant: Discretize a circle on a sphere with a given center and radius (but it may be more than you need for your application). $\endgroup$ – David K Jul 21 '15 at 19:28
  • $\begingroup$ About the last comment, yes, maybe it's something more. I will try your formula, I suppose I have to solve a system of three of these equations. I will put the center, and two other points I found. $\endgroup$ – studente100 Jul 22 '15 at 7:20
2
$\begingroup$

One way to accidentally get an ellipse instead of a circle is to have different length scales on the two coordinate axes.

| cite | improve this answer | |
$\endgroup$
1
$\begingroup$

Google Maps uses the Mercator projection system, which distorts the coordinates vertically, proportionally to the secant of the latitude.

On the picture I measure that the ellipse is about $482\times689$ pixels, i.e. has an aspect ratio of $0.7$, which corresponds to a latitude of $45.6°$. The true latitude of Milano is $45°28'=45.46°$. Not so bad...

| cite | improve this answer | |
$\endgroup$
0
$\begingroup$

The general equation of an circle is $(x-x_c)^2+(y-y_c)^2=r^2$. This can be rewritten to your equation. I think that there is a mistake in your code. In particular, check whether you don't divide of multiply $x$ by anything, that will result in an ellipse.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Ok, thank you very much. I will check and let you know. $\endgroup$ – studente100 Jul 21 '15 at 15:30

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.