BenJacob
BenJacob

Reputation: 987

Scaling a rotated ellipse

I have a function that draws an ellipse respecting some major axis (vx) and minor axis (vy) scales rotated clockwise by an angle a. I would like to adjust it so that the unrotated ellipse satisfies the equation:

(x / vx)^2 + (y / vy)^2 = s

For some value s which is passed in.

function [] = plotellipse(cx, cy, vx, vy, s, a)
    t = linspace(0, 2 * pi);
    x = cx + vx * cos(t) * cos(-a) - vy * sin(t) * sin(-a);
    y =  cy + vy * sin(t) * cos(-a) + vx * cos(t) * sin(-a);
    plot(x,y,'y-');

Upvotes: 0

Views: 1007

Answers (1)

Mad Physicist
Mad Physicist

Reputation: 114290

The usual equation for an ellipse, which you have implemented correctly, is

\left(\frac{x}{vx}\right)^2+\left(\frac{y}{vy}\right)^2=1

To reduce the desired equation to the same form, divide through by s:

\left(\frac{x}{vx\sqrt{s}}\right)^2+\left(\frac{y}{vy\sqrt{s}}\right)^2=1

Now x and y become

vxs = vx / sqrt(s)
vys = vy / sqrt(s)
x = cx + vxs * cos(t) * cos(-a) - vys * sin(t) * sin(-a);
y =  cy + vys * sin(t) * cos(-a) + vxs * cos(t) * sin(-a);

Upvotes: 1

Related Questions