The Wayback Machine - https://web.archive.org/web/20240603190155/https://www.geeksforgeeks.org/program-to-find-equation-of-a-plane-passing-through-3-points/
Open In App

Program to find equation of a plane passing through 3 points

Last Updated : 09 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Given three points (x1, y1, z1), (x2, y2, z2), (x3, y3, z3). The task is to find the equation of the plane passing through these 3 points.
 

Examples: 
 

Input: x1 = -1 y1 = w z1 = 1 
x2 = 0 y2 = -3 z2 = 2 
x3 = 1 y3 = 1 z3 = -4 
Output: equation of plane is 26 x + 7 y + 9 z + 3 = 0.
Input: x1 = 2, y1 = 1, z1 = -1, 1 
x2 = 0, y2 = -2, z2 = 0 
x3 = 1, y3 = -1, z3 = 2 
Output: equation of plane is -7 x + 5 y + 1 z + 10 = 0.

 

Approach: Let P, Q and R be the three points with coordinates (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) respectively. Then the equation of plane is a * (x – x0) + b * (y – y0) + c * (z – z0) = 0, where a, b, c are direction ratios of normal to the plane and (x0, y0, z0) are co-ordinates of any point(i.e P, Q, or R) passing through the plane. For finding direction ratios of normal to the plane, take any two vectors in plane, let it be vector PQ, vector PR. 
 

=> Vector PQ = (x2 - x1, y2 - y1, z2 - z1) = (a1, b1, c1).
=> Vector PR = (x3 - x1, y3 - y1, z3 - z1) = (a2, b2, c2).

Normal vector to this plane will be vector PQ x vector PR. 
 

=> PQ X PR = (b1 * c2 - b2 * c1) i 
              + (a2 * c1 - a1 * c2) j 
              + (a1 * b2 - b1 *a2) k = ai + bj + ck.

Direction ratios of normal vector will be a, b, c. Taking any one point from P, Q, or R, let its co-ordinate be (x0, y0, z0). Then the equation of plane passing through a point(x0, y0, z0) and having direction ratios a, b, c will be 
 

=> a * (x - x0) + b * (y - y0) + c * (z - z0) = 0.
=> a * x - a * x0 + b * y - b * y0 + c * z - c * z0 = 0.
=> a * x + b * y + c * z + (- a * x0 - b * y0 - c * z0) = 0.

Below is the implementation of the above approach: 
 

C++




// C++ program to find equation of a plane
// passing through given 3 points.
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <iomanip>
 
using namespace std;
 
// Function to find equation of plane.
void equation_plane(float x1, float y1,
                    float z1, float x2,
                    float y2, float z2,
                    float x3, float y3, float z3)
{
    float a1 = x2 - x1;
    float b1 = y2 - y1;
    float c1 = z2 - z1;
    float a2 = x3 - x1;
    float b2 = y3 - y1;
    float c2 = z3 - z1;
    float a = b1 * c2 - b2 * c1;
    float b = a2 * c1 - a1 * c2;
    float c = a1 * b2 - b1 * a2;
    float d = (- a * x1 - b * y1 - c * z1);
    std::cout << std::fixed;
    std::cout << std::setprecision(2);
    cout << "equation of plane is " << a << " x + " << b
        << " y + " << c << " z + " << d << " = 0.";
}
 
// Driver Code
int main()
{
     
    float x1 =-1;
    float y1 = 2;
    float z1 = 1;
    float x2 = 0;
    float y2 =-3;
    float z2 = 2;
    float x3 = 1;
    float y3 = 1;
    float z3 =-4;
    equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3);
    return 0;
}
// This code is contributed
// by Amber_Saxena.


C




// C program to find equation of a plane
// passing through given 3 points.
 
#include<stdio.h>
 
// Function to find equation of plane.
void equation_plane(float x1, float y1,
                    float z1, float x2,
                    float y2, float z2,
                    float x3, float y3, float z3)
{
    float a1 = x2 - x1;
    float b1 = y2 - y1;
    float c1 = z2 - z1;
    float a2 = x3 - x1;
    float b2 = y3 - y1;
    float c2 = z3 - z1;
    float a = b1 * c2 - b2 * c1;
    float b = a2 * c1 - a1 * c2;
    float c = a1 * b2 - b1 * a2;
    float d = (- a * x1 - b * y1 - c * z1);
    printf("equation of plane is %.2f x + %.2f"
        " y + %.2f z + %.2f = 0.",a,b,c,d);
    return;
}
 
// Driver Code
int main()
{
    float x1 =-1;
    float y1 = 2;
    float z1 = 1;
    float x2 = 0;
    float y2 =-3;
    float z2 = 2;
    float x3 = 1;
    float y3 = 1;
    float z3 =-4;
    equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3);
    return 0;
}
// This code is contributed
// by Amber_Saxena.


Java




// Java program to find equation
// of a plane passing through
// given 3 points.
import java .io.*;
 
