2012-04-13 61 views
1
  • 我有一個Plane(普通,d)和Vector3點(X,Y,Z)。
  • 我需要將平面轉換到該點的X距離。我怎麼做?

我想出這個..如何將平面轉換爲X距離的點?

plane = Plane.Transform(plane, Matrix.CreateTranslation(

但找不出什麼的地方在那裏。它必須是點積,Plane.Normal和我的Vector3

編輯:

我想這一點。

public static Plane MoveTo(this Plane p, Vector3 point, float distance) 
{ 
    Vector3 planeVector = p.Normal * p.D; 

    Matrix matrix = Matrix.CreateTranslation(Vector3.Normalize(planeVector)) * 
     distance * Math.Sign(Vector3.Dot(planeVector, point - planeVector)) 

    return Plane.Transform(p, matrix); 
} 

如果有人認爲這是錯誤或錯誤的,請注意。

+0

你有沒有檢查MSDN? http://msdn.microsoft.com/en-us/library/windows/desktop/bb281689(v=vs.85).aspx – ABH 2012-04-13 07:03:03

+0

@hamad不,我沒有,但我用同樣的方法。我只需要一種方法。 – AgentFire 2012-04-13 07:19:10

+0

那它會對你有用嗎?創建一個新的矩陣,並將其傳遞給Plane.Transform() – ABH 2012-04-13 07:23:23

回答

3

從點P到平面的距離Pi爲:

enter image description here

enter image description here

你應該calc下當前d(P,PI),。減去該量X,並且然後只需計算D即可獲得新飛機。

編輯:

// This line has no sense... is useless do that. 
Vector3 planeVector = p.Normal * p.D; 

要知道一個點和平面之間的關係,你只需要計算其方程:R = AX + +鋯+ d,其中(A,B,C)是正常和(X,Y,Z)的點...

如果(R == 0)的點被包含在平面
如果(R> 0)的點是前//或反之亦然
如果(R < 0),該點是背面

R = plane.DotCoordinate(point);  
distance*=(R>0) ? 1 : -1; // or viceversa, i'm not sure now 
Matrix matrix = Matrix.CreateTranslation(plane.Normal * distance); 
return Plane.Transform(p, matrix); 
+0

順便說一句,我已經有了從點到飛機的距離(通過點積)。我需要一個'Vector3'-翻譯器。我可以使用平面矩陣平移的值。 – AgentFire 2012-04-13 07:04:00

+0

只需從D中減去或添加到它? – AgentFire 2012-04-13 07:08:19

+0

如果初始距離d(P,PI)爲100,並且要朝向點平移10個單位,新的距離將是100-10 = 90 ...就只需要計算「d」知道d( P,pi)== 90. – Blau 2012-04-13 08:30:07