Plotting a line between two points

2 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by