class GFG
{
     
// Function to find equation of plane.
static void equation_plane(float x1, float y1,
                           float z1, float x2,
                           float y2, float z2,
                           float x3, float y3,
                           float z3)
{
    float a1 = x2 - x1;
    float b1 = y2 - y1;
    float c1 = z2 - z1;
    float a2 = x3 - x1;
    float b2 = y3 - y1;
    float c2 = z3 - z1;
    float a = b1 * c2 - b2 * c1;
    float b = a2 * c1 - a1 * c2;
    float c = a1 * b2 - b1 * a2;
    float d = (- a * x1 - b * y1 - c * z1);
    System.out.println("equation of plane is " + a +
                       " x + " + b + " y + " + c +
                       " z + " + d + " = 0.");
}
 
// Driver code
public static void main(String[] args)
{
    float x1 =-1;
    float y1 = 2;
    float z1 = 1;
    float x2 = 0;
    float y2 =-3;
    float z2 = 2;
    float x3 = 1;
    float y3 = 1;
    float z3 =-4;
    equation_plane(x1, y1, z1, x2,
                   y2, z2, x3, y3, z3);
}
}
 
// This code is contributed
// by Amber_Saxena.


Python




# Python program to find equation of a plane
# passing through given 3 points.
 
# Function to find equation of plane.
def equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3):
     
    a1 = x2 - x1
    b1 = y2 - y1
    c1 = z2 - z1
    a2 = x3 - x1
    b2 = y3 - y1
    c2 = z3 - z1
    a = b1 * c2 - b2 * c1
    b = a2 * c1 - a1 * c2
    c = a1 * b2 - b1 * a2
    d = (- a * x1 - b * y1 - c * z1)
    print "equation of plane is ",
    print a, "x +",
    print b, "y +",
    print c, "z +",
    print d, "= 0."
 
# Driver Code
x1 =-1
y1 = 2
z1 = 1
x2 = 0
y2 =-3
z2 = 2
x3 = 1
y3 = 1
z3 =-4
equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3)


C#




// C# program to find equation
// of a plane passing through
// given 3 points.
using System;
 
class GFG
{
     
// Function to find equation of plane.
static void equation_plane(float x1, float y1,
                           float z1, float x2,
                           float y2, float z2,
                           float x3, float y3,
                           float z3)
{
    float a1 = x2 - x1;
    float b1 = y2 - y1;
    float c1 = z2 - z1;
    float a2 = x3 - x1;
    float b2 = y3 - y1;
    float c2 = z3 - z1;
    float a = b1 * c2 - b2 * c1;
    float b = a2 * c1 - a1 * c2;
    float c = a1 * b2 - b1 * a2;
    float d = (- a * x1 - b * y1 - c * z1);
    Console.Write("equation of plane is " + a +
                      "x + " + b + "y + " + c +
                          "z + " + d + " = 0");
}
 
// Driver code
public static void Main()
{
    float x1 =-1;
    float y1 = 2;
    float z1 = 1;
    float x2 = 0;
    float y2 =-3;
    float z2 = 2;
    float x3 = 1;
    float y3 = 1;
    float z3 =-4;
    equation_plane(x1, y1, z1,
                   x2, y2, z2,
                   x3, y3, z3);
}
}
 
// This code is contributed
// by ChitraNayal


PHP




<?php
// PHP program to find equation
// of a plane passing through
// given 3 points.
 
// Function to find equation of plane.
function equation_plane($x1, $y1, $z1,
                        $x2, $y2, $z2,
                        $x3, $y3, $z3)
{
    $a1 = $x2 - $x1;
    $b1 = $y2 - $y1;
    $c1 = $z2 - $z1;
    $a2 = $x3 - $x1;
    $b2 = $y3 - $y1;
    $c2 = $z3 - $z1;
    $a = $b1 * $c2 - $b2 * $c1;
    $b = $a2 * $c1 - $a1 * $c2;
    $c = $a1 * $b2 - $b1 * $a2;
    $d = (- $a * $x1 - $b * $y1 - $c * $z1);
    echo sprintf("equation of the plane is %.2fx" .
                     " + %.2fy + %.2fz + %.2f = 0",
                                   $a, $b, $c, $d);
}
 
// Driver Code
$x1 =-1;
$y1 = 2;
$z1 = 1;
$x2 = 0;
$y2 =-3;
$z2 = 2;
$x3 = 1;
$y3 = 1;
$z3 =-4;
equation_plane($x1, $y1, $z1, $x2,
               $y2, $z2, $x3, $y3, $z3);
 
// This code is contributed
// by Amber_Saxena.
?>


Javascript




