Plotting a line between two points

4 Ansichten (letzte 30 Tage)
Scott
Scott am 23 Mär. 2014
Kommentiert: Mischa Kim am 23 Mär. 2014
I am writing a script to simulate a mechanism. I am up to a point where I have x and y co-ordinates for each of the joints. I now need to plot lines between each point, for example between O2 and A. I attempted to put the x and y co-ordinates of each point into a matrix, but was having difficulties with that. Does anyone have any suggestions? Cheers.
O2_x(i) = 0;
O2_y(i) = 0;
A_x(i) = (link_2*cos(theta_2(i)));
A_y(i) = (link_2*sin(theta_2(i)));
B_x(i) = (A_x(i) + (link_3*cos(theta_3(i))));
B_y(i) = (A_y(i) + (link_3*sin(theta_3(i))));
O4_x(i) = 3.79;
O4_y(i) = 0;

Antworten (2)

Mischa Kim
Mischa Kim am 23 Mär. 2014
Bearbeitet: Mischa Kim am 23 Mär. 2014
Scott, did you try it this way?
xi = [O2_x(i) A_x(i) B_x(i) O4_x(i)];
yi = [O2_y(i) A_y(i) B_y(i) O4_y(i)];
plot(xi, yi)
For two points you'd use
xi = [O2_x(i) A_x(i)];
yi = [O2_y(i) A_y(i)];
  1 Kommentar
Mischa Kim
Mischa Kim am 23 Mär. 2014
Check out:
x = 0:0.1:pi;
y = sin(x);
t = 0:0.1:10;
for ii = 1:numel(t)
plot(x,y*sin(t(ii)))
axis equal
ylim([-1 1])
F(ii) = getframe;
end
Please add follow-up questions and comments as comments, not answers.

Melden Sie sich an, um zu kommentieren.


Scott
Scott am 23 Mär. 2014
Hi Mischa, thanks so much.
I did try something similar, but I was putting an (i) out the front of the xi term. That makes complete sense now, thank you.
If you don't mind me asking, do you know how I would animate each iteration of the for loop?
Cheers, Scott

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by