Subject: CGAL users discussion list
List archive
- From: Steve Newsome <>
- To: "" <>
- Subject: [cgal-discuss] Obtaining vertex coordinates from General_polygon_2
- Date: Fri, 2 Jan 2015 18:58:07 +0000 (UTC)
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.com; b=TtP32EjL9WCfZyIzKqQuU9Sde616KTXS0m1gbnX4bYRStxUo/p12ZQF1xe8VdU+Iy/jFFxEKMAuAPOV3/tjcckhXvwkHgt3dUlXnK/LZl1aqLEdRyT2ob5fIJI8NQkL8YkZIn3yTbjlSn2nitzu9wtEGC1HHXm6AQaGa3FYu+uJTuE2zQF5T512GLIYVGzOQmaQh+HAgUnYYgfutvpEuhSMBlVRo7VvNOz7kjPw7J6rZGdDSPaqe8LWt6bIbJ56hgXz79cQUciz5VBE/4fVjgOT0OqsskxNWJApHJ3skQczSwlOgGMbILirfTmHyBZjM3cpESPjmPB6eW8Rb+eb7dw==;
Hello All. Firstly, thank you for making something as powerful as CGAL
available.
I am a scientific programmer and need to perform some basic computational
geometry work in an analysis pipeline. The tool I'm using CGAL within is
purely for internal use only.
Disclaimer: while I do a fair bit of programming, I last really used C++ in
the late '90s. So all of the metaprogramming, traits, etc., current
idiomatic C++ stuff is new to me. I'm admittedly muddling through using
examples and reading as I can. My question may be pretty obvious/naiive to
someone well-versed in modern C++.
Question: How can I extract vertices out of the outer polygon that results
from applying approximated_offset_2 to a simple input polygon?
The use case is offsetting (Minkowski sum with a circle) a simple polygon.
The construction accuracy is not critical. I can construct the source
polygon to supply to approximated_offset_2 , but I have not been able to
figure out, once the offset polygon has been constructed, how to extract
vertices from the General_polygon_2 that comes from the outer_boundary()
method.
Thank you very much for any help.
A reduced example code is below:
#include <vector>
#include <cmath>
#include <cstdio>
// CGAL includes
#include <CGAL/Cartesian.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/approximated_offset_2.h>
#include <CGAL/offset_polygon_2.h>
#include <CGAL/Lazy_exact_nt.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
// typedefs for CGAL items
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
typedef CGAL::Point_2<Kernel> Point_2;
typedef CGAL::Gps_circle_segment_traits_2<Kernel> Gps_traits_2;
typedef Gps_traits_2::Polygon_with_holes_2 Offset_polygon_with_holes_2;
typedef CGAL::Lazy_exact_nt<CGAL::Quotient<CGAL::MP_Float> > NT;
typedef struct {double x; double y;} vertex_2;
void init_regular_ngon_2(std::vector<vertex_2>& ngon_vertices, const double
center_x, const double center_y, const double r)
{
unsigned int i, num_subdiv;
double theta;
num_subdiv = ngon_vertices.size();
for (i = 0; i < num_subdiv; i++)
{
theta = 2.0 * M_PI * (double)i / (double)num_subdiv;
ngon_vertices[i].y = center_y + (r * sin(theta));
ngon_vertices[i].x = center_x + (r * cos(theta));
}
}
void ngon_2_to_CGAL_poly(const std::vector<vertex_2>& ngon_vertices,
Polygon_2& dest_poly)
{
unsigned int i;
for (i = 0; i < ngon_vertices.size(); i++)
{
dest_poly.push_back(Point_2(ngon_vertices[i].x, ngon_vertices[i].y));
}
}
int main(void)
{
CGAL::Lazy_exact_nt<NT>::set_relative_precision_of_to_double(1E-8);
Polygon_2 test_poly;
Offset_polygon_with_holes_2 offset_poly;
std::vector<vertex_2> ngon(8);
init_regular_ngon_2(ngon, 0.0, 0.0, 5.0);
ngon_2_to_CGAL_poly(ngon, test_poly);
offset_poly = approximated_offset_2(test_poly, 0.85, 1E-5);
printf("The offset polygon has %d verts and %d holes\n",
offset_poly.outer_boundary().size(), offset_poly.number_of_holes());
// How to obtain vertex coordinates comprising offset polygon boundary??
Goal is to to store these in a vector of vertex_2 for later manipulation.
return 0;
}
- [cgal-discuss] Obtaining vertex coordinates from General_polygon_2, Steve Newsome, 01/02/2015
Archive powered by MHonArc 2.6.18.