Plotting a line between two points
2 views (last 30 days)
Show older comments
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;
0 Comments
Answers (2)
Mischa Kim
on 23 Mar 2014
Edited: Mischa Kim
on 23 Mar 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 Comment
Mischa Kim
on 23 Mar 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.
See Also
Categories
Find more on Annotations 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!