1

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.

enter image description here

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
Niss Green
  • 13
  • 3
  • You can't define a rotation with respect to a *point*, only a direction. – meowgoesthedog May 23 '18 at 11:10
  • 1
    You have not specified how do you define ellipse. – MBo May 23 '18 at 11:30
  • I would find point with defined tangent angle ... can use binary search on single quadrant ... or [Approximation search](https://stackoverflow.com/a/36163847/2521214) on the whole ellipse – Spektre May 24 '18 at 07:19

1 Answers1

3

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

enter image description here

MBo
  • 77,366
  • 5
  • 53
  • 86
  • ...thank you very much for the great answer. As I am not a mathematician I didn't understand all the notations you have used in the breaking down of the original equation (TtG) but the Delphi code was a great help. The only issue I had was that when the fi value was lower than 0 top point became bottom and bottom point became top (same for left and right) but that was easy to fix with a simple condition. Thank you again... – Niss Green May 24 '18 at 16:32
  • Condition check is good, because alternative would be more complex analysis of trigonometric relations. – MBo May 25 '18 at 03:48
  • I spent all of yesterday trying to learn differentiation rules as I loved the way you took an equation and broke it down into the relationships between its components to get the desired points. I understood that your breakdown was based on the fact that the extremities of ellipse tangents would have either a horizontal or vertical tangent. I have tried to work out, based on your analysis above, how to figure out the tangent of any point on the ellipse - but did not succeed. I certainly want to learn more about differentiation now... – Niss Green May 25 '18 at 12:45
  • I've used not extrema of tangents but extrema of coordinates - and note usage of parametric equation (x(t) and y(t)). It is possible also to get equations of tangents and find when they become vertical and horizontal (zero nominator or denominator - essentially the same formulas as I have got) – MBo May 25 '18 at 13:46