How to generate lines between a fixed point and evenly spaced points on a line
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Fazil Doruk Inanc
le 3 Mai 2020
Réponse apportée : Thiago Henrique Gomes Lobato
le 3 Mai 2020
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,
0 commentaires
Réponse acceptée
Thiago Henrique Gomes Lobato
le 3 Mai 2020
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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!