0

我发现在 POV-Ray 中很难找到将对象从一个给定点移动到另一个给定点的旋转。

几何上很容易找到:我计算Dist从原点到目标点的距离PointT(绿色),并Point0<Dist, 0, 0>(蓝色)处创建。然后我计算它们之间的角度Point0PointT垂直于它们的角度。AngleDaround的旋转Perp移动Point0Point1= 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}
}

在此处输入图像描述

4

3 回答 3

0

在 transforms.inc 中查找 Axis_Rotate_Trans

#include "transforms.inc" 

sphere {
  ..., ...
  Axis_Rotate_Trans(
    VPerp_To_Plane(<...>, <...>), 
    VAngleD(<...>, <...>)
  )
}
于 2018-11-29T21:58:56.233 回答
0

meowgoesthedog 提供的链接中的旋转矩阵给出了预期的结果。

#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)
}
于 2017-12-31T11:51:50.553 回答
0

因此,简而言之,设 是一个单位向量,并假设您想要围绕它旋转 alpha 度。然后 v1 v2 v3 *alpha 将不会产生所需的转换。这是一个错误,一个严重的错误。

于 2020-05-29T22:45:04.740 回答