(三)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; }當然官網的文檔可以看出,仿射變換的構造函數有很多種,官方文檔傳送門:https://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Aff__transformation__2.html#a47f305715cb75778048ea7329b5c02dc
總結
以上是生活随笔為你收集整理的(三)CGAL库应用:仿射变换(点的旋转、平移、放大)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 张小龙的30条产品法则
- 下一篇: 【回眸】牛客网刷刷刷!嵌入式软件中也会遇