📜  在3D平面中找到点的垂直脚

📅  最后修改于: 2021-04-21 20:49:20             🧑  作者: Mango

给定3-D中的一个点(x1,y1,z1)和平面方程的系数,我们必须找到3D平面中一个点的垂直脚。

例子:

方法:平面方程式为ax + x + cz + d =0。因此,法线与平面的方向比为(a,b,c) 。令N为从给定点到给定平面的垂直脚,因此,线PN的有向比(a,b,c)穿过P(x1,y1,z1)。

PN线的等式为:-

因此,PN线上的任何点都可以写成:-

由于N位于直线和平面中,因此将满足(ax + by + cz + d = 0)。

现在,以k表示的点N的坐标将是:

下面是上述的实现:

C++
// C++ program to find
// foot of perpendicular
// of a point in a 3 D plane.
#include 
#include 
#include 
#include 
using namespace std;
  
// Function to find foot of perpendicular
void foot(float a, float b,
          float c, float d,
          float x1, float y1,
          float z1)
{
    float k = (-a * x1 - b * y1 - c * z1 - d) / (float)(a * a + b * b + c * c);
    float x2 = a * k + x1;
    float y2 = b * k + y1;
    float z2 = c * k + z1;
  
    std::cout << std::fixed;
    std::cout << std::setprecision(1);
    cout << " x2 = " << x2;
    cout << " y2 = " << y2;
    cout << " z2 = " << z2;
}
  
// Driver Code
int main()
{
    float a = 1;
    float b = -2;
    float c = 0;
    float d = 0;
    float x1 = -1;
    float y1 = 3;
    float z1 = 4;
  
    // function call
    foot(a, b, c, d, x1, y1, z1);
    return 0;
}
// This code is contributed  by Amber_Saxena.


Java
// Java program to find
// foot of perpendicular
// of a point in a 3 D plane.
import java.util.*;
import java.text.*;
  
class solution
{
  
// Function to find foot of perpendicular
static void foot(float a, float b,
        float c, float d,
        float x1, float y1,
        float z1)
{
    float k = (-a * x1 - b * y1 - c * z1 - d) / (float)(a * a + b * b + c * c);
    float x2 = a * k + x1;
    float y2 = b * k + y1;
    float z2 = c * k + z1;
    DecimalFormat form = new DecimalFormat("0.0");
    System.out.print(" x2 = " +form.format(x2));
    System.out.print(" y2 = " +form.format(y2));
    System.out.print( " z2 = " +form.format(z2));
}
  
// Driver Code
public static void main(String arr[])
{
    float a = 1;
    float b = -2;
    float c = 0;
    float d = 0;
    float x1 = -1;
    float y1 = 3;
    float z1 = 4;
  
    // function call
    foot(a, b, c, d, x1, y1, z1);
  
}
}


Python3
# Python3 program to find 
# foot of perpendicular 
# of a point in a 3 D plane. 
  
# Function to find foot of perpendicular 
def foot(a, b, c, d, x1, y1, z1) :
  
    k = (-a * x1 - b * y1 - c * z1 - d) / (a * a + b * b + c * c); 
    x2 = a * k + x1; 
    y2 = b * k + y1; 
    z2 = c * k + z1; 
  
    print("x2 =",round(x2,1)) 
    print("y2 =",round(y2,1))
    print("z2 =",round(z2,1))
  
  
# Driver Code 
if __name__ == "__main__" : 
  
    a = 1
    b = -2 
    c = 0
    d = 0 
    x1 = -1 
    y1 = 3
    z1 = 4 
  
    # function call 
    foot(a, b, c, d, x1, y1, z1) 
  
# This code is contributed by Ryuga


C#
// C# program to find 
// foot of perpendicular 
// of a point in a 3 D plane. 
using System;
using System.Globalization;
  
class GFG
{ 
  
// Function to find foot of perpendicular 
static void foot(float a, float b, 
        float c, float d, 
        float x1, float y1, 
        float z1) 
{ 
    float k = (-a * x1 - b * y1 - c * z1 - d) / 
                (float)(a * a + b * b + c * c); 
    float x2 = a * k + x1; 
    float y2 = b * k + y1; 
    float z2 = c * k + z1; 
    NumberFormatInfo form = new NumberFormatInfo();
    form.NumberDecimalSeparator = ".";
    Console.Write(" x2 = " + x2.ToString(form)); 
    Console.Write(" y2 = " + y2.ToString(form)); 
    Console.Write( " z2 = " + z2.ToString(form)); 
} 
  
// Driver Code 
public static void Main(String []arr) 
{ 
    float a = 1; 
    float b = -2; 
    float c = 0; 
    float d = 0; 
    float x1 = -1; 
    float y1 = 3; 
    float z1 = 4; 
  
    // function call 
    foot(a, b, c, d, x1, y1, z1); 
} 
} 
  
// This code contributed by Rajput-Ji


PHP


输出:
x2 = 0.4 y2 = 0.2 z2 = 4.0