From 0994eed6c5a49ee3a05560f35a6800e27b07762e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 2 Mar 2022 11:23:49 +0100 Subject: [PATCH] Fix make_icosahedron() having wrong radius --- BGL/include/CGAL/boost/graph/generators.h | 80 ++++++++++++----------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/generators.h b/BGL/include/CGAL/boost/graph/generators.h index dd9cb32b393..d49a53fd814 100644 --- a/BGL/include/CGAL/boost/graph/generators.h +++ b/BGL/include/CGAL/boost/graph/generators.h @@ -19,6 +19,10 @@ #include #include +#include +#include +#include + namespace CGAL { namespace Euler { @@ -640,8 +644,9 @@ template typename boost::graph_traits::halfedge_descriptor make_icosahedron(Graph& g, const P& center = P(0,0,0), - typename CGAL::Kernel_traits

::Kernel::FT radius = 1.0) + typename CGAL::Kernel_traits

::Kernel::FT radius = 1) { + typedef typename CGAL::Kernel_traits

::Kernel::FT FT; typedef typename boost::property_map::type Point_property_map; typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; Point_property_map vpmap = get(CGAL::vertex_point, g); @@ -652,70 +657,71 @@ make_icosahedron(Graph& g, for(int i=0; i<12; ++i) v_vertices[i] = add_vertex(g); - typename CGAL::Kernel_traits

::Kernel::FT t = radius * (1.0 + CGAL::approximate_sqrt(5.0)) / 2.0; + const FT phi = (FT(1) + CGAL::approximate_sqrt(FT(5))) / FT(2); + const FT t = radius / CGAL::approximate_sqrt(1 + square(phi)); + const FT t_phi = t * phi; - put(vpmap, v_vertices[0], P(-radius + center.x(), t + center.y(), 0.0 + center.z())); - put(vpmap, v_vertices[1], P( radius + center.x(), t + center.y(), 0.0 + center.z())); - put(vpmap, v_vertices[2], P(-radius + center.x(), -t + center.y(), 0.0 + center.z())); - put(vpmap, v_vertices[3], P( radius + center.x(), -t + center.y(), 0.0 + center.z())); + put(vpmap, v_vertices[0], P(center.x(), center.y() + t, center.z() + t_phi)); + put(vpmap, v_vertices[1], P(center.x(), center.y() + t, center.z() - t_phi)); + put(vpmap, v_vertices[2], P(center.x(), center.y() - t, center.z() + t_phi)); + put(vpmap, v_vertices[3], P(center.x(), center.y() - t, center.z() - t_phi)); - put(vpmap, v_vertices[4], P( 0.0 + center.x(), -radius + center.y(), t + center.z())); - put(vpmap, v_vertices[5], P( 0.0 + center.x(), radius + center.y(), t + center.z())); - put(vpmap, v_vertices[6], P( 0.0 + center.x(), -radius + center.y(), -t + center.z())); - put(vpmap, v_vertices[7], P( 0.0 + center.x(), radius + center.y(), -t + center.z())); + put(vpmap, v_vertices[4], P(center.x() + t, center.y() + t_phi, center.z())); + put(vpmap, v_vertices[5], P(center.x() + t, center.y() - t_phi, center.z())); + put(vpmap, v_vertices[6], P(center.x() - t, center.y() + t_phi, center.z())); + put(vpmap, v_vertices[7], P(center.x() - t, center.y() - t_phi, center.z())); - put(vpmap, v_vertices[8], P( t + center.x(), 0.0 + center.y(), -radius + center.z())); - put(vpmap, v_vertices[9], P( t + center.x(), 0.0 + center.y(), radius + center.z())); - put(vpmap, v_vertices[10], P(-t + center.x(), 0.0 + center.y(), -radius + center.z())); - put(vpmap, v_vertices[11], P(-t + center.x(), 0.0 + center.y(), radius + center.z())); + put(vpmap, v_vertices[8], P(center.x() + t_phi, center.y(), center.z() + t)); + put(vpmap, v_vertices[9], P(center.x() + t_phi, center.y(), center.z() - t)); + put(vpmap, v_vertices[10], P(center.x() - t_phi, center.y(), center.z() + t)); + put(vpmap, v_vertices[11], P(center.x() - t_phi, center.y(), center.z() - t)); - std::vector face; - face.resize(3); - face[1] = v_vertices[0]; face[0] = v_vertices[5]; face[2] = v_vertices[11]; + std::array face; + face[0] = v_vertices[0]; face[1] = v_vertices[2]; face[2] = v_vertices[8]; Euler::add_face(face, g); - face[1] = v_vertices[0]; face[0] = v_vertices[1]; face[2] = v_vertices[5]; + face[0] = v_vertices[0]; face[1] = v_vertices[8]; face[2] = v_vertices[4]; Euler::add_face(face, g); - face[1] = v_vertices[0]; face[0] = v_vertices[7]; face[2] = v_vertices[1]; + face[0] = v_vertices[0]; face[1] = v_vertices[4]; face[2] = v_vertices[6]; Euler::add_face(face, g); - face[1] = v_vertices[0]; face[0] = v_vertices[10]; face[2] = v_vertices[7]; + face[0] = v_vertices[0]; face[1] = v_vertices[6]; face[2] = v_vertices[10]; Euler::add_face(face, g); - face[1] = v_vertices[0]; face[0] = v_vertices[11]; face[2] = v_vertices[10]; + face[0] = v_vertices[0]; face[1] = v_vertices[10]; face[2] = v_vertices[2]; Euler::add_face(face, g); - face[1] = v_vertices[1]; face[0] = v_vertices[9]; face[2] = v_vertices[5]; + face[0] = v_vertices[1]; face[1] = v_vertices[9]; face[2] = v_vertices[3]; Euler::add_face(face, g); - face[1] = v_vertices[5]; face[0] = v_vertices[4]; face[2] = v_vertices[11]; + face[0] = v_vertices[1]; face[1] = v_vertices[3]; face[2] = v_vertices[11]; Euler::add_face(face, g); - face[1] = v_vertices[11]; face[0] = v_vertices[2]; face[2] = v_vertices[10]; + face[0] = v_vertices[1]; face[1] = v_vertices[11]; face[2] = v_vertices[6]; Euler::add_face(face, g); - face[1] = v_vertices[10]; face[0] = v_vertices[6]; face[2] = v_vertices[7]; + face[0] = v_vertices[1]; face[1] = v_vertices[6]; face[2] = v_vertices[4]; Euler::add_face(face, g); - face[1] = v_vertices[7]; face[0] = v_vertices[8]; face[2] = v_vertices[1]; + face[0] = v_vertices[1]; face[1] = v_vertices[4]; face[2] = v_vertices[9]; Euler::add_face(face, g); - face[1] = v_vertices[3]; face[0] = v_vertices[4]; face[2] = v_vertices[9]; + face[0] = v_vertices[5]; face[1] = v_vertices[8]; face[2] = v_vertices[2]; Euler::add_face(face, g); - face[1] = v_vertices[3]; face[0] = v_vertices[2]; face[2] = v_vertices[4]; + face[0] = v_vertices[5]; face[1] = v_vertices[2]; face[2] = v_vertices[7]; Euler::add_face(face, g); - face[1] = v_vertices[3]; face[0] = v_vertices[6]; face[2] = v_vertices[2]; + face[0] = v_vertices[5]; face[1] = v_vertices[7]; face[2] = v_vertices[3]; Euler::add_face(face, g); - face[1] = v_vertices[3]; face[0] = v_vertices[8]; face[2] = v_vertices[6]; + face[0] = v_vertices[5]; face[1] = v_vertices[3]; face[2] = v_vertices[9]; Euler::add_face(face, g); - face[1] = v_vertices[3]; face[0] = v_vertices[9]; face[2] = v_vertices[8]; + face[0] = v_vertices[5]; face[1] = v_vertices[9]; face[2] = v_vertices[8]; Euler::add_face(face, g); - face[1] = v_vertices[4]; face[0] = v_vertices[5]; face[2] = v_vertices[9]; + face[0] = v_vertices[8]; face[1] = v_vertices[9]; face[2] = v_vertices[4]; Euler::add_face(face, g); - face[1] = v_vertices[2]; face[0] = v_vertices[11]; face[2] = v_vertices[4]; + face[0] = v_vertices[3]; face[1] = v_vertices[7]; face[2] = v_vertices[11]; Euler::add_face(face, g); - face[1] = v_vertices[6]; face[0] = v_vertices[10]; face[2] = v_vertices[2]; + face[0] = v_vertices[11]; face[1] = v_vertices[7]; face[2] = v_vertices[10]; Euler::add_face(face, g); - face[1] = v_vertices[8]; face[0] = v_vertices[7]; face[2] = v_vertices[6]; + face[0] = v_vertices[10]; face[1] = v_vertices[7]; face[2] = v_vertices[2]; Euler::add_face(face, g); - face[1] = v_vertices[9]; face[0] = v_vertices[1]; face[2] = v_vertices[8]; + face[0] = v_vertices[6]; face[1] = v_vertices[11]; face[2] = v_vertices[10]; Euler::add_face(face, g); - return halfedge(v_vertices[1], v_vertices[0], g).first; + return halfedge(v_vertices[5], v_vertices[0], g).first; } /*!