# Program to find X, Y and Z intercepts of a plane

In this article, it is explained how to find the X, Y, and Z intercepts of a plane. There are two ways to find the intercepts:

### Case 1: When the general equation of the plane is given.

Examples:

```Input: A = -6, B = 5, C = -3, D = 9
Output:
1.5
-1.8
3.0```
```Input: A = 7, B = 4, C = 5, D = -7
Output:
1.0
1.75
1.4 ```

### Approach:

The result can be computed by following the below steps:

• Convert general equation of a plane Ax + By + Cz + D = 0 to Ax + By + Cz = – D
• Divide by -D into both sides of the equation
• So, the equation becomes x/(-D/A) + y/(-D/B) + z(-D/C) = 1
• The above equation is in the intercept form of a plane. Therefore,
X intercepts will be = -D/A
Y intercepts will be = -D/B
Z intercepts will be = -D/C

Below is the implementation of the above approach:

## C++

 `// C++ program to find the ``// X, Y and Z intercepts of a plane``#include``using` `namespace` `std;` `float` `* XandYandZintercept(``float` `A, ``float` `B,``                            ``float` `C, ``float` `D)``{``        ``static` `float` `rslt[3];``        ` `        ``// For finding the x-intercept ``        ``// put y = 0 and z = 0 ``        ``float` `x = -D / A ;``    ` `        ``// For finding the y-intercept ``        ``// put x = 0 and z = 0 ``        ``float` `y = -D / B ;``    ` `        ``// For finding the z-intercept ``        ``// put x = 0 and y = 0 ``        ``float` `z = -D / C ;``        ` `        ``rslt[0] = x;``        ``rslt[1] = y;``        ``rslt[2] = z;``        ` `        ``return` `rslt; ``}``    ` `// Driver code ``int` `main () ``{``    ``int` `A = 2 ;``    ``int` `B = 5 ;``    ``int` `C = 7;``    ``int` `D = 8 ;``        ` `    ``float` `*rslt = XandYandZintercept(A, B, C, D);``        ` `    ``for``(``int` `i = 0; i < 3 ; i++)``    ``{``        ``cout << rslt[i] << ``" "``;``    ``}``    ` `}` `// This code is contributed by ANKITKUMAR34`

## Java

 `// Java program to find the ``// X, Y and Z intercepts of a plane``class` `GFG ``{``    ` `    ``static` `float``[] XandYandZintercept(``float` `A, ``                    ``float` `B, ``float` `C, ``float` `D)``    ``{``        ``float` `rslt[] = ``new` `float``[``3``];``        ` `        ``// For finding the x-intercept ``        ``// put y = 0 and z = 0 ``        ``float` `x = -D / A ;``    ` `        ``// For finding the y-intercept ``        ``// put x = 0 and z = 0 ``        ``float` `y = -D / B ;``    ` `        ``// For finding the z-intercept ``        ``// put x = 0 and y = 0 ``        ``float` `z = -D / C ;``        ` `        ``rslt[``0``] = x;``        ``rslt[``1``] = y;``        ``rslt[``2``] = z;``        ` `        ``return` `rslt; ``    ``}``    ` `    ``// Driver code ``    ``public` `static` `void` `main (String[] args) ``    ``{``        ``int` `A = ``2` `;``        ``int` `B = ``5` `;``        ``int` `C = ``7``;``        ``int` `D = ``8` `;``        ` `        ``float` `rslt[] = XandYandZintercept(A, B, C, D);``        ` `        ``for``(``int` `i = ``0``; i < ``3` `; i++)``        ``{``            ``System.out.print(rslt[i] + ``" "``);``        ``}``    ``}``}` `// This code is contributed by AnkitRai01`

## Python3

 `# Python program to find the ``# X, Y and Z intercepts of a plane` `def` `XandYandZintercept(A, B, C, D): ` `    ``# For finding the x-intercept ``    ``# put y = 0 and z = 0``    ``x ``=` `-``D ``/` `A` `    ``# For finding the y-intercept ``    ``# put x = 0 and z = 0 ``    ``y ``=` `-``D ``/` `B ` `    ``# For finding the z-intercept ``    ``# put x = 0 and y = 0``    ``z ``=` `-``D ``/` `C``    ``return` `[x, y, z]` `# Driver code``A ``=` `2``B ``=` `5``C ``=` `7``D ``=` `8``print``(XandYandZintercept(A, B, C, D))`

