CGAL在三维中按x轴旋转

CGAL rotation by x-axis in 3D

本文关键字:旋转 三维 CGAL      更新时间:2023-10-16

CGAL中是否有预定义的x轴旋转。如果没有,为什么不呢?如果我必须定义它,我会怎么做?

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Aff_transformation_3.h>
#include <cmath>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Aff_transformation_3<Kernel> transform3D;
transform3D rotationX(double angle)
{
    const double cosa{cos(angle)};
    const double sina{sin(angle)};
    return transform3D(
            1.0, 0.0, 0.0,
            0.0, cosa, -sina,
            0.0, sina, cosa);
}
void test()
{
    using Point3D = CGAL::Point_3<Kernel>;
    Point3D p{1.0,1.0,1.0};
    const transform3D rotate{rotationX(M_PI_2)};
    rotate(p);
}

要在3D中旋转,可以使用Aff_transformation_3并使用变换矩阵指定变换矩阵。

例如:要在x轴上旋转某个角度x,可以使用以下矩阵:

1   0        0         0
0   cos(x)   -sin(x)   0
0   sin(x)   cos(x)    0
0   0        0         1