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

前端 未结 1 974
粉色の甜心
粉色の甜心 2021-02-06 12:04

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 i

相关标签:
1条回答
  • 2021-02-06 12:27

    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 
    }
    
    0 讨论(0)
提交回复
热议问题