一个轻型库:geometry template library

最近在google code 上面看了很多3d方面的优秀的库,以及一些游戏引擎, 学习到了很多东西,当然了要归功于开源,再一次被开源的魅力所感动。

这里我想和大家分享一个小型的3D库,名字简称也叫GTL: Geometry Template Library。说到GTL一般人都会想到graphy template library ...

这个库所有类列表:

file  box2.hpp   二维包围盒
file  box3.hpp  三维包围体
file  circle.hpp  圆
file  complex.hpp 复数
file  gtl.hpp  
file  matrix3.hpp 3×3旋转矩阵
file  matrix4.hpp  4×4齐次矩阵
file  plane.hpp  平面
file  quat.hpp   四元数
file  ray.hpp   射线
file  sphere.hpp  包围球体 
file  vec2.hpp 
file  vec3.hpp  向量
file  vec4.hpp
file  xfbox3.hpp  立方体 

所有的模板类都是在gtl名字空间中。

基于这个轻型库,可以很容易进行二次开发,可以添加自己的东西,构建自己的库。

链接地址:http://code.google.com/p/geometry/

库下载地址:http://code.google.com/p/geometry/downloads/list

在Boost.Geometry中,你可以使用`boost::geometry::model::d2::point_xy`和`boost::geometry::model::ring`来创建一个二维空间中的圆形。首先,你需要包含必要的头文件,并定义一个点类型作为圆心以及一个环类型来表示圆形边界。下面是一个简单的示例: ```cpp #include <boost/geometry.hpp> #include <boost/geometry/geometries/register/point.hpp> #include <boost/geometry/geometries/ring.hpp> // 定义圆心点类型 typedef boost::geometry::model::d2::point_xy<double> point_type; // 定义圆形边界的环类型 typedef boost::geometry::model::ring<point_type> ring_type; // 创建一个固定的半径 double radius = 5.0; // 创建圆心点 point_type center(0.0, 0.0); // 创建一个包含中心点的点集合 std::vector<point_type> circle_points = {center + boost::geometry::unit_vector(radius, 0), // 上方 center - boost::geometry::unit_vector(radius, 0), // 下方 center + boost::geometry::unit_vector(radius, 1), // 右方 center - boost::geometry::unit_vector(radius, 1) }; // 左方 // 构建圆形边界,使用逆时针顺序 ring_type boundary; for (const auto& p : circle_points) { boundary.push_back(p); } // 最后,将边界点集合并圆心点组成一个圆形 boost::geometry::model::polygon<point_type> circular_polygon(center, boundary); ``` 在这个例子中,我们创建了一个圆形边界并将其封装在一个`boost::geometry::model::polygon`对象中。注意,由于Boost.Geometry默认使用逆时针方向构建环,所以这里的顺时针方向是通过手动调整点的顺序实现的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值