How to generate lines between a fixed point and evenly spaced points on a line

4 vues (au cours des 30 derniers jours)
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,

Réponse acceptée

Thiago Henrique Gomes Lobato
If I understood your question right you mean something like this?
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;
plot(X,Y,'-*')
for k=2:n-1
plot([Ax X(k)], [Ay Y(k)],'k')
end
Distances = sqrt( (X-Ax).^2+(Y-Ay).^2 )
end
hold off
Distances =
82.4621 69.6419 58.3095 49.4975 44.7214

Plus de réponses (0)

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by