Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perpendicular on a line from a given point

How can I draw a perpendicular on a line segment from a given point? My line segment is defined as (x1, y1), (x2, y2), If I draw a perpendicular from a point (x3,y3) and it meets to line on point (x4,y4). I want to find out this (x4,y4).

like image 715
Zinx Avatar asked Nov 28 '09 04:11

Zinx


2 Answers

I solved the equations for you:

k = ((y2-y1) * (x3-x1) - (x2-x1) * (y3-y1)) / ((y2-y1)^2 + (x2-x1)^2) x4 = x3 - k * (y2-y1) y4 = y3 + k * (x2-x1) 

Where ^2 means squared

like image 156
Ray Hidayat Avatar answered Sep 24 '22 02:09

Ray Hidayat


From wiki:

In algebra, for any linear equation y=mx + b, the perpendiculars will all have a slope of (-1/m), the opposite reciprocal of the original slope. It is helpful to memorize the slogan "to find the slope of the perpendicular line, flip the fraction and change the sign." Recall that any whole number a is itself over one, and can be written as (a/1)

To find the perpendicular of a given line which also passes through a particular point (x, y), solve the equation y = (-1/m)x + b, substituting in the known values of m, x, and y to solve for b.

The slope of the line, m, through (x1, y1) and (x2, y2) is m = (y1 - y2) / (x1 - x2)

like image 34
Mitch Wheat Avatar answered Sep 26 '22 02:09

Mitch Wheat