Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I want to check an element if it's in a circle in my browser. I know the circle formula from my high school:

enter image description here

But I'm not sure if it's same in browser XY system too. Because browsers zero coordinate is on left top of the page and from there to right is positive x axis and to bottom is positive y axis.

Browser XY

For example in this picture point c have positive x and y. Please optimize the circle formula for this system and also give me the correct formula for a circle centered in c = (200,200) with 150 radius.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

For any affine change of variables $x \to a_1 x + a_2 y + a_3$ and $y \to b_1 x + b_2 y + b_3$ the equation of the circle $(x-x_0)^2 + (y-y_0)^2 = r^2$ translates into $$ ( a_1 x + a_2 y + a_3 - x_0)^2 + (b_1 x + b_2 y +b_3 - y_0)^2 = r^2 $$ Expanding $$ \begin{eqnarray} & & x^2 ( a_1^2 + b_1^2) + y^2 (a_2^2 + b_2^2) + 2 x y ( a_1 a_2 + b_1 b_2) \\ && + 2 x ( a_1 (a_3 - x_0) + b_1 (b_3-y_0) ) + 2 y ( a_2 (a_3 - x_0) + b_2 (b_3-y_0) ) \\ && + (a_3-x_0)^2 + (b_3 - y_0)^2 = r^2 \end{eqnarray} $$ Now, choosing $a_1$, $a_2$ and $b_1$ and $b_2$ so that $$ a_1^2 + b_1^2 = a_2^2 + b_2^2 = 1 \qquad a_1 a_2 + b_1 b_2 = 0 $$ and completing squares will again arrive at $(x-\hat{x}_0)^2 + (y-\hat{y}_0)^2 = \hat{r}^2$.

share|improve this answer

Even with the $y$-coordinate flipped, the equation for your circle is still $$ (x-200)^2+(y-200)^2=150^2\tag{1} $$ In the normal coordinates, this would be the circle of radius $150$ and center $(200,-200)$ so the equation with flipped $y$-coordinate would be $$ (x-200)^2+(-y-(-200))^2=150^2\tag{2} $$ Equation $(2)$ is the same as equation $(1)$ since $(-1)^2=1$.

share|improve this answer
    
Why -y in second statement? –  Mohsen Sep 21 '11 at 0:59
    
@Mohsen: He's demonstrating that changing the signs of $y$-coordinates has no effect here. –  J. M. Sep 21 '11 at 3:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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