- 21

- 0

**parametrizing an ellipse -- what am I doing wrong?**

I have the width, height, and center point of the ellipse. I have an angle/vector from the center point and I want to know at what point it intersects the ellipse perimeter. Based on this wikipedia article:

http://en.wikipedia.org/wiki/Ellipse

I implemented this formula (Flash ActionScript):

x = center.x + ellipse.width/2 * Math.cos(angleR)

y = center.y + ellipse.height/2 * Math.sin(angleR)

angleR is achieved like this:

Math.atan2(p2.y - p1.y, p2.x - p1.x);

p1 is the ellipse center point, and p2 is the X object that follows your cursor in the Flash example.

Here is the result:

http://abeall.com/files/temp/ellipse.swf

It is only correct at 90 degree angles. What am I doing wrong?

To describe what's going wrong in the Flash example a little more clearly:

The X which follows your cursor represents my a target point to create the vector/angle from the ellipse center point. The blue line is drawn and the angle is measured at the top as radian(left) and degree(right). The radian value as shown there is what is used in the equation above, angleR. The resulting x,y point is shown in the Flash as a small blue box on the ellipse perimeter. As you can see, it does not line up with the original vector. If I draw a red line between the center and the perimeter x,y and measure the angle, the resulting values are shown under "Resulting Angle" in the Flash, again with radian to the left and angle to the right. The results just doesn't line up.

NOTE: when the shape is a circle, it works at every angle. The more elliptical it is, the less accurate the areas between 90 degrees become.

Last edited: