射线有坐标r(t) = L + t * (P-L)。这是组件形式:
r_x = L_x + t*(P_x-L_x)
r_y = L_y + t*(P_y-L_y)
r_z = L_z + t*(P_z-L_z)
现在你需要找到Q = r(t) 使得r_y = 0
。这是在什么时候完成的t = -L_y/(P_y-L_y)
or
Q_x = L_x - L_y/(P_y-L_y)*(P_x-L_x)
Q_y = 0
Q_z = L_z - L_y/(P_y-L_y)*(P_z-L_z)
一般来说,投影平面由单位法向量定义n=(n_x,n_y,n_z)
以及平面到原点的距离d。一个点r(t) 位于平面上,如果r(t)·n=d其中·是向量点积。
点的解决方案Q一般来说是
t = (d - n·L)/(n·(P-L))
Q = L + t *( P-L )
伪C上面的样式代码是:
// L : Light Source
// P : Point to be projected
// n : Plane _unit_ normal vector
// d : Distance of plane to the origin
// returns: The point Q along the ray that intersects the plane.
Vector3 HitPlaneWithRay(Vector3 L, Vector3 P, Vector3 n, double d)
{
double t = (d-Dot(L,n))/Dot(P-L,n);
return L + t*(P-L);
}
// Intersect ray with floor (Normal=[0,1,0], Distance=0)
Vector3 HitFloorWithRay(Vector3 L, Vector3 P)
{
return HitPlaneWithRay(L, P, Vector3.J, 0);
}