You are given a points (x1, y1, z1) and a plane a * x + b * y + c * z + d = 0. The task is to find the perpendicular(shortest) distance between that point and the given Plane.
Input: x1 = 4, y1 = -4, z1 = 3, a = 2, b = -2, c = 5, d = 8
Output: Perpendicular distance is 6.78902858227
Input: x1 = 2, y1 = 8, z1 = 5, a = 1, b = -2, c = -2, d = -1
Output: Perpendicular distance is 8.33333333333
Approach: The perpendicular distance (i.e shortest distance) from a given point to a Plane is the perpendicular distance from that point to the given plane. Let the co-ordinate of the given point be (x1, y1, z1)
and equation of the plane be given by the equation a * x + b * y + c * z + d = 0, where a, b and c are real constants.
The formula for distance between a point and Plane in 3-D is given by:
Distance = (| a*x1 + b*y1 + c*z1 + d |) / (sqrt( a*a + b*b + c*c))
Below is the implementation of the above formulae:
# Python program to find the Perpendicular(shortest) # distance between a point and a Plane in 3 D. import math # Function to find distance def shortest_distance(x1, y1, z1, a, b, c, d): d = abs((a * x1 + b * y1 + c * z1 + d)) e = (math.sqrt(a * a + b * b + c * c)) print("Perpendicular distance is"), d/e # Driver Code x1 = 4 y1 = -4 z1 = 3 a = 2 b = -2 c = 5 d = 8 # Function call shortest_distance(x1, y1, z1, a, b, c, d)
Perpendicular distance is 6.78902858227
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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Angle between two Planes in 3D
- Haversine formula to find distance between two points on a sphere
- Program to find equation of a plane passing through 3 points
- Perpendicular distance between a point and a Line in 2 D
- Mirror of a point through a 3 D plane
- Program to determine the octant of the axial plane
- Shortest distance between a Line and a Point in a 3-D plane
- Program to find the Volume of a Triangular Prism
- Program to check congruency of two triangles
- Bresenham’s Algorithm for 3-D Line Drawing