如何在 POV-Ray 中围绕矢量旋转对象?
How to rotate an object around a vector in POV-Ray?
我发现在 POV-Ray 中找到将对象从一个给定点移动到另一个给定点的旋转非常困难。
在几何上很容易找到:我计算从原点到目标点 PointT
(绿色)的距离 Dist
,并在 <Dist, 0, 0>
处创建 Point0
(蓝色的)。然后我从 Point0
和 PointT
计算它们之间的角度和垂直于它们的角度。围绕 Perp
旋转 AngleD
将 Point0
移动到 Point1
= PointT
.
在 POV-Ray 中我可以使用 vaxis_rotate
来计算 Point1
。但我想实际旋转一个对象(当然,它不会是一个球体),但我没有看到一个明显的方法来做到这一点。我试过 rotate -AngleD*Perp
,但结果略有不同(红色)。
我如何对一个对象做些什么,vaxis_rotate
对一个点做了什么?
#declare PointT = <2, 2, 2>;
#declare Dist = VDist(<0, 0, 0>, PointT);
#declare Point0 = <Dist, 0, 0>;
#declare AngleD = VAngleD(PointT, Point0);
#declare Perp = VPerp_To_Plane(PointT, Point0);
#declare Point1 = vaxis_rotate(Point0, Perp, -AngleD);
sphere{Point0, R pigment{color Blue} }
sphere{Point1, R pigment{color Green} }
sphere{
Point0, R
rotate -AngleD*Perp
pigment{color Red}
}
meowgoesthedog提供的link中的旋转矩阵给出了预期的结果。
#macro RotMatFromVectorAndAngle(Vector, Angle)
// takes normalized vector and angle in radians
#local U = Vector.x;
#local V = Vector.y;
#local W = Vector.z;
#local Sin = sin(Angle);
#local Cos = cos(Angle);
#local M11 = U*U + (1-U*U)*Cos;
#local M12 = U*V*(1-Cos) - W*Sin;
#local M13 = U*W*(1-Cos) + V*Sin;
#local M21 = U*V*(1-Cos) + W*Sin;
#local M22 = V*V + (1-V*V)*Cos;
#local M23 = V*W*(1-Cos) - U*Sin;
#local M31 = U*W*(1-Cos) - V*Sin;
#local M32 = V*W*(1-Cos) + U*Sin;
#local M33 = W*W + (1-W*W)*Cos;
matrix <M11, M12, M13,
M21, M22, M23,
M31, M32, M33,
0 , 0 , 0 >
#end
应用于上例中的球体:
#declare Angle = VAngle(PointT, Point0);
#declare Perp = VPerp_To_Plane(PointT, Point0);
sphere{
Point0, R
RotMatFromVectorAndAngle(Perp, Angle)
}
在 transforms.inc
中寻找 Axis_Rotate_Trans
#include "transforms.inc"
sphere {
..., ...
Axis_Rotate_Trans(
VPerp_To_Plane(<...>, <...>),
VAngleD(<...>, <...>)
)
}
因此,简而言之,令 为一个单位向量,并假设您想要围绕它旋转 alpha 度。然后 v1 v2 v3 *alpha 将不会产生所需的转换。这是一个错误,一个严重的错误。
我发现在 POV-Ray 中找到将对象从一个给定点移动到另一个给定点的旋转非常困难。
在几何上很容易找到:我计算从原点到目标点 PointT
(绿色)的距离 Dist
,并在 <Dist, 0, 0>
处创建 Point0
(蓝色的)。然后我从 Point0
和 PointT
计算它们之间的角度和垂直于它们的角度。围绕 Perp
旋转 AngleD
将 Point0
移动到 Point1
= PointT
.
在 POV-Ray 中我可以使用 vaxis_rotate
来计算 Point1
。但我想实际旋转一个对象(当然,它不会是一个球体),但我没有看到一个明显的方法来做到这一点。我试过 rotate -AngleD*Perp
,但结果略有不同(红色)。
我如何对一个对象做些什么,vaxis_rotate
对一个点做了什么?
#declare PointT = <2, 2, 2>;
#declare Dist = VDist(<0, 0, 0>, PointT);
#declare Point0 = <Dist, 0, 0>;
#declare AngleD = VAngleD(PointT, Point0);
#declare Perp = VPerp_To_Plane(PointT, Point0);
#declare Point1 = vaxis_rotate(Point0, Perp, -AngleD);
sphere{Point0, R pigment{color Blue} }
sphere{Point1, R pigment{color Green} }
sphere{
Point0, R
rotate -AngleD*Perp
pigment{color Red}
}
meowgoesthedog提供的link中的旋转矩阵给出了预期的结果。
#macro RotMatFromVectorAndAngle(Vector, Angle)
// takes normalized vector and angle in radians
#local U = Vector.x;
#local V = Vector.y;
#local W = Vector.z;
#local Sin = sin(Angle);
#local Cos = cos(Angle);
#local M11 = U*U + (1-U*U)*Cos;
#local M12 = U*V*(1-Cos) - W*Sin;
#local M13 = U*W*(1-Cos) + V*Sin;
#local M21 = U*V*(1-Cos) + W*Sin;
#local M22 = V*V + (1-V*V)*Cos;
#local M23 = V*W*(1-Cos) - U*Sin;
#local M31 = U*W*(1-Cos) - V*Sin;
#local M32 = V*W*(1-Cos) + U*Sin;
#local M33 = W*W + (1-W*W)*Cos;
matrix <M11, M12, M13,
M21, M22, M23,
M31, M32, M33,
0 , 0 , 0 >
#end
应用于上例中的球体:
#declare Angle = VAngle(PointT, Point0);
#declare Perp = VPerp_To_Plane(PointT, Point0);
sphere{
Point0, R
RotMatFromVectorAndAngle(Perp, Angle)
}
在 transforms.inc
中寻找 Axis_Rotate_Trans#include "transforms.inc"
sphere {
..., ...
Axis_Rotate_Trans(
VPerp_To_Plane(<...>, <...>),
VAngleD(<...>, <...>)
)
}
因此,简而言之,令 为一个单位向量,并假设您想要围绕它旋转 alpha 度。然后 v1 v2 v3 *alpha 将不会产生所需的转换。这是一个错误,一个严重的错误。