## C#

 `// C# program to find the ``// X, Y and Z intercepts of a plane``using` `System;` `class` `GFG ``{``    ` `    ``static` `float``[] XandYandZintercept(``float` `A, ``                    ``float` `B, ``float` `C, ``float` `D)``    ``{``        ``float` `[]rslt = ``new` `float``[3];``        ` `        ``// For finding the x-intercept ``        ``// put y = 0 and z = 0 ``        ``float` `x = -D / A ;``    ` `        ``// For finding the y-intercept ``        ``// put x = 0 and z = 0 ``        ``float` `y = -D / B ;``    ` `        ``// For finding the z-intercept ``        ``// put x = 0 and y = 0 ``        ``float` `z = -D / C ;``        ` `        ``rslt[0] = x;``        ``rslt[1] = y;``        ``rslt[2] = z;``        ` `        ``return` `rslt; ``    ``}``    ` `    ``// Driver code ``    ``public` `static` `void` `Main() ``    ``{``        ``int` `A = 2 ;``        ``int` `B = 5 ;``        ``int` `C = 7;``        ``int` `D = 8 ;``        ` `        ``float` `[]rslt = XandYandZintercept(A, B, C, D);``        ` `        ``for``(``int` `i = 0; i < 3 ; i++)``        ``{``            ``Console.Write(rslt[i] + ``" "``);``        ``}``    ``}``}` `// This code is contributed by AnkitRai01`

## Javascript

 ``

Output:
`[-4.0, -1.6, -1.1428571428571428]`

Time Complexity: O(1)

Auxiliary Space: O(1)

### Case 2: When 3 non-collinear points are given.

Examples:

```Input: A = (3, 17, 2), B = (4, 8, 5), C = (1, 8, 3)
Output:
1.5
-1.8
3.0```
```Input: A = (2, 11, 4), B = (7, 8, 3), C = (9, 18, 23)
Output:
1.0
1.75
1.4 ```

### Approach:

The idea is to find the Cartesian form of the equation using three points.

• When three points (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) are given, the determinant value of the following matrix gives the Cartesian form.
• | (x â€“ x1) (y â€“ y1) (z â€“ z1) |
| (x2 â€“ x1) (y2 â€“ y1) (z2 â€“ z1)| = 0
| (x3 â€“ x1) (y3 â€“ y1) (z3 â€“ z1)|
• Once the above determinant is found, then the intercepts can be found using the first mentioned approach.

Below is the implementation of the above approach:

## C++

 `// C++ program to find the ``// X, Y and Z intercepts of a plane``#include``using` `namespace` `std;` `float` `* XandYandZintercept( ``float` `A, ``float` `B, ``                            ``float` `C, ``float` `D)``{``    ``static` `float` `rslt[3];``    ` `    ``// For finding the x-intercept ``    ``// put y = 0 and z = 0``    ``float` `x = -D / A;` `    ``// For finding the y-intercept ``    ``// put x = 0 and z = 0 ``    ``float` `y = -D / B ;` `    ``// For finding the z-intercept ``    ``// put x = 0 and y = 0``    ``float` `z = -D / C;``    ``rslt[0] = x;``    ``rslt[1] = y;``    ``rslt[2] = z; ``    ` `    ``return` `rslt;``}` `void` `equation_plane(``int` `p[], ``int` `q[], ``int` `r[])``{``    ``int` `x1 = p[0];``    ``int` `y1 = p[1];``    ``int` `z1 = p[2];``    ``int` `x2 = q[0];``    ``int` `y2 = q[1];``    ``int` `z2 = q[2];``    ``int` `x3 = r[0];``    ``int` `y3 = r[1];``    ``int` `z3 = r[2];``    ` `    ``// For Finding value of A, B, C, D``    ``int` `a1 = x2 - x1;``    ``int` `b1 = y2 - y1;``    ``int` `c1 = z2 - z1;``    ``int` `a2 = x3 - x1;``    ``int` `b2 = y3 - y1;``    ``int` `c2 = z3 - z1;``    ``int` `A = b1 * c2 - b2 * c1;``    ``int` `B = a2 * c1 - a1 * c2;``    ``int` `C = a1 * b2 - b1 * a2;``    ``int` `D = (- A * x1 - B * y1 - C * z1);``    ` `    ``// Calling the first created function ``    ``float` `* rslt=XandYandZintercept(A, B, C, D); ``    ``for``(``int` `i = 0; i < 3; i++)``    ``{``        ``cout << rslt[i] << ``" "``;``    ``}``}``    ` `// Driver Code ``int` `main() ``{``    ``int` `x1 =-1;``    ``int` `y1 = 2;``    ``int` `z1 = 1;``    ``int` `x2 = 0;``    ``int` `y2 =-3;``    ``int` `z2 = 2;``    ``int` `x3 = 1;``    ``int` `y3 = 1;``    ``int` `z3 =-4;``        ` `    ``int` `p[3] = {x1, y1, z1};``    ``int` `q[3] = {x2, y2, z2};``    ``int` `r[3] = {x3, y3, z3};``    ``equation_plane(p, q, r);` `}` `// This code is contributed by chitranayal`

