如何确定 4x4 S矩阵以使 P 在 XZ (Y=0) 平面上投影到 Q 中?
Q = S P
射线的坐标为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)
或
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 )· n = d则点r ( t ) 位于平面上,其中 · 是向量点积。
点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);
}
我将给出从点L到平面E的中心投影的一般解决方案(假设L不包含在E中)。
为方便起见,我将使用 Octave/MATLAB 表示法。
让L在齐次坐标中给出
L=[lx ly lz 1]'
并且E以 Hessian 范式给出(也是齐次坐标)
E=[nx, ny, ,nz, d]'
其中 [nx, ny, nz] 是平面的法线,d 是它到原点的有符号距离。
那么通过投影L的中心将任意点P(也在齐次坐标中)投影到平面E的矩阵S是
S=eye(4)*(L'*E)-L*E'
中心投影是
Q=S*P
作为 Octave/MATLAB 函数
% A matrix S describing central projection to a plane E
% L a point in homogeneous coordinates of projective 3-space
% E a plane in homogeneous coordinates of projective 3-space
% Requirement: scalar product of L and E is non-zero (i.e. L is not contained in E)
function S = central_projection_to_plane(L, E)
S = [
+ L(2)*E(2) + L(3)*E(3) + L(4)*E(4), - L(1)*E(2) , - L(1)*E(3) , - L(1)*E(4) ;
- L(2)*E(1) , + L(1)*E(1) + L(3)*E(3) + L(4)*E(4) , - L(2)*E(3) , - L(2)*E(4) ;
- L(3)*E(1) , - L(3)*E(2) , + L(1)*E(1) + L(4)*E(4) + L(2)*E(2) , - L(3)*E(4) ;
- L(4)*E(1) , - L(4)*E(2) , - L(4)*E(3) , + L(1)*E(1) + L(2)*E(2) + L(3)*E(3)
];
end % function
PS:要得出这个,请注意通过L和P的线可以写成 4x4 Plücker 矩阵
Rx=L*P'-P*L'.
直线 Rx 和平面E的交点很简单
Q=Rx*E
=(L*P'-P*L')*E
=(eye(4)*(L'*E)-L*E')*P
=S*P