Given a point P in 2-D plane and equation of a line, the task is to find the foot of the perpendicular from P to the line.
Note: Equation of line is in form ax+by+c=0.
Input : P=(1, 0), a = -1, b = 1, c = 0 Output : Q = (0.5, 0.5) The foot of perpendicular from point (1, 0) to line -x + y = 0 is (0.5, 0.5) Input : P=(3, 3), a = 0, b = 1, c = -2 Output : Q = (3, 2) The foot of perpendicular from point (3, 3) to line y-2 = 0 is (3, 2)
Since equation of the line is given to be of the form ax + by + c = 0. Equation of line passing through P and is perpendicular to line. Therefore equation of line passing through P and Q becomes ay – bx + d = 0. Also P passes through line passing through P and Q, so we put coordinate of P in the above equation:
ay1 - bx1 + d = 0 or, d = bx1 - ay1
Also, Q is the intersection of the given line and the line passing through P and Q. So we can find the solution of:
ax + by + c = 0 and, ay - bx + (bx1-ay1) = 0
Since a, b, c, d all are known we can find x and y here as:
Below is the implementataion of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the foot of perpendicular of a point in a 3 D plane
- Perpendicular distance between a point and a Line in 2 D
- Shortest distance between a Line and a Point in a 3-D plane
- Slope of perpendicular to line
- Length of the perpendicular bisector of the line joining the centers of two circles
- Find mirror image of a point in 2-D plane
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Number of jump required of given length to reach a point of form (d, 0) from origin in 2D plane
- Mirror of a point through a 3 D plane
- Distance between a point and a Plane in 3 D
- Check if a line at 45 degree can divide the plane into two equal weight parts
- Count of intersections of M line segments with N vertical lines in XY plane
- Count of Right-Angled Triangle formed from given N points whose base or perpendicular are parallel to X or Y axis
- Find an Integer point on a line segment with given two ends
- Program to find the mid-point of a line
- Find the other end point of a line with given one end and mid
- Program to find equation of a plane passing through 3 points
- Find the equation of plane which passes through two points and parallel to a given axis
- Program to find X, Y and Z intercepts of a plane
- Rotation of a point about another point in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.