How to find the point at which a line becomes perpendicular to another line?

2 views (last 30 days)
In the figure, the first two points are:
x = [150 0]
y = [0 150]
So, the line was plotted using
line(x,y,'color','red');
For a given red line, how can you find the point at which a line from the center becomes perpendicular to it? I just need the x value.
You can also think of it as the point where the radius value decreases then increases if you were to follow the red line from the first point to the second.

Accepted Answer

KSSV
KSSV on 29 Jul 2020
Edited: KSSV on 29 Jul 2020
x = [150 0]
y = [0 150]
C = [0 0] ;
% get the line ax+by+c = 0
slope = diff(y)/diff(x) ; % slope
a = slope ;
b = -1 ;
c = y(1)-slope*x(1) ;
% foot of the perpendicular
m = -(a*C(1)+b*C(2)+c)/(a^2+b^2) ;
h = a*m+C(1) ;
k = b*m+C(2) ;
line(x,y,'color','red');
hold on
line([C(1) h],[C(2) k],'color','black')
line([h h],[k 0],'color','black')
plot(h,k,'*g')
  5 Comments
KSSV
KSSV on 30 Jul 2020
This is not issue. This is correct. You need to extend the straight line..basic high school maths
% extend the straight line
x = 0:150 ;
y = -a/b*x-c/b ;
plot(x,y,'-b')

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!