Find the equation of plane which passes through two points and parallel to a given axis

Given two points A(x1, y1, z1) and B(x2, y2, z2) and a set of points (a, b, c) which represent the axis (ai + bj + ck), the task is to find the equation of plane which passes through the given points A and B and parallel to the given axis.
Examples:Â
Input: x1 = 1, y1 = 2, z1 = 3, x2 = 3, y2 = 4, z2 = 5, a= 6, b = 7, c = 8Â
Output: 2x + 4y + 2z + 0 = 0ÂInput: x1 = 2, y1 = 3, z1 = 5, x2 = 6, y2 = 7, z2 = 8, a= 11, b = 23, c = 10.Â
Output: -29x + 7y + 48z + 0= 0Â
Approach:Â
From the given two points on plane A and B, The directions ratios a vector equation of line AB is given by:Â Â
direction ratio = (x2 – x1, y2 – y1, z2 – z1)Â
Since the lineÂ
Â
is parallel to the given axisÂ
Â
. Therefore, the cross-product ofÂ
Â
andÂ
Â
is 0 which is given by:Â
Âwhere,Â
d, e, and f are the coefficient of vector equation of line AB i.e.,Â
d = (x2 – x1),Â
e = (y2 – y1), andÂ
f = (z2 – z1)Â
and a, b, and c are the coefficient of given axis.Â
The equation formed by the above determinant is given by:Â Â
Â(Equation 1)Â
Â
Equation 1 is perpendicular to the line AB which means it is perpendicular to the required plane.Â
Let the Equation of the plane is given byÂ
(Equation 2)Â
where A, B, and C are the direction ratio of the plane perpendicular to the plane.
Since Equation 1 is Equation 2 are perpendicular to each other, therefore the value of the direction ratio of Equation 1 & 2 are parallel. Then the coefficient of the plane is given by:Â Â
A = (b*f – c*e),Â
B = (a*f – c*d), andÂ
C = (a*e – b*d)Â
Now dot product of plane and vector line AB gives the value of D as Â
D = -(A * d – B * e + C * f) Â
Below is the implementation of the above approach:Â
C++
// C++ implementation to find the// equation of plane which passes// through two points and parallel// to a given axisÂ
#include <bits/stdc++.h>using namespace std;Â
void findEquation(int x1, int y1, int z1,                  int x2, int y2, int z2,                  int d, int e, int f){Â
    // Find direction vector    // of points (x1, y1, z1)    // and (x2, y2, z2)    double a = x2 - x1;    double b = y2 - y1;    double c = z2 - z1;Â
    // Values that are calculated    // and simplified from the    // cross product    int A = (b * f - c * e);    int B = (a * f - c * d);    int C = (a * e - b * d);    int D = -(A * d - B * e + C * f);Â
    // Print the equation of plane    cout << A << "x + " << B << "y + "         << C << "z + " << D << "= 0";}Â
// Driver Codeint main(){Â
    // Point A    int x1 = 2, y1 = 3, z1 = 5;Â
    // Point B    int x2 = 6, y2 = 7, z2 = 8;Â
    // Given axis    int a = 11, b = 23, c = 10;Â
    // Function Call    findEquation(x1, y1, z1,                 x2, y2, z2,                 a, b, c);Â
    return 0;} |
