将平面从 Point/Normal/D 转换为平面方程

问题描述

我有一个平面类,将平面存储为

Vector position;
Vector normal;
float d;

(向量只是辅助类中的 x,y,z)

多年来一直使用它,几乎可以满足我的所有目的。但是,我将它用作学者,并没有真正考虑它的工作原理。

所以...我需要将其转换为 float[4] 格式,供朋友用于某些 OpenGL 渲染。在 float[4] 中将点/法线/d 转换为平面方程的正确方法是什么?我尝试的一切似乎都有点偏离。

[编辑] 这是平面的Create()函数,它给d赋值...

void            Create(Vector thePoint,Vector thenormal)
    {
        thenormal.normalize();
        pos=thePoint;
        normal=thenormal;
        d=-thenormal.Dot(thePoint);
    }

解决方法

使用齐次坐标点是

 Point = [x,y,z,1] 

定义平面的方程

eq1

平面坐标需要以下4个值

Plane = [n_x,n_y,n_z,-d]

其中 (n_x,n_z) 是法向量,d 是到原点的距离。

现在取点和平面的点积得到方程

[x,1] . [n_x,-d] = 0

x*n_x + y*n_y + z*n_z - d = 0

C# 代码中这是

public float[] GetCoord(Plane plane)
{
   return new float[] { plane.normal.X,plane.normal.Y,plane.normal.Z,-plane.d };
}