简体   繁体   中英

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.

I also have the distances of a point to the three planes. How can I determine the position of the point in 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. 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..

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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