📜  查找平面的X,Y和Z截距的程序

📅  最后修改于: 2021-04-29 05:07:42             🧑  作者: Mango

在本文中,说明了如何查找平面的X,Y和Z截距。
有两种方法可以找到截距:

  • 情况1:给出平面的一般方程式时。

例子:

方法:可以通过以下步骤计算结果:

  • 将平面的一般方程Ax + By + Cz + D = 0转换Ax + By + Cz = – D
  • 在等式两边除以-D
  • 因此,方程变为x /(-D / A)+ y /(-D / B)+ z(-D / C)= 1
  • 上式是平面的截距形式。所以,
    X截距将为–D / A
    Y截距将为–D / B
    Z截距将为–D / C

下面是上述方法的实现:

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


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


输出:
[-4.0, -1.6, -1.1428571428571428]



  • 情况2:给定3个非共线点。

例子:

方法:想法是使用三个点找到方程的笛卡尔形式。

  • 当给出三个点(x1,y1,z1),(x2,y2,z2),(x3,y3,z3)时,以下矩阵的行列式值给出笛卡尔形式。
  • | (x – x1)(y – y1)(z – z1)|
    | (x2 – x1)(y2 – y1)(z2 – z1)| = 0
    | (x3 – x1)(y3 – y1)(z3 – z1)|
  • 一旦找到上述行列式,就可以使用第一个提到的方法来找到截距。

下面是上述方法的实现:

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
输出:
[-0.11538461538461539, -0.42857142857142855, -0.3333333333333333]