How to plot point which moves in space

27 Ansichten (letzte 30 Tage)
Giuseppe Giaquinta
Giuseppe Giaquinta am 21 Nov. 2014
Beantwortet: Badr Nasr am 3 Feb. 2017
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.

Akzeptierte Antwort

Mark
Mark am 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 Kommentare
Mark
Mark am 21 Nov. 2014
By the way, you might have a look at the functions comet and comet3!
ranjani raja
ranjani raja am 2 Aug. 2016
can i add a video file into this code and trace the path of moving object_...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Badr Nasr
Badr Nasr am 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.

Kategorien

Mehr zu 2-D and 3-D Plots 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!

Translated by