首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在POV中围绕矢量旋转物体?

如何在POV中围绕矢量旋转物体?
EN

Stack Overflow用户
提问于 2017-12-31 02:27:17
回答 3查看 1K关注 0票数 0

我发现在POV中很难找到物体从一个给定点移动到另一个点的旋转。

几何上,很简单就可以找到:我计算出从原点到目标点的距离Dist (绿色),并在<Dist, 0, 0> (蓝色)创建Point0。然后从Point0PointT计算出它们之间的夹角和垂直于它们的角度。AngleD围绕Perp的旋转将Point0移动到Point1 = PointT

在POV中,我可以使用vaxis_rotate计算Point1.但是我想要旋转一个物体(当然,它不会是一个球体),我看不出有什么明显的方法可以做到这一点。我尝试了rotate -AngleD*Perp,但结果略有不同(红色)。

我如何处理一个对象,vaxis_rotate如何处理某个对象?

代码语言:javascript
复制
#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}
}

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-12-31 11:51:50

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

代码语言:javascript
复制
#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

应用于上述示例中的球体:

代码语言:javascript
复制
#declare Angle = VAngle(PointT, Point0);
#declare Perp = VPerp_To_Plane(PointT, Point0);
sphere{
    Point0, R
    RotMatFromVectorAndAngle(Perp, Angle)
}
票数 0
EN

Stack Overflow用户

发布于 2018-11-29 21:58:56

查找Axis_Rotate_Trans in transforms.inc

代码语言:javascript
复制
#include "transforms.inc" 

sphere {
  ..., ...
  Axis_Rotate_Trans(
    VPerp_To_Plane(<...>, <...>), 
    VAngleD(<...>, <...>)
  )
}
票数 0
EN

Stack Overflow用户

发布于 2020-05-29 22:45:04

因此,简单地说,假设是一个单位向量,假设你想要一个α度的旋转。然后v1 v2 v3 *alpha将不会产生所需的转换。这是一个错误,一个严重的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48039475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档