Distance between a point and a Plane in 3 D

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.

Examples :

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)      
Output:

Perpendicular distance is 6.78902858227


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.




Practice Tags :

Recommended Posts:



0 Average Difficulty : 0/5.0
No votes yet.






User Actions