CGAL库应用:仿射变换(点的旋转、平移、放大)"/>
(三)CGAL库应用:仿射变换(点的旋转、平移、放大)
因为某些时候需要点的坐标进行平移、旋转、缩放,cgal库也以kernel object的形式提供了仿射变换,就和点、线段、向量、矩形一样,仿射变换也是这样类似的几何kernel object,定义在头文件#include<CGAL/Aff_transformation_2.h>中,以下代码是针对点的简单的旋转、平移和放大,而且cgal也提供了仿射变化的相关运算,得到复合的仿射变换,最后得到的结果是一样的,运行结果如图所示。
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include<CGAL/Aff_transformation_2.h>#include<fstream>
#include<iostream>typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Aff_transformation_2 Transformation;
typedef K::Point_2 Point;
typedef K::Vector_2 Vector;using namespace std;
int main(int argc, char *argv[]){Transformation transformation_ROTATION(CGAL::ROTATION,sin(3.1415/4),cos(3.1415 / 4));Transformation transformation_TRANSLATION(CGAL::TRANSLATION, Vector(4, 0));Transformation transformation_SCALING(CGAL::SCALING, 100);Point A(1, 1);Point B = transformation_ROTATION(A);cout << B << endl;B = transformation_TRANSLATION(B);cout << B << endl;B = transformation_SCALING(B);cout << B << endl;Transformation transformation2 = transformation_SCALING*(transformation_TRANSLATION * transformation_ROTATION);Point C = transformation2(A);cout << C << endl;system("pause");return 0;
}
当然官网的文档可以看出,仿射变换的构造函数有很多种,官方文档传送门:.html#a47f305715cb75778048ea7329b5c02dc
更多推荐
(三)CGAL库应用:仿射变换(点的旋转、平移、放大)
发布评论