Get line equation from different lines met at one point

10 vues (au cours des 30 derniers jours)
NURFATIN NADIA
NURFATIN NADIA le 23 Mar 2018
Commenté : NURFATIN NADIA le 24 Mar 2018
Dear all, I am new to MATLAB. I've plotted straight lines connecting centroid of one particular object (i.e. centroidA) to other objects(each with different centroids, i.e. centroidB) surrounding it. From my workspace, centroidA is 22x1cell. How can I get equation of all these lines so I can extend each of them to my desired length?
Thank you in advance.

Réponse acceptée

KSSV
KSSV le 23 Mar 2018
Check the below example code:
P0 = rand(2,1) ; % Two random points through which line passes
P1 = rand(2,1) ;
%%Equation of line
x = [P0(1) P1(1)] ; % GEt x coordinates
y = [P0(2) P1(2)] ; % Get y coordinates
p = polyfit(x,y,1) ; % Fit a line through P0 and P1, it gives slope and y-intercept
%%Extend length of line
x1 = linspace(-1,+1);
y1 = polyval(p,x1);
figure
plot(x,y,'O-r')
hold on
plot(x1,y1,'b')
hold off
  3 commentaires
KSSV
KSSV le 23 Mar 2018
P0 will be centroid....run a loop for P1.
NURFATIN NADIA
NURFATIN NADIA le 24 Mar 2018
Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices 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!

Translated by