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 th开发者_Go百科e axes of the ellipse are rotated I've never been able to figure out how to compute y (and possibly the extents of x)
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:
And the limits for x are:
LimitX= +/- Sqrt[a + b + (-a + b)*Cos[2*psi]]/(Sqrt[2]*Sqrt[a]*Sqrt[b])
精彩评论