<script>
// javascript program to find equation
// of a plane passing through
// given 3 points.
 
    // Function to find equation of plane.
    function equation_plane(x1 , y1 , z1 , x2 ,
    y2 , z2 , x3 , y3, z3) {
        var a1 = x2 - x1;
        var b1 = y2 - y1;
        var c1 = z2 - z1;
        var a2 = x3 - x1;
        var b2 = y3 - y1;
        var c2 = z3 - z1;
        var a = b1 * c2 - b2 * c1;
        var b = a2 * c1 - a1 * c2;
        var c = a1 * b2 - b1 * a2;
        var d = (-a * x1 - b * y1 - c * z1);
        document.write("equation of plane is " + a + " x + "
        + b + " y + " + c + " z + " + d + " = 0.");
    }
 
    // Driver code
     
        var x1 = -1;
        var y1 = 2;
        var z1 = 1;
        var x2 = 0;
        var y2 = -3;
        var z2 = 2;
        var x3 = 1;
        var y3 = 1;
        var z3 = -4;
        equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3);
 
// This code is contributed by Rajput-Ji
</script>


Output: 

equation of plane is  26 x + 7 y + 9 z + 3 = 0.

 

Time Complexity: O(1)
Auxiliary Space: O(1)



Previous Article
Next Article

Similar Reads

Find the equation of the straight line passing through the given points
Given an array arr containing N coordinate points in a plane, the task is to check whether the coordinate points lie on a straight line or not. If they lie on a straight line then print Yes and also the equation of that line otherwise print No. Example: Input: arr[] = {{1, 1}, {2, 2}, {3, 3}} Output: Yes1x- 1y=0 Input: arr[] = {{0, 1}, {2, 0}}Outpu
6 min read
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 =
9 min read
Program to find line passing through 2 Points
Given two points P and Q in the coordinate plane, find the equation of the line passing through both points.This kind of conversion is very useful in many geometric algorithms like intersection of lines, finding the circumcenter of a triangle, finding the incenter of a triangle and many more... Examples: Input : P(3, 2) Q(2, 6) Output : 4x + 1y = 1
6 min read
Find X and Y intercepts of a line passing through the given points
Given two points on a 2D plane, the task is to find the x - intercept and the y - intercept of a line passing through the given points.Examples: Input: points[][] = {{5, 2}, {2, 7}} Output: 6.2 10.333333333333334Input: points[][] = {{3, 2}, {2, 4}} Output: 4.0 8.0 Approach: Find the slope using the given points.Put the value of the slope in the exp
7 min read
Equation of straight line passing through a given point which bisects it into two equal line segments
Given a straight line which passes through a given point (x0, y0) such that this point bisects the line segment in two equal line segments. The task is to find the equation of this straight line.Examples: Input: x0 = 4, y0 = 3 Output: 3x + 4y = 24Input: x0 = 7, y0 = 12 Output: 12x + 7y = 168 Approach: Let PQ be the line and AB be the line segment b
4 min read
Equation of a straight line passing through a point and making a given angle with a given line
Given four integers a, b, c representing coefficients of a straight line with equation (ax + by + c = 0), the task is to find the equations of the two straight lines passing through a given point [Tex](x1, y1) [/Tex]and making an angle ? with the given straight line. Examples: Input: a = 2, b = 3, c = -7, x1 = 4, y1 = 9, ? = 30Output: y = -0.49x +1
16 min read
Minimum points to be selected such that removal of line segments passing through them empties given array
Given a 2D array arr[][], where each row is of the form {start, end} representing the start and endpoints of each line segment on the X-axis. In one step, select a point on the X-axis and delete all the line segments passing through that point. The task is to find the minimum number of such points that need to be selected to delete all the line seg
7 min read
Find the sum of diagonals passing through given coordinates for Q query
Given a 2D matrix of size N x M and Q queries where each query represents a coordinate (x, y) of the matrix, the task is to find the sum of all elements lying in the diagonals that pass through the given point. Examples: Input: N = 4, M = 4, mat[][] = {{1, 2, 2, 1}, {2, 4, 2, 4}, {2, 2, 3, 1}, {2, 4, 2, 4}}, query = { {0, 0}, {3, 1}, {3, 3} } Outpu
12 min read
Program to check whether 4 points in a 3-D plane are Coplanar
Given 4 points (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4). The task is to write a program to check whether these 4 points are coplanar or not.Note: 4 points in a 3-D plane are said to be coplanar if they lies in the same plane. Examples: Input: x1 = 3, y1 = 2, z1 = -5 x2 = -1, y2 = 4, z2 = -3 x3 = -3, y3 = 8, z3 = -5 x4 = -3, y4 = 2, z4
9 min read
Maximum distinct lines passing through a single point
Given [Tex]N [/Tex]lines represented by two points [Tex](x1, y1) [/Tex]and [Tex](x2, y2) [/Tex]. The task is to find maximum number of lines which can pass through a single point, without superimposing (or covering) any other line. We can move any line but not rotate it.Examples: Input : Line 1 : x1 = 1, y1 = 1, x2 = 2, y2 = 2 Line 2 : x2 = 2, y1 =
6 min read
Practice Tags :