Java
// Java implementation to find the // equation of plane which passes // through two points and parallel // to a given axis import java.util.*; Â
class GFG{ Â
static void findEquation(int x1, int y1, int z1,                          int x2, int y2, int z2,                          int d, int e, int f) {         // Find direction vector     // of points (x1, y1, z1)     // and (x2, y2, z2)     double a = x2 - x1;     double b = y2 - y1;     double c = z2 - z1; Â
    // Values that are calculated     // and simplified from the     // cross product     int A = (int)(b * f - c * e);     int B = (int)(a * f - c * d);     int C = (int)(a * e - b * d);     int D = -(int)(A * d - B * e + C * f); Â
    // Print the equation of plane     System.out.println(A + "x + " + B + "y + " +                        C + "z + " + D + "= 0 "); } Â
// Driver code public static void main(String[] args) { Â
    // Point A     int x1 = 2, y1 = 3, z1 = 5; Â
    // Point B     int x2 = 6, y2 = 7, z2 = 8; Â
    // Given axis     int a = 11, b = 23, c = 10; Â
    // Function Call     findEquation(x1, y1, z1,                  x2, y2, z2,                  a, b, c); } } Â
// This code is contributed by Pratima Pandey |
Python3
# Python3 implementation # to find the equation # of plane which passes# through two points and # parallel to a given axisdef findEquation(x1, y1, z1,                 x2, y2, z2,                 d, e, f):       # Find direction vector    # of points (x1, y1, z1)    # and (x2, y2, z2)    a = x2 - x1    b = y2 - y1    c = z2 - z1Â
    # Values that are calculated    # and simplified from the    # cross product    A = (b * f - c * e)    B = (a * f - c * d)    C = (a * e - b * d)    D = -(A * d - B *          e + C * f)Â
    # Print the equation of plane    print (A, "x + ", B, "y + ",            C, "z + ", D, "= 0")Â
# Driver Codeif __name__ == "__main__":Â Â Â Â Â Â Â # Point AÂ Â Â Â x1 = 2Â Â Â Â y1 = 3Â Â Â Â z1 = 5;Â
    # Point B    x2 = 6    y2 = 7    z2 = 8Â
    # Given axis    a = 11    b = 23    c = 10Â
    # Function Call    findEquation(x1, y1, z1,                 x2, y2, z2,                 a, b, c)Â
# This code is contributed by Chitranayal |
C#
// C# implementation to find the // equation of plane which passes // through two points and parallel // to a given axis using System;class GFG{ Â
static void findEquation(int x1, int y1, int z1,                          int x2, int y2, int z2,                          int d, int e, int f) {         // Find direction vector     // of points (x1, y1, z1)     // and (x2, y2, z2)     double a = x2 - x1;     double b = y2 - y1;     double c = z2 - z1; Â
    // Values that are calculated     // and simplified from the     // cross product     int A = (int)(b * f - c * e);     int B = (int)(a * f - c * d);     int C = (int)(a * e - b * d);     int D = -(int)(A * d - B * e + C * f); Â
    // Print the equation of plane     Console.Write(A + "x + " + B + "y + " +                   C + "z + " + D + "= 0 "); } Â
// Driver code public static void Main() { Â
    // Point A     int x1 = 2, y1 = 3, z1 = 5; Â
    // Point B     int x2 = 6, y2 = 7, z2 = 8; Â
    // Given axis     int a = 11, b = 23, c = 10; Â
    // Function Call     findEquation(x1, y1, z1,                  x2, y2, z2,                  a, b, c); } } Â
// This code is contributed by Code_Mech |
Javascript
<script>// javascript implementation to find the // equation of plane which passes // through two points and parallel // to a given axis Â
    function findEquation(x1 , y1 , z1 , x2 , y2 , z2 , d , e , f)    {Â
        // Find direction vector        // of points (x1, y1, z1)        // and (x2, y2, z2)        var a = x2 - x1;        var b = y2 - y1;        var c = z2 - z1;Â
        // Values that are calculated        // and simplified from the        // cross product        var A = parseInt( (b * f - c * e));        var B = parseInt( (a * f - c * d));        var C = parseInt( (a * e - b * d));        var D = -parseInt( (A * d - B * e + C * f));Â
        // Print the equation of plane        document.write(A + "x + " + B + "y + " + C + "z + " + D + "= 0 ");    }Â
    // Driver code             // Point A        var x1 = 2, y1 = 3, z1 = 5;Â
        // Point B        var x2 = 6, y2 = 7, z2 = 8;Â
        // Given axis        var a = 11, b = 23, c = 10;Â
        // Function Call        findEquation(x1, y1, z1, x2, y2, z2, a, b, c);Â
// This code is contributed by Rajput-Ji</script> |
-29x + 7y + 48z + 0= 0
Â
Time Complexity: O(1)
Auxiliary Space: O(1)
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!




