I wrote a program that creates an ellipse made of a series of points that can be rotated by an angle, psi, in the xy plane. I am using a rotation matrix to rotate the ellipse.
angle = linspace(0, Num_periods*2*pi, N_frames);
x1 = a1 * cos(angle);
y1 = b1 * sin(angle);
psi=pi/4;
R1 = [cos(psi), -sin(psi); sin(psi), cos(psi)];
ellipse1 = R1 * [x1; y1];
x1_rot = ellipse1(1, :) + x1_0;
y1_rot = ellipse1(2, :) + y1_0;
I am then attempting to add another point which should be located at a distance l_proj_1 from the center in the direction of the short axis, but it is located in different spots relative to the ellipse based on different angles. I also notice that the shape of the ellipse changes sometimes based on the rotation angle, which also should not happen. Is this an error in my code or Matlab and how do I fix either. Thank you.
phi_1 = pi/12; %angle of opening
theta_1 = pi/4; %tilt angle
l_1 = a1/(sin(phi_1));
l_proj_1 = l_1*cos(phi_1)*cos(theta_1);
x0_base_1 = x1_0 + l_proj_1*cos(psi);
y0_base_1 = y1_0 + l_proj_1*sin(psi);
figure;
for i = 1:N_frames
plot(x1_rot(i),y1_rot(i),'o')
axis([0 nx 0 ny])
hold on
pause(.5)
plot(x0_base_1,y0_base_1,'o')
end
I have tried altering the sin’s and cos’s of the bases and the negatives. It is never consistent.
David Merges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.