I have a nice implementation of a spring that can move along an axis X.
plot (N - number of spring turns):
t=0:0.01:20;
alpha=0:0.01:2*pi;
N=10;
h=4;
R=0.25;
for i=1:N
Xpr(i)=(i-1)*1/(N-1);
if i==1
Ypr(i)=2.5*R+h;
elseif i==N
Ypr(i)=2.5*R+h;
else
Ypr(i)=2.5*R+h/2+h/4*(-1)^i;
end
end
Spring=plot(Xpr*2,Ypr);
animation:
t=0:0.01:20;
alpha=0:0.01:2*pi;
x0=1;
x=x0+0.3*cos(alpha);
for i=1:length(t)
set(Spring,'Xdata',Xpr*x(i));
pause(0.01);
end
I need to spin this spring clockwise on plane. One end is fixed. How to do it?
There a lot ways have been tried. None of them is worked. Idea of animation's implementation was in using Rotate matrix. Like this:
function L = Rot2D (Vers, phi)
L(1,:) = Vers(1,:)*cos(phi)-Vers(2,:)*sin(phi)
L(2,:) = Vers(1,:)*sin(phi)+Vers(2,:)*cos(phi)
endfunction
Then pack each of the coils of the spring into a vector:
N=10;
h=4;
R=0.25;
for i=1:N
Xpr(i)=(i-1)*1/(N-1);
if i==1
Ypr(i)=2.5*R+h;
SpringVector=[Xpr(i);Ypr(i)];
elseif i==N
Ypr(i)=2.5*R+h;
newElem=[Xpr(i);Ypr(i)];
SpringVector=[SpringVector; newElem];
else
Ypr(i)=2.5*R+h/2+h/4*(-1)^i;
newElem=[Xpr(i);Ypr(i)];
SpringVector=[SpringVector; newElem];
end
end
After that invocation Rot2D has shown nothing:
y0=1;
y=y0+cos(alpha);
N=10;
for i=1:N
phi=-acos(y(i)-1);
RotArrSpring=Rot2D(SpringVector,phi);
set(Spring,'XData', RotArrSpring(1,:)*x(i), 'YData', RotArrSpring(2,:)*y(i));
pause(0.01);
end
How to solve this problem?