Forum Moderators: open

Message Too Old, No Replies

Calculating an ellipse

         

appi2

12:49 pm on Oct 23, 2006 (gmt 0)

10+ Year Member



Ok i'm stuck, trying to find how to get if the mouse is inside an ellipse

From a bit of basic math

An ellipse centered on (0,0)
Major access A
Minor access B
Covers all points (X.Y)

if ( ( (Math.pow(X,2)) / (Math.pow(A,2)) ) + ( (Math.pow(Y,2)) / (Math.pow(B,2)) ) > 1 ) {

// we are outside the ellipse

}

Problem is
What if its centered on (500,500)
and the ellipse is rotated 90 Deg (as in an egg in an eggcup)?

jalarie

2:05 pm on Oct 23, 2006 (gmt 0)

10+ Year Member



An ellipse centered on (K,L)
X axis length A
Y axis length B
Covers all points (X.Y)


if ( ( (Math.pow((X-K),2)) / (Math.pow(A,2)) )
+ ( (Math.pow((Y-L),2)) / (Math.pow(B,2)) ) > 1 ) {
// we are outside the ellipse
}

appi2

2:30 pm on Oct 23, 2006 (gmt 0)

10+ Year Member



Thanks, just worked out same.
The rotation is the main bit I need.

Rotating each point (x,y) 90 deg is (y,x)

So ..... arrrgh mind melt

appi2

6:41 pm on Oct 23, 2006 (gmt 0)

10+ Year Member



if ( ( (Math.pow((Y-L),2)) / (Math.pow(A,2)) )
+ ( (Math.pow((X-K),2)) / (Math.pow(B,2)) ) > 1 ) {
// we are outside the ellipse
}

SOLVED

jalarie

12:50 pm on Oct 24, 2006 (gmt 0)

10+ Year Member



You're working too hard. Set "A" and "B" to whatever they need to be and the equation will do the rest. If the "A" value is greater than the "B" value, then the ellipse will have its major axis along the "X" axis. If the "B" value is greater than the "A" value, then the major axis will be in line with the "Y" axis. If both values are the same, the result will be a circle.