## Java

 `// Java program to find the ``// X, Y and Z intercepts of a plane``import` `java.util.*;` `class` `solution{` `static` `double``[] XandYandZintercept( ``double` `A, ``double` `B, ``                            ``double` `C, ``double` `D)``{``    ``double` `[]rslt = ``new` `double``[``3``];``    ` `    ``// For finding the x-intercept ``    ``// put y = 0 and z = 0``    ``double` `x = -D / A;` `    ``// For finding the y-intercept ``    ``// put x = 0 and z = 0 ``    ``double` `y = -D / B ;` `    ``// For finding the z-intercept ``    ``// put x = 0 and y = 0``    ``double` `z = -D / C;``    ``rslt[``0``] = x;``    ``rslt[``1``] = y;``    ``rslt[``2``] = z; ``    ` `    ``return` `rslt;``}` `static` `void` `equation_plane(``int` `[]p, ``int` `[]q, ``int` `[]r)``{``    ``int` `x1 = p[``0``];``    ``int` `y1 = p[``1``];``    ``int` `z1 = p[``2``];``    ``int` `x2 = q[``0``];``    ``int` `y2 = q[``1``];``    ``int` `z2 = q[``2``];``    ``int` `x3 = r[``0``];``    ``int` `y3 = r[``1``];``    ``int` `z3 = r[``2``];``    ` `    ``// For Finding value of A, B, C, D``    ``int` `a1 = x2 - x1;``    ``int` `b1 = y2 - y1;``    ``int` `c1 = z2 - z1;``    ``int` `a2 = x3 - x1;``    ``int` `b2 = y3 - y1;``    ``int` `c2 = z3 - z1;``    ``int` `A = b1 * c2 - b2 * c1;``    ``int` `B = a2 * c1 - a1 * c2;``    ``int` `C = a1 * b2 - b1 * a2;``    ``int` `D = (- A * x1 - B * y1 - C * z1);``    ` `    ``// Calling the first created function ``    ``double` `[]rslt = XandYandZintercept(A, B, C, D);``    ``for``(``int` `i = ``0``; i < ``3``; i++)``    ``{``        ``System.out.printf(rslt[i]+``" "``);``    ``}``}``    ` `// Driver Code ``public` `static` `void` `main(String args[]) ``{``    ``int` `x1 =-``1``;``    ``int` `y1 = ``2``;``    ``int` `z1 = ``1``;``    ``int` `x2 = ``0``;``    ``int` `y2 =-``3``;``    ``int` `z2 = ``2``;``    ``int` `x3 = ``1``;``    ``int` `y3 = ``1``;``    ``int` `z3 =-``4``;``        ` `    ``int` `[]p = {x1, y1, z1};``    ``int` `[]q = {x2, y2, z2};``    ``int` `[]r = {x3, y3, z3};``    ``equation_plane(p, q, r);` `}``}` `// This code is contributed by Surendra_Gangwar`

