# 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

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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 on both side of equation
• So, the equation becomes x/(-D/A) + y/(-D/B) + z(-D/C) = 1
• 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; ` `         `  `        ``// 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 = x; ` `        ``rslt = y; ` `        ``rslt = 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 `

## 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``; ` `         `  `        ``// 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 = x; ` `        ``rslt = y; ` `        ``rslt = 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 `

## 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)) `

Output:

```[-4.0, -1.6, -1.1428571428571428]
```
• 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

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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:

 `# 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)) `

Output:

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

My Personal Notes arrow_drop_up 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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : AnkitRai01, ANKITKUMAR34