MATLAB: Get line equation from different lines met at one point

line equation

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.

Best Answer

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