如何确定4x4的S矩阵,使得P在XZ平面(Y=0)上被投影到Q上?
Q = S P
如何确定4x4的S矩阵,使得P在XZ平面(Y=0)上被投影到Q上?
Q = S P
L=[lx ly lz 1]'
如果给定 Hessian 正规形式(也称为齐次坐标系),则 E 为:
E=[nx, ny, ,nz, d]'
其中[nx,ny,nz]是平面的法向量,d是它到原点的有符号距离。
然后将任意点P(也在齐次坐标中)投影到通过投影中心L的平面E的矩阵S为:
S=eye(4)*(L'*E)-L*E'
中心投影是
Q=S*P
% 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
附言: 为了得出这个结果,注意到通过L和P的直线可以写成一个4x4的Plücker矩阵。
Rx=L*P'-P*L'.
Q=Rx*E
=(L*P'-P*L')*E
=(eye(4)*(L'*E)-L*E')*P
=S*P
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)
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_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 )
伪代码如下:
// 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);
}