5

I wish to plot an ellipse by scanline finding the values for y for each value of x.

For a plain ellipse the formula is trivial to find: y = Sqrt[b^2 - (b^2 x^2)/a^2]

But when the axes of the ellipse are rotated I've never been able to figure out how to compute y (and possibly the extents of x)

hippietrail
  • 15,848
  • 18
  • 99
  • 158
  • This might be helpful: http://wwwdev.maa.org/joma/Volume8/Kalman/General.html – sje397 Dec 17 '10 at 02:18
  • 1
    If it sticks around, this [link](http://web.archive.org/web/20110913163032/http://web.archive.org/web/20041013054628/http://www.j3d.org/matrix_faq/curvfaq_latest.html#Q23) may prove useful - see the section on ellipses and rendering. – J Trana Oct 10 '15 at 06:05

1 Answers1

18

In parametric form

x[t]= a Cos[t] Cos[psi] - b Sin[t] Sin[psi]

y[t]= b Cos[psi] Sin[t] + a Cos[t] Sin[psi]

Where psi is the rotation angle, and a and b the semi-axes.

The parameter t goes from 0 to 2 Pi.

Or if you prefer in Cartesian non-parametric form:

(a x^2+b y^2) Cos[psi]^2 + (b x^2 +a y^2) Sin[psi]^2 + (a-b) x y Sin[2 psi]==1

Which yields to the two possible solutions for y[x], equivalent to the two solutions for the square root in the non-rotated case:

y -> (-(Sqrt[2]*Sqrt[a + b - 2*a*b*x^2 + (-a + b)*Cos[2*psi]]) + 
       (-a + b)*x*Sin[2*psi]) / (2*(b*Cos[psi]^2 + a*Sin[psi]^2))

y ->   (Sqrt[2]*Sqrt[a + b - 2*a*b*x^2 + (-a + b)*Cos[2*psi]] + 
       (-a + b)*x*Sin[2*psi])/ (2*(b*Cos[psi]^2 + a*Sin[psi]^2))

Well, you asked for it :)

Those functions give:

enter image description here

And the limits for x are:

LimitX= +/- Sqrt[a + b + (-a + b)*Cos[2*psi]]/(Sqrt[2]*Sqrt[a]*Sqrt[b])
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190