How to generate lines between a fixed point and evenly spaced points on a line
Mostrar comentarios más antiguos
I want to generate lines between a fixed point and evenly distributed points and calculate the length of each line. The reason for this implementation is to see how the length of the line (which represents the length of a cable) changes. Here is the code that I have written that;
1) Creates an evenly distributed points on a line (which is the path that the end of the cable will follow)
2) Creates the initial and final line between the origin(where the cable is winded and released from a pulley)
clc;
xlim([0, 100]);
ylim([0, 100]);
hold on
Ax=0;
Ay=0;
x=40;
y=20;
plot([Ax x], [Ay y],'b')
hold on
x1=20;
y1=80;
plot([Ax x1], [Ay y1],'g')
hold on
L1 = sqrt((x1-x)^2 + (y1-y)^2);
m = abs(y1-y)/abs(x1-x);
if x<x1
X=x:5:x1;
else
X=x1:5:x;
n=length(X);
Y=m*abs(X-x)+y;
for k=1:n
plot(X,Y,'-*')
end
end
hold off

There should be 5 lines in the given figure and the lengths of those lines should be calculated by the use of the equation (code line:22) (L1 = sqrt(...))
Also, (if this knowladge is in any use) the spacing of the points will be much smaller in the real implementation.
Thank you for your time,
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
