How can I show this shape moving along the trajectory?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
This only generates the projectile at the end of the trajectory. The shape should start at (0,20) and end at (20,100)and scale from 100% to 25%
function v = problem1
% coordinates of square under one variable square = [0, 4, 4, 0;0, 0, 4, 4];
% generate animation window figure
xmin = -5;
xmax = 25;
ymin = -5;
ymax = 125;
axis equal
axis([xmin xmax ymin ymax])
hold on
%setting your trajectory
t = linspace(0,20,500); % independent variable of your function
trajectory = 1/4*t.^2; % represents y in y = t^2
scale = .99;
for i = 500
% object moving along projectile
h = fill(square(1,:) + t(i),square(2,:) + trajectory(i),'r');
hold on;
% scales the figure from 100% to 25%
fill(scale*square(1,:) + t(i), scale*square(2,:) + trajectory(i), 'r');
hold on;
% do not change below 2 lines, should follow your fill command
v.x(i,:)=get(h,'xdata')';
v.y(i,:)=get(h,'ydata')';
pause(.3)
end
end
1 Kommentar
Antworten (1)
Eugene
am 12 Mai 2014
1. your for loop definition should be
i=1:500
2. you didn't have an algorithm to change the value of scale.
3. scale will not work to shrink the size of the square (i'm assuming that is what you're tyring to do) because the original coordinates do not put the centroid of the square at zero.
Try this:
square = [-2, 2, 2, -2;-2, -2, 2, 2];
figure;
xmin = -5;
xmax = 25;
ymin = -5;
ymax = 125;
axis equal
axis([xmin xmax ymin ymax])
hold on
N = 50;
t = linspace(0,20,N);
trajectory = 1/4*t.^2;
scale = linspace(1,0.25,N);
for i = 1:N
% object moving along projectile
h = fill(square(1,:) + t(i),square(2,:) + trajectory(i),'r');
hold on;
% scales the figure from 100% to 25%
fill(scale(i)*square(1,:) + t(i), scale(i)*square(2,:) + trajectory(i), 'r');
hold on;
pause(0.3)
end
Otherwise if you don't want to have a persistent image then just change the x and y data for the filled object.
square = [-2, 2, 2, -2;-2, -2, 2, 2];
figure;
xmin = -5;
xmax = 25;
ymin = -5;
ymax = 125;
axis equal
axis([xmin xmax ymin ymax])
hold on
N = 50;
t = linspace(0,20,N);
trajectory = 1/4*t.^2;
scale = linspace(1,0.25,N);
h1 = fill(square(1,:) + t(1),square(2,:) + trajectory(1),'r');
h2 = fill(scale(1)*square(1,:) + t(1), scale(1)*square(2,:) + trajectory(1), 'r');
for i = 2:N
% object moving along projectile
set(h1,'XData',square(1,:) + t(i),'YData',square(2,:) + trajectory(i));
hold on;
% scales the figure from 100% to 25%
set(h2,'XData',scale(i)*square(1,:) + t(i),'YData',scale(i)*square(2,:) + trajectory(i));
hold on;
pause(0.3)
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!