When I am trying to draw straight skeleton with CGAL I am getting strange results (non-symmetric skeleton on symmetric polygon).
Result with kernels:
is here.
Using kernel
is here (this is better, but it break when I shift points in definition of polygon cyclically).
I am using this code:
#include <vector>
#include <boost/shared_ptr.hpp>
// #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
// typedef CGAL::Exact_predicates_inexact_constructions_kernel K ;
// #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
// typedef CGAL::Exact_predicates_exact_constructions_kernel K ;
#include <CGAL/Cartesian.h>
typedef CGAL::Cartesian<float> K;
#include <CGAL/Polygon_2.h>
#include <CGAL/create_straight_skeleton_2.h>
typedef K::Point_2 Point_2;
typedef CGAL::Straight_skeleton_2<K> Ss;
typedef boost::shared_ptr<Ss> SsPtr;
int main() {
Point_2 pts[] = {
Point_2(0, -1385),//top
Point_2(500, 0),//right half:
Point_2(300, 0),
Point_2(400, 173),
Point_2(200, 173),
Point_2(100, 0),
Point_2(-100, 0),//left half:
Point_2(-200, 173),
Point_2(-400, 173),
Point_2(-300, 0),
Point_2(-500, 0),
} ;
std::vector<Point_2> poly(pts,pts+11);
SsPtr iss = CGAL::create_interior_straight_skeleton_2(poly.begin(), poly.end(), K());
//printing for debugging
for ( Ss::Halfedge_const_iterator i = (*iss).halfedges_begin(); i != (*iss).halfedges_end(); ++i ) {
if ( i->is_bisector()){
std::cout<<"i ";
}
else {
std::cout<<"c ";
}
CGAL::Point_2<K> pa= i->opposite()->vertex()->point();
CGAL::Point_2<K> pb= i->vertex()->point();
std::cout << pa.x() << " " << pa.y() << " " << pb.x() << " " << pb.y() << std::endl;
}
return 0;
}
Problem seems to be that degeneracies (4 lines meeting in one point) aren't computed precisely.
Am I using kernel inappropriately? How should I use it to get this result: https://i.sstatic.net/ESk9U.png
As workaround I upscale polygon by 100, then call CGAL, then downscale result again.
Notes:
Script for displaying results (for debugging): https://gist.github.com/anonymous/5497523
Fair enough. The answer is that you are using the Kernel appropriately. This is not a problem with your code, it's a bug in CGAL which I need to fix. Jiri (the OP), please contact me in private (fernando dot cacciola at gmail) so you can follow up on this.