Plotting a line between two points

조회 수: 4 (최근 30일)
Scott
Scott 2014년 3월 23일
댓글: Mischa Kim 2014년 3월 23일
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;

답변 (2개)

Mischa Kim
Mischa Kim 2014년 3월 23일
편집: Mischa Kim 2014년 3월 23일
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
Mischa Kim
Mischa Kim 2014년 3월 23일
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.

댓글을 달려면 로그인하십시오.


Scott
Scott 2014년 3월 23일
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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by