Get line equation from different lines met at one point
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
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
Plus de réponses (0)
Voir également
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!