XZ (Y=0) 平面上で P が Q に投影されるように 4x4 S行列を決定する方法は?
Q = SP
光線の座標は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);
}