How can I change the camera view point position in an animation so that it is placed on a oscillating mass in a moving reference frame

7 views (last 30 days)
Hello,
I am analyzing two masses connected together with an elastic rope. An external force is applied to one of the masses. This results in both masses oscillating between each other while both moving away away from the starting point.
I have m file that allows me to visualize this oscillation by reading in the X and Y coordinates from a Simulink model that was put together by a collegue. However the viewpoint is such that in the animation I see then entire trajectory as such (from the origin point)
I would like to move the animation viewpoint so that it is centered about the mass center of the two masses. I am not so interested in viewing the path that the entire system takes, just the oscillation of two masses.
Here is the m file:
anim=anim4';
l=0.5;
x1=anim(1,:); %get x and y values for each point mass
y1=anim(2,:);
x2=anim(3,:);
y2=anim(4,:);
figure
axis([-l*1,l*100,-l*1,l*100]);
hold on; %define figure size
j = (1/8:1/4:1)*2*pi; %draw Trolly
xd1 = 1*cos(j);
yd1 = 1*sin(j);
xd2=1*l+l*1.4*cos(j);
yd2=1.2*sin(j);
hd1=fill(xd1,yd1,'r'); %draw circle for each mass in model
hd2=fill(xd2,yd2,'y');
dt=0.01;
for i=1:1/(dt*100):200000 %loop to animate model's movement
set(hd1,'XData',xd1+x1(i),'YData', yd1+y1(i));
set(hd2,'XData',xd2+x2(i),'YData', yd2+y2(i));
xlabel(['Time = ',num2str(i*dt)], 'FontSize',10) %print time for each time-step at bottom of figure
pause(0.2);
end
I'm guessing that I should create the desired origin point (mass center) in simulink and import it into the file, i'm just not sure how!
Please find attached the Simulink model and another m file for inputing parameters into the model.
Thanks

Answers (0)

Categories

Find more on Simulation and Analysis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!