前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CGAL 一般多边形

CGAL 一般多边形

作者头像
用户3519280
发布2023-07-06 14:39:54
2550
发布2023-07-06 14:39:54
举报
文章被收录于专栏:c++ 学习分享c++ 学习分享

CGAL 一般多边形 : rigid motions and area 标签 c++ geometry transformation area cgal

调查 this question ,我将不得不处理其边界由线段和圆弧组成的形状。看来 CGAL 应该可以在这里帮助我:根据 this section of the User’s Manual , 一个 General_polygon_set_2 与 Gps_segment_traits_2 因为它的特征类应该能够表达我需要的大部分操作,特别是交集和差异。

到目前为止,我还没有在文档中找到对这些形状应用刚性运动的方法,以及计算所得形状面积的方法。

我想我可以解决这两个问题。对于刚性运动,我可以在转换原始定义对象后重新创建形状。为了计算面积,我可以使用鞋带方法的一种变体,并进行调整以应对圆弧。手册中的示例打印了有关支持圈的详细信息,并深入挖掘了标题,我发现每个 curve因为我的多边形确实有一个 supporting_circle() 方法,所以我想它实际上是一个 Arr_circle_segment_traits_2::X_monotone_curve_2 .所以我应该能够获得足够的圆信息来计算面积。在使用故意的编译器错误消息来了解手册简单描述为 unspecified_type 的某些对象的类型之后,我才在标题中发现了这一点。 .

不过,这两个操作都需要相当多的工作,令我惊讶的是似乎没有内置的方法来完成这些操作。另一方面,CGAL 通过模板参数进行自定义的方式,我可能只是缺少一种方法来执行这些适用于圆形线段的操作,尽管它可能不适用于其他一般多边形。您知道我可以使用的任何快捷方式吗?

代码语言:javascript
复制
#include <CGAL/basic.h>
#ifndef CGAL_USE_CORE
#include <iostream>
int main ()
{
  std::cout << "Sorry, this example needs CORE ..." << std::endl;
  return (0);
}
#else
#include <CGAL/Cartesian.h>
#include <CGAL/CORE_algebraic_number_traits.h>
#include <CGAL/Arr_conic_traits_2.h>
#include <CGAL/General_polygon_2.h>
#include <CGAL/Gps_traits_2.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <list>
typedef CGAL::CORE_algebraic_number_traits              Nt_traits;
typedef Nt_traits::Rational                             Rational;
typedef Nt_traits::Algebraic                            Algebraic;
typedef CGAL::Cartesian<Rational>                       Rat_kernel;
typedef CGAL::Cartesian<Algebraic>                      Alg_kernel;
typedef CGAL::Arr_conic_traits_2<Rat_kernel, Alg_kernel,Nt_traits>
                                                        Conic_traits_2;
typedef CGAL::General_polygon_2<Conic_traits_2>         Polygon_2;
typedef CGAL::Gps_traits_2<Conic_traits_2, Polygon_2>   Traits_2;
typedef Traits_2::General_polygon_with_holes_2          Polygon_with_holes_2;
typedef Traits_2::Curve_2                               Curve_2;
typedef Traits_2::X_monotone_curve_2                    X_monotone_curve_2;
typedef Traits_2::Point_2                               Point_2;
// Insert a conic arc as a polygon edge: Subdivide the arc into x-monotone
// sub-arcs and append these sub-arcs as polygon edges.
void append_conic_arc (Polygon_2& polygon, const Curve_2& arc)
{
  Conic_traits_2                    traits;
  std::list<CGAL::Object>           objects;
  std::list<CGAL::Object>::iterator it;
  X_monotone_curve_2                xarc;
  traits.make_x_monotone_2_object() (arc, std::back_inserter(objects));
  for (it = objects.begin(); it != objects.end(); ++it)
  {
    if (CGAL::assign (xarc, *it))
      polygon.push_back (xarc);
  }
}
int main ()
{
  // Construct a parabolic arc supported by a parabola: x^2 + 2y - 4 = 0,
  // and whose endpoints lie on the line y = 0:
  Curve_2 parabola1 = Curve_2 (1, 0, 0, 0, 2, -4, CGAL::COUNTERCLOCKWISE,
                               Point_2(2, 0), Point_2(-2, 0));
  // Construct a parabolic arc supported by a parabola: x^2 - 2y - 4 = 0,
  // and whose endpoints lie on the line y = 0:
  Curve_2 parabola2 = Curve_2 (1, 0, 0, 0, -2, -4, CGAL::COUNTERCLOCKWISE,
                               Point_2(-2, 0), Point_2(2, 0));
  // Construct a polygon from these two parabolic arcs.
  Polygon_2 P;
  append_conic_arc (P, parabola1);
  append_conic_arc (P, parabola2);
  // Construct a polygon that corresponds to the ellipse: x^2 + 9y^2 - 9 = 0:
  Polygon_2 Q;
  append_conic_arc (Q, Curve_2 (-1, -9, 0, 0, 0, 9));
  // Compute the intersection of the two polygons.
  std::list<Polygon_with_holes_2> res;
  CGAL::intersection (P, Q, std::back_inserter(res));
  std::copy (res.begin(), res.end(),       // export to standard output
             std::ostream_iterator<Polygon_with_holes_2>(std::cout, "\n"));
  std::cout << std::endl;
  return (0);
}
#endif
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-07-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档