finding a point on an ellipse circumference which is inside a rectangle having center point, height and width?

荒凉一梦 提交于 2020-01-12 03:53:32

问题


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


回答1:


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.

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 
}


来源:https://stackoverflow.com/questions/2781206/finding-a-point-on-an-ellipse-circumference-which-is-inside-a-rectangle-having-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!