views:

344

answers:

1

Hi all.

I have a rectangle in .NET in which I draw an ellipse.

I know the width, height and center point of that rectangle.

Of course the center point of the rectangle is also the center point of the ellipse.

I know how to calculate a point on a circle, however I have no clue about an ellipse.

I have those parameters and an angle, i need the point on the ellipse, can someone post the formula?

I saw somewhere you need to calculate 2 points in which 2 radii will go, the sum of the radii will be fixed and they will change in size accordingly.

I don't know how to do that, I only have the rectangle height, width and center point and of course the angle I wish to find the point at.

thanks for any help Shlomi

+2  A: 

You can use the canonical form in polar coordinates for your problem where the width and height of a rectangle is w and h respectively.

alt text

alt text

where t is an angle in radians, a is w/2 and b is h/2

So to plot your ellipse, all you have to do is vary t from 0 to 360 degrees (in radians so that's 0 and 2pi) and depending on how you space out t, you get the points on the ellipse.

Since your rectangle is not centered at the origin, you will have to offset it by the coordinates of the center of the rectangle, say, (Cx,Cy)

const double C_x = 10, C_y = 20, w = 40, h = 50;
for(double t = 0; t <=2*pi; t+=0.01)
{
   double X = C_x+(w/2)*cos(t);
   double Y = C_y+(h/2)*sin(t);
   // Do what you want with X & Y here 
}
Jacob
Thank`s, that did the trick.
Shlomi Assaf