小弧光的博客

公众号:小弧光黑板报

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

统计

使用 cgal 库计算向量的夹角

 

#include <vector>
#include <iostream>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Ray_2.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/intersections.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Vector_2 Vector_2;
typedef Kernel::Segment_2 Segment_2;
typedef Kernel::Circle_2 Circle_2;
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Line_2 Line_2;
int main()
{
Vector_2 v1(-1, -1);
Vector_2 v2(0, -1);
// Compute the scalar product and squared length of the vectors
double scalar_product = CGAL::to_double(v1 * v2);
double squared_length_v1 = CGAL::to_double(v1.squared_length());
double squared_length_v2 = CGAL::to_double(v2.squared_length());
// Compute the angle between the vectors
double cos_angle = scalar_product / std::sqrt(squared_length_v1 * squared_length_v2);
double angle = std::acos(cos_angle)* (180 /CGAL_PI);
std::cout << "angle: " << angle << std::endl;
return 0;
}

 

posted on   小弧光  阅读(150)  评论(1编辑  收藏  举报

相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示