2016-03-07 71 views
0

我有三個平面的法線,這三個平面相互成90度,並穿過原點。根據三個平面的法線和距離它們的距離得到一個點

我也有一個點到三架飛機的距離。我怎樣才能確定在C#中的位置?

繼承人是我迄今爲止...

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 ???? 
    } 

回答

1

由於飛機是在90度到對方,並通過原點,它們的法線形成一個直角座標系與相同起源。因此,到每個平面的距離是在新座標系中沿着與平面(歸一化)法線對應的軸的點的座標。

因此,找到每個平面的歸一化法線,乘以與該平面相應的距離,並加起來找到該點。

需要注意的是,您需要知道點的每個平面的哪一個;如果它位於法線的另一側,則在相應距離的前面放一個負號。

+0

噢!謝謝!! –

1

當給定從點到一個平面的距離時。該點現在可以位於與第一個平面相距預定距離的平面內的任意點上,因此您可以將該位置從3維範圍內的任何位置縮小到第三維僅具有2維的這些子集的任何位置..

當您給出從點到第二個平面的距離。你現在有了同樣的信息,這是一個可以達到的點。你會注意到這兩個平原相交併形成一條線。沒有必要存儲這條線。只要知道你已經將可能點的位置縮小到1維。

最後給出從點到第三平面的距離。您可以在距原始平面定義的距離上創建新平面,並且該平面應與其他2個新平面相交。所有三架飛機將在一點相交,這將是該點的位置。

謝天謝地,我們可以添加到平面矢量的距離,以創建新的平面。然後,我們可以通過使用每個飛機的相關尺寸來獲得該點的位置,以獲得該點的位置。

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 
} 

請注意,在Unity中有一個plane結構。

相關問題