How to plot point which moves in space
20 views (last 30 days)
Show older comments
Good morning , I need to plot the trajectory of a point. The only infos about the point i know, is the set of three coordinates that the point occupies in 4 different instants (defined t1 , t2 , t3, t4) . Suppose that I am in possession of three vectors of coordinates: X=[x1,x2,x3,x4]; Y=[y1,y2,y3,y4]; Z=[z1,z2,z3,z4]; Knowing that xi, yi , zi are the coordinates of the point at time (ti), i would like to plot a point (and its path) that moves with a speed set by me (or at least slowly enough to allow me to see the trajectory ) , from the first through fourth set of coordinates (passing both for second and third set obviously). I would like to draw, in practice , the broken line described by the point that moves between the four sets of coordinates .
Hoping to have been clear enough i thank anyone who can give me some tips.
0 Comments
Accepted Answer
Mark
on 21 Nov 2014
Hi,
I would suggest that you interpolate the coordinates such that you get, say, 100 steps in between the points. You can then plot the point and use getframe to grab the frame and movie to play the movie.
Here is a short example. I first interpolate between two points, then create a rectangle, from which I change the Position object for each time step:
x = [0 1];
y = [1 1];
numSteps = 100;
% Calculate the trajectory by linear interpolation of the x and y coordinate.
trajectory = [ linspace(x(1),x(2),numSteps); linspace(y(1),y(2),numSteps) ];
% Make figure with axes.
figure; axis square;
set(gca,'XLim',[-2 2], 'YLim', [-2 2]);
% Make the moving point object, starting at point [x(1), y(1)].
movingPoint = rectangle( 'Parent', gca, 'Position', [x(1), y(1), .1, .1], 'Curvature', [1 1] );
% Make the frames for the movie.
for frameNr = 1 : numSteps
set( movingPoint, 'Position', [trajectory(1,frameNr), trajectory(2,frameNr), .1, .1] );
frames(frameNr) = getframe;
end
Play the movie using:
movie(frames);
4 Comments
ranjani raja
on 2 Aug 2016
can i add a video file into this code and trace the path of moving object_...
More Answers (1)
Badr Nasr
on 3 Feb 2017
hello dears plz hepe how can i Compute the joint space trajectory q1(t); q2(t) for the work space tra- jectory that describes a circle x(t) = x0 -r cos(pi*t=10); y(t) = y0 +r sin(pi*t=10); t is [0,20] for x0 = 60, y0 = 100, r = 40 using the inverse kinematics method ikine of the SerialLink object. First generate the corresponding homogeneous transfor- mations that correspond to the end effector trajectory with transl. Compute the inverse kinematics for these transformations with ikine, you need to specify the arguments poses, initial joint configuration q1(0) = 0.55; q2(0) = 2.0 and the mask [1 1 0 0 0 0] to restrict inverse kinematics to the x and y components as the arm only has two degrees of freedom. A zero entry in the mask ignores the corresponding workspace dimension, in our case z-translation and rotations along x; y; z-axes.
and Generate a fgure with three subplots End effector trajectory x; y as a function of the time vector t Joint trajectory q1; q2 as a function of the time vector t End effector path x; y plotting x versus y.
0 Comments
See Also
Categories
Find more on Scatter Plots 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!