You are given two planes P1: a1 * x + b1 * y + c1 * z + d1 = 0 and P2: a2 * x + b2 * y + c2 * z + d2 = 0. The task is to write a program to find distance between these two Planes.
Input: a1 = 1, b1 = 2, c1 = -1, d1 = 1, a2 = 3, b2 = 6, c2 = -3, d2 = -4 Output: Distance is 0.952579344416 Input: a1 = 1, b1 = 2, c1 = -1, d1 = 1, a2 = 1, b2 = 6, c2 = -3, d2 = -4 Output: Planes are not parallel
Approach :Consider two planes are given by the equations:-
P1 : a1 * x + b1 * y + c1 * z + d1 = 0, where a1, b1 and c1, d1 are real constants and
P2 : a2 * x + b2 * y + c2 * z + d2 = 0, where a2, b2 and c2, d2 are real constants.
The condition for two planes to be parallel is:-
=> a1 / a2 = b1 / b2 = c1 / c2
Find a point in any one plane such that the distance from that point to the other plane that will be the distance between those two planes. The distance can be calculated by using the formulae:
Distance = (| a*x1 + b*y1 + c*z1 + d |) / (sqrt( a*a + b*b + c*c))
Let a point in Plane P1 be P(x1, y1, z1),
put x = y = 0 in equation a1 * x + b1 * y + c1 * z + d1 = 0 and find z.
=> z = -d1 / c1
Now we have coordinates of P(0, 0, z) = P(x1, y1, z1).
Distance of point P to Plane P2 will be:-
Distance = (| a2*x1 + b2*y1 + c2*z1 + d2 |) / (sqrt( a2*a2 + b2*b2 + c2*c2))
= (| a2*0 + b2*0 + c2*z1 + d2 |) / (sqrt( a2*a2 + b2*b2 + c2*c2))
= (| c2*z1 + d2 |) / (sqrt( a2*a2 + b2*b2 + c2*c2))
Below is the implementation of the above formulae:
Perpendicular distance is 0.952579344416
- Distance between two parallel lines
- Angle between two Planes in 3D
- Maximum number of line intersections formed through intersection of N planes
- Count paths with distance equal to Manhattan distance
- Find whether only two parallel lines contain all coordinates points or not
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Maximum number of region in which N non-parallel lines can divide a plane
- Number of parallelograms when n horizontal parallel lines intersect m vertical parallellines
- Distance of chord from center when distance between center and another equal length chord is given
- Program to check if the points are parallel to X axis or Y axis
- Distance between a point and a Plane in 3 D
- Puzzle | Minimum distance for Lizard
- Perpendicular distance between a point and a Line in 2 D
- Shortest distance between a point and a circle
- Hammered distance between N points in a 2-D plane
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.