Visual Computing Library
Loading...
Searching...
No Matches
icosahedron.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_ALGORITHMS_MESH_CREATE_ICOSAHEDRON_H
24#define VCL_ALGORITHMS_MESH_CREATE_ICOSAHEDRON_H
25
26#include <vclib/mesh/requirements.h>
27
28namespace vcl {
29
41template<FaceMeshConcept MeshType>
43{
44 using VertexType = MeshType::VertexType;
45 using CoordType = VertexType::CoordType;
46
47 MeshType mesh;
48
49 const double t = (1.0 + std::sqrt(5.0)) / 2.0;
50
51 // Vertices
52 mesh.addVertex(CoordType(-1.0, t, 0.0));
53 mesh.addVertex(CoordType(1.0, t, 0.0));
54 mesh.addVertex(CoordType(-1.0, -t, 0.0));
55 mesh.addVertex(CoordType(1.0, -t, 0.0));
56 mesh.addVertex(CoordType(0.0, -1.0, t));
57 mesh.addVertex(CoordType(0.0, 1.0, t));
58 mesh.addVertex(CoordType(0.0, -1.0, -t));
59 mesh.addVertex(CoordType(0.0, 1.0, -t));
60 mesh.addVertex(CoordType(t, 0.0, -1.0));
61 mesh.addVertex(CoordType(t, 0.0, 1.0));
62 mesh.addVertex(CoordType(-t, 0.0, -1.0));
63 mesh.addVertex(CoordType(-t, 0.0, 1.0));
64
66 for (VertexType& v : mesh.vertices())
67 v.coord().normalize();
68 }
69
70 // Faces
71 mesh.addFace(0, 11, 5);
72 mesh.addFace(0, 5, 1);
73 mesh.addFace(0, 1, 7);
74 mesh.addFace(0, 7, 10);
75 mesh.addFace(0, 10, 11);
76 mesh.addFace(1, 5, 9);
77 mesh.addFace(5, 11, 4);
78 mesh.addFace(11, 10, 2);
79 mesh.addFace(10, 7, 6);
80 mesh.addFace(7, 1, 8);
81 mesh.addFace(3, 9, 4);
82 mesh.addFace(3, 4, 2);
83 mesh.addFace(3, 2, 6);
84 mesh.addFace(3, 6, 8);
85 mesh.addFace(3, 8, 9);
86 mesh.addFace(4, 9, 5);
87 mesh.addFace(2, 4, 11);
88 mesh.addFace(6, 2, 10);
89 mesh.addFace(8, 6, 7);
90 mesh.addFace(9, 8, 1);
91
92 return mesh;
93}
94
95} // namespace vcl
96
97#endif // VCL_ALGORITHMS_MESH_CREATE_ICOSAHEDRON_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
MeshType createIcosahedron(bool normalizeVertices=false)
Creates and returns an icosahedron mesh.
Definition icosahedron.h:42