2009/03/23

Intersection of Line and Plane

以前用偷吃步的方法在已知x,y狀況下與某面的交點z值如下


public float getHeight(Vector3 camPos, Vector3 tP1, Vector3 tP2, Vector3 tP3){
final Vector3 faceN = Vector3.getNormal(tP1, tP2, tP3);
//取一點為該面上一點
//求平面方程算出Ax+By+Cz+D=0中的D
final float d = -(faceN.x()*tP1.x()+ faceN.y()*tP1.y()+ faceN.z()*tP1.z());
//帶入A,B,C,D,x,z求出y
return (faceN.x()*camPos.x() + faceN.z()*camPos.z() + d) / -faceN.y();
}

正統解法:
(Lo + Lv * t) * Pn + Pd = 0
t ← (Pd + (Lo * Pn)) / Lv * Pn
交點 ← Lo + Lv * t

Ref:
Graphics Gems

沒有留言 :