简体   繁体   English

根据三个平面的法线及其与该点的距离获取一个点

[英]Get a point based on the normals of three planes and the distance of the point from them

I have the normals of three planes which are at 90 degrees to each other and pass through the origin. 我有三个平面的法线,它们彼此成90度角并穿过原点。

I also have the distances of a point to the three planes. 我也有一个点到这三个平面的距离。 How can I determine the position of the point in C#? 如何确定点在C#中的位置?

Heres what I have so far... 这是我到目前为止所拥有的...

    public static Vector3 RealWorldSpaceToOtherSpace(Vector3 realspace, Vector4 clipplane)
    {
        // Work out the normal vectors of 3 imaginary planes
        Vector3 floor = new Vector3(clipplane.X, clipplane.Y, clipplane.Z);
        Vector3 centre = new Vector3(1f, -clipplane.X / clipplane.Y, 0f);
        Vector3 wall = Vector3.Cross(floor, centre);

        // Get distances from the planes
        float distanceToFloor = realspace.y;
        float distanceToCentre = realspace.x;
        float distanceToWall = realspace.z;

        //   ?
        //   ?  do stuff here
        //   ?

        // return ????
    }

Since the planes are at 90 degrees to each other, and pass through the origin, their normals form an orthogonal coordinate system with the same origin. 由于这些平面彼此成90度角并穿过原点,因此它们的法线形成具有相同原点的正交坐标系。 Thus the distance to each plane is the coordinate of the point along the axis corresponding to the plane's (normalized) normal, in the new coordinate system. 因此,在新坐标系中,到每个平面的距离是沿点的坐标,该点沿着与平面的(归一化的)法线相对应的轴。

Hence find the normalized normals of each plane, multiply by the corresponding distance to the plane, and add up to find the point. 因此,找到每个平面的归一化法线,乘以到该平面的相应距离,然后累加即可找到该点。

A caveat is that you need to know which side of each plane the point is on; 需要注意的是,您需要知道该点在每个平面的哪一侧 if it is on the other side of the normal, put a minus sign in front of the corresponding distance. 如果它在法线的另一侧,则在相应距离的前面放置一个减号。

When given the distance from the point to one plane. 当给出从点到一个平面的距离时。 The point can now be at any one point inside a plane that is at the defined distance from your first plane, so you have narrowed down the position from anywhere within the 3 dimensions to anywhere with these subset of the 3rd dimension which only has 2 dimensions.. 现在,该点可以位于与第一个平面已定义距离的平面内的任意点上,因此您已将位置从3维内的任何位置缩小到第3维这些子集(仅有2个维)的任何位置..

When you are given the distance from the point to a second plane. 当给定从点到第二平面的距离时。 You now have that same information, a plane at which the point can be. 现在,您具有相同的信息,即该点所在的平面。 You will notice that both of these plains intersect and form a line. 您会注意到这两个平原相交并形成一条线。 There's no need to store this line. 无需存储此行。 Just know that you have narrowed down the possible point's position to 1 dimension. 只知道您已将可能点的位置缩小到1维。

Finally you are given the distance from the point to the third plane. 最后,您将获得从该点到第三平面的距离。 You can create the new plane at the defined distance from the original plane , and this plane should intersect the other 2 new planes. 您可以在距原始平面已定义的距离处创建新平面,并且该平面应与其他两个新平面相交。 All three planes will intersect at one point, which will be the position of the point. 所有三个平面将在一个点相交,这将是该点的位置。

Thankfully we can add the distance to the planes vector in order to create the new planes. 幸运的是,我们可以将距离添加到平面向量中以创建新的平面。 And then we can finally get the point's position by using each of the plane's relevant dimensions in order to get the point's position. 然后,我们最终可以通过使用平面的每个相关尺寸来获取点的位置,以获得点的位置。

public static Vector3 RealWorldSpaceToOtherSpace(Vector3 realspace, Vector4 clipplane)
{
    // Work out the normal vectors of 3 imaginary planes
    Vector3 floor = new Vector3(clipplane.X, clipplane.Y, clipplane.Z);
    Vector3 centre = new Vector3(1f, -clipplane.X / clipplane.Y, 0f);
    Vector3 wall = Vector3.Cross(floor, centre);

    // Get distances from the planes
    // Distance is represented as a Vector, since it needs to hold
    // the direction in 3d space.
    Vector3 distanceToFloor = new Vector3(0f,   realspace.y ,0f,);
    Vector3 distanceToCentre = new Vector3(     realspace.x ,0f,0f,);
    Vector3 distanceToWall = new Vector3(0f,0f, realspace.z );

    // Create planes that contain all the possible positions of the point
    // based on the distance from point to the corresponding plane.
    Vector3 pointY = floor + distanceToFloor;
    Vector3 pointX = centre + distanceToCentre;
    Vector3 pointZ = wall + distanceToWall;

    // Now that we have all 3 point's dimensions, we can create a new vector that will hold its position.
    Vector3 point = new Vector3(pointX.x,pointY.y, pointZ.z);

    return point
}

Note that there is a plane struct in Unity. 请注意,Unity中有一个平面结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM