Reputation: 13
I am trying to find an algorithm to derive the 4 angles, from the centre of a rotated ellipse to its extremities. In other words, from the centre to the points where the bounding box touches the ellipse's line.
I have already figured out how to get the bounding box by using:
leftX/rightX = h± sqrt(a*a*cos(PI)*cos(PI) + b*b*sin(PI)*sin(PI))
topY/bottomY = k± sqrt(a*a*sin(PI)*sin(PI) + b*b*cos(PI)*cos(PI))
The above gives me the bounding box AND:
the x of the left and right points
the y of the top and bottom points
But I need the x and y of the left and right points and the x and y of the top and bottom points in order to calculate the angles.
I feel like I missing something simple but could not find it.
The Image illustrates the point at the top of the bounding box.
Upvotes: 1
Views: 515
Reputation: 80187
Let ellipse semiaxes are a, b
, center point is (cx, cy)
and rotation angle is fi
. Then coordinates on ellipse circumference at parameter t
are:
x = a * Cos(t) * Cos(fi) - b * Sin(t) * Sin(fi) + cx
y = a * Cos(t) * Sin(fi) + b * Sin(t) * Cos(fi) + cy
To get extremal points, we can differentiate coordinates by t
and set derivatives to zero
a * Sin(t) * Cos(fi) = - b * Cos(t) * Sin(fi) // dx/dt
a * Sin(t) * Sin(fi) = b * Cos(t) * Cos(fi) // dy/dt
tg(t) = -b/a * Tg(fi)
t(l,r) = Pi * k + Atan(-b/a * Ttg(fi) //left and right, k=0,1
tg(t) = b/a * Ctg(fi)
t(t,b) = Pi * k + Atan(b/a * Ctg(fi)) //top and bottom, k = 0,1
ytop = a * Cos(t(t)) * Sin(fi) + b * Sin(t(t)) * Cos(fi) + cy
and so on
real example for a: 200; b: 100; fi: Pi/6 CW;
generated by quick-made Delphi code
Upvotes: 3