📜  3D 中两个平面之间的角度

📅  最后修改于: 2021-10-23 08:06:38             🧑  作者: Mango

给定两个平面P1: a1 * x + b1 * y + c1 * z + d1 = 0 和P2: a2 * x + b2 * y + c2 * z + d2 = 0。任务是找到这两个平面之间的角度在 3D 中。

例子:

方法:考虑给定两个平面的以下方程:

P1 : a1 * x + b1 * y + c1 * z + d1 = 0 and,
P2 : a2 * x + b2 * y + c2 * z + d2 = 0, 

其中 a1、b1、c1 和 a2、b2、c2 是平面 P1 和 P2 的法线方向比。
两个平面之间的角度等于由平面的法向量确定的角度。
这些平面之间的角度使用以下公式给出:-
余弦 A = \huge\frac{(a_{1}*a_{2}+b_{1}*b_{2}+c_{1}*c_{2})}{(\sqrt{a_{1}*a_{1}+b_{1}*b_{1}+c_{1}*c_{1}})*(\sqrt{a_{2}*a_{2}+b_{2}*b_{2}+c_{2}*c_{2}})}
使用逆性质,我们得到:
一 = Cos^{-1}\left ( \frac{(a_{1}*a_{2}+b_{1}*b_{2}+c_{1}*c_{2})}{(\sqrt{a_{1}*a_{1}+b_{1}*b_{1}+c_{1}*c_{1}})*(\sqrt{a_{2}*a_{2}+b_{2}*b_{2}+c_{2}*c_{2}})} \right )
下面是上述公式的实现:

C++
// C++ program to find
// the Angle between
// two Planes in 3 D.
#include 
#include
 
using namespace std;
 
// Function to find Angle
void distance(float a1, float b1,
              float c1, float a2,
              float b2, float c2)
{
    float d = (a1 * a2 + b1 *
               b2 + c1 * c2);
    float e1 = sqrt(a1 * a1 + b1 *
                    b1 + c1 * c1);
    float e2 = sqrt(a2 * a2 + b2 *
                    b2 + c2 * c2);
    d = d / (e1 * e2);
    float pi = 3.14159;
    float A = (180 / pi) * (acos(d));
    cout << "Angle is "
         << A << " degree";
}
 
// Driver Code
int main()
{
    float a1 = 1;
    float b1 = 1;
    float c1 = 2;
    float d1 = 1;
    float a2 = 2;
    float b2 = -1;
    float c2 = 1;
    float d2 = -4;
    distance(a1, b1, c1,
             a2, b2, c2);
    return 0;
}
 
// This code is contributed
// by Akanksha Rai(Abby_akku)


C
// C program to find
// the Angle between
// two Planes in 3 D.
#include
#include
 
// Function to find Angle
void distance(float a1, float b1,
              float c1, float a2,
              float b2, float c2)
{
    float d = (a1 * a2 + b1 *
               b2 + c1 * c2);
    float e1 = sqrt(a1 * a1 + b1 *
                    b1 + c1 * c1);
    float e2 = sqrt(a2 * a2 + b2 *
                    b2 + c2 * c2);
    d = d / (e1 * e2);
    float pi = 3.14159;
    float A = (180 / pi) * (acos(d));
    printf("Angle is %.2f degree", A);
}
 
// Driver Code
int main()
{
    float a1 = 1;
    float b1 = 1;
    float c1 = 2;
    float d1 = 1;
    float a2 = 2;
    float b2 = -1;
    float c2 = 1;
    float d2 = -4;
    distance(a1, b1, c1,
             a2, b2, c2);
    return 0;
}
 
// This code is contributed
// by Amber_Saxena.


Java
// Java program to find
// the Angle between
// two Planes in 3 D.
import java .io.*;
import java.lang.Math;
 
class GFG
{
     
// Function to find Angle
static void distance(float a1, float b1,
                     float c1, float a2,
                     float b2, float c2)
{
     
    float d = (a1 * a2 + b1 *
               b2 + c1 * c2);
    float e1 = (float)Math.sqrt(a1 * a1 + b1 *
                                b1 + c1 * c1);
    float e2 = (float)Math.sqrt(a2 * a2 + b2 *
                                b2 + c2 * c2);
    d = d / (e1 * e2);
    float pi = (float)3.14159;
    float A = (180 / pi) * (float)(Math.acos(d));
    System.out.println("Angle is "+ A +" degree");
}
 
// Driver code
public static void main(String[] args)
{
    float a1 = 1;
    float b1 = 1;
    float c1 = 2;
    float d1 = 1;
    float a2 = 2;
    float b2 = -1;
    float c2 = 1;
    float d2 = -4;
    distance(a1, b1, c1,
             a2, b2, c2);
}
}
 
// This code is contributed
// by Amber_Saxena.


Python
# Python program to find the Angle between
# two Planes in 3 D.
 
import math
 
# Function to find Angle
def distance(a1, b1, c1, a2, b2, c2):
     
    d = ( a1 * a2 + b1 * b2 + c1 * c2 )
    e1 = math.sqrt( a1 * a1 + b1 * b1 + c1 * c1)
    e2 = math.sqrt( a2 * a2 + b2 * b2 + c2 * c2)
    d = d / (e1 * e2)
    A = math.degrees(math.acos(d))
    print("Angle is"), A, ("degree")
 
# Driver Code
a1 = 1
b1 = 1
c1 = 2
d1 = 1
a2 = 2
b2 = -1
c2 = 1
d2 = -4
distance(a1, b1, c1, a2, b2, c2)


C#
// C# program to find
// the Angle between
// two Planes in 3 D.
using System;
 
class GFG
{
     
// Function to find Angle
static void distance(float a1, float b1,
                     float c1, float a2,
                      float b2, float c2)
{
     
    float d = (a1 * a2 + b1 *
               b2 + c1 * c2);
    float e1 = (float)Math.Sqrt(a1 * a1 + b1 *
                                b1 + c1 * c1);
    float e2 = (float)Math.Sqrt(a2 * a2 + b2 *
                                b2 + c2 * c2);
    d = d / (e1 * e2);
    float pi = (float)3.14159;
    float A = (180 / pi) * (float)(Math.Acos(d));
    Console.Write("Angle is "+ A +" degree");
}
 
// Driver code
public static void Main()
{
    float a1 = 1;
    float b1 = 1;
    float c1 = 2;
    float a2 = 2;
    float b2 = -1;
    float c2 = 1;
     
    distance(a1, b1, c1,
            a2, b2, c2);
}
}
 
// This code is contributed
// by ChitraNayal


PHP


Javascript


输出:
Angle is 60.0 degree