Projecting a point into a line

조회 수: 19 (최근 30일)
Donigo Fernando Sinaga
Donigo Fernando Sinaga 2018년 12월 10일
댓글: Donigo Fernando Sinaga 2018년 12월 19일
How can I project a point (let's say (50,0)) to a line (y = 5.6x - 7.1)?
Thank you.
  댓글 수: 3
Donigo Fernando Sinaga
Donigo Fernando Sinaga 2018년 12월 11일
How can I define a function y = 9.1*x -135.3396 in 'vector' variable? And how can I plot like that?
Adam Danz
Adam Danz 2018년 12월 11일
If you look at the example in the link Mark provided, you'll see that the vector variable is actually a 2x2 matrix of the endpoint coordinates of the line.
Since you already have the slope, intercept, and (x,y) coordinates of another point, I suggest using the method proposed in the answer section.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2018년 12월 11일
편집: Adam Danz 2018년 12월 11일
You need the equation of both perpendicular lines. You already have the equation for the first line. In your line y = 5.6x - 7.1 the slope is 5.6.
The slope of the second line will just be the perpendicular slope of your first line.
m = 5.6;
b = -7.1;
x = 50;
y = 0;
perpSlope = -1/m;
To get the y intercept of the 2nd line you just need to solve for y=mx+b using your point (x,y)
yInt = -perpSlope * x + y;
Now you've got the two linear equations and you need to find out where they intersect. Here we find the x coordinate of the intersection. m and b are the slope and intercept of line 1, perSlope and yInt are the slope and intercept of line 2.
xIntersection = (yInt - b) / (m - perpSlope);
To get the y coordinate of the intersection, we just plug the x coordinate into one of the equations.
yIntersection = perpSlope * xIntersection + yInt;
Now we can plot it out to make sure it looks rights
figure
plot(x,y, 'rx')
hold on
plot(xIntersection, yIntersection, 'ro')
refline(m, b)
refline(perpSlope, yInt)
axis equal
181211 152914-Figure 1.jpg
  댓글 수: 1
Donigo Fernando Sinaga
Donigo Fernando Sinaga 2018년 12월 19일
Thank you very much, your answer really helps me. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by