## Python3

 `# Python program to find the ``# X, Y and Z intercepts of a plane` `def` `XandYandZintercept(A, B, C, D): `` ` `    ``# For finding the x-intercept ``    ``# put y = 0 and z = 0``    ``x ``=` `-``D ``/` `A` `    ``# For finding the y-intercept ``    ``# put x = 0 and z = 0 ``    ``y ``=` `-``D ``/` `B ` `    ``# For finding the z-intercept ``    ``# put x = 0 and y = 0``    ``z ``=` `-``D ``/` `C``    ``return` `[x, y, z]`` ` `def` `equation_plane(p, q, r): ``    ``x1 ``=` `p[``0``]``    ``y1 ``=` `p[``1``]``    ``z1 ``=` `p[``2``]``    ``x2 ``=` `q[``0``]``    ``y2 ``=` `q[``1``]``    ``z2 ``=` `q[``2``]``    ``x3 ``=` `r[``0``]``    ``y3 ``=` `r[``1``]``    ``z3 ``=` `r[``2``]``    ` `    ``# For Finding value of A, B, C, D``    ``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)``    ` `    ``# Calling the first created function ``    ``print``(XandYandZintercept(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))`

## C#

 `// C# program to find the  ``// X, Y and Z intercepts of a plane ``using` `System;``class` `GFG{``    ` `static` `double``[] XandYandZintercept(``double` `A, ``                                   ``double` `B,  ``                                   ``double` `C, ``                                   ``double` `D) ``{ ``  ``double``[] rslt = ``new` `double``[3]; ` `  ``// For finding the x-intercept  ``  ``// put y = 0 and z = 0 ``  ``double` `x = -D / A; ` `  ``// For finding the y-intercept  ``  ``// put x = 0 and z = 0  ``  ``double` `y = -D / B ; ` `  ``// For finding the z-intercept  ``  ``// put x = 0 and y = 0 ``  ``double` `z = -D / C; ``  ``rslt[0] = x; ``  ``rslt[1] = y; ``  ``rslt[2] = z;  ` `  ``return` `rslt; ``} ` `static` `void` `equation_plane(``int``[] p, ``                           ``int``[] q, ``                           ``int``[] r) ``{ ``  ``int` `x1 = p[0]; ``  ``int` `y1 = p[1]; ``  ``int` `z1 = p[2]; ``  ``int` `x2 = q[0]; ``  ``int` `y2 = q[1]; ``  ``int` `z2 = q[2]; ``  ``int` `x3 = r[0]; ``  ``int` `y3 = r[1]; ``  ``int` `z3 = r[2]; ` `  ``// For Finding value ``  ``// of A, B, C, D ``  ``int` `a1 = x2 - x1; ``  ``int` `b1 = y2 - y1; ``  ``int` `c1 = z2 - z1; ``  ``int` `a2 = x3 - x1; ``  ``int` `b2 = y3 - y1; ``  ``int` `c2 = z3 - z1; ``  ``int` `A = (b1 * c2 - ``           ``b2 * c1); ``  ``int` `B = (a2 * c1 - ``           ``a1 * c2); ``  ``int` `C = (a1 * b2 - ``           ``b1 * a2); ``  ``int` `D = (- A * x1 - ``           ``B * y1 - ``           ``C * z1); ` `  ``// Calling the first ``  ``// created function  ``  ``double``[] rslt = XandYandZintercept(A, B, ``                                     ``C, D); ``  ``for``(``int` `i = 0; i < 3; i++) ``  ``{ ``    ``Console.Write(rslt[i] + ``" "``); ``  ``} ``} ` `// Driver code``static` `void` `Main() ``{``  ``int` `x1 =-1; ``  ``int` `y1 = 2; ``  ``int` `z1 = 1; ``  ``int` `x2 = 0; ``  ``int` `y2 =-3; ``  ``int` `z2 = 2; ``  ``int` `x3 = 1; ``  ``int` `y3 = 1; ``  ``int` `z3 =-4; ` `  ``int``[] p = {x1, y1, z1}; ``  ``int``[] q = {x2, y2, z2}; ``  ``int``[] r = {x3, y3, z3}; ``  ``equation_plane(p, q, r); ``}``}` `// This code is contributed by divyeshrabadiya07`

## Javascript

 ``

Output:
`[-0.11538461538461539, -0.42857142857142855, -0.3333333333333333]`

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

Previous
Next