Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Parametrizing an ellipse - what am I doing wrong?

  1. Jan 9, 2008 #1
    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:

    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:

    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: Jan 9, 2008
  2. jcsd
  3. Jan 9, 2008 #2
    what are the p2 and p1?
  4. Jan 9, 2008 #3
    Oops, pardon me, in this case p1 is the ellipse center point, and p2 would be the X object that follows your cursor in the Flash example.
  5. Jan 9, 2008 #4
    well in the one case you have a vector whose endpoint has gone a certain distance, say some number of radians around the ellipse. and you have another vector whose angle with a line going through the center is the same as the distance the other point has gone around the ellipse. i'm not positive these lines have to be parallel.

    to be explain better, an example:

    when the blue line makes an angle of pi/4, that means the blue box has gone pi/4 radians around the ellipse. lets assume the ellipse is centered at the origin. that means it's coordinates are (acos(pi/4),bsin(pi/4). however, the angle of this vector is not in the general case equal to the angle of the blue line. however in the case of the circle, it would be.
    Last edited: Jan 9, 2008
  6. Jan 9, 2008 #5
    I think I figured it out. I plotted points around the perimeter and realized that the parameter angleR in the parametric equation for an ellipse doesn't correspond to the angle from the center to the point (x,y) on the ellipse. So I looked for another equation and found this to be the answer:

    r = 0.5 / sqrt( (cos(angleR)/ellipse.width)^2 + (sin(angleR)/ellipse.height)^2 )
    x = center.x + r*cos(angleR)
    y = center.y + r*sin(angleR)

    Seems to work:
    (clear browser cache)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook