MEPP2 Project
triangles.hpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <boost/graph/graph_traits.hpp>
14 #include <boost/graph/properties.hpp>
16 
18 // For are_collinear() and MACH_EPS_DOUBLE :
20 
21 namespace FEVV {
22 namespace Operators {
23 namespace Geometry {
35 template< typename GeometryTraits >
36 inline typename GeometryTraits::Point
38  const typename GeometryTraits::Point &b,
39  const typename GeometryTraits::Point &c,
40  const GeometryTraits &/*gt*/)
41 {
42  typedef typename GeometryTraits::Point Point;
43 
44  return Point((a[0] + b[0] + c[0]) / 3,
45  (a[1] + b[1] + c[1]) / 3,
46  (a[2] + b[2] + c[2]) / 3);
47 }
58 template< typename GeometryTraits >
59 inline double
61  const typename GeometryTraits::Point &b,
62  const typename GeometryTraits::Point &c,
63  const GeometryTraits &gt)
64 {
65  typedef typename GeometryTraits::Vector Vector;
66 
67  Vector ab(b - a), bc(c - b), ca(a - c);
68 
69  return (gt.length(ab) + gt.length(bc) + gt.length(ca));
70 }
81 template< typename GeometryTraits >
82 inline typename GeometryTraits::Vector
84  const typename GeometryTraits::Point &b,
85  const typename GeometryTraits::Point &c,
86  const GeometryTraits &gt)
87 {
88  typedef typename GeometryTraits::Vector Vector;
89 
90  Vector cb(b[0] - c[0], b[1] - c[1], b[2] - c[2]),
91  ca(a[0] - c[0], a[1] - c[1], a[2] - c[2]);
92  return gt.cross_product(ca, cb);
93 }
104 template< typename GeometryTraits >
105 inline double
107  const typename GeometryTraits::Point &b,
108  const typename GeometryTraits::Point &c,
109  const GeometryTraits &gt)
110 {
111  typedef typename GeometryTraits::Vector Vector;
112 
113  Vector n = triangle_normal_unnormalized< GeometryTraits >(a, b, c, gt);
114  return gt.length(n) * 0.5;
115 }
135 template< typename FaceGraph,
136  typename GeometryTraits = FEVV::Geometry_traits< FaceGraph > >
137 inline double
139  const typename GeometryTraits::Point &a,
140  const typename GeometryTraits::Point
141  &b, // the central point for which we give the gradient
142  const typename GeometryTraits::Point &c,
143  const double prohib_energy,
144  const GeometryTraits &gt)
145 {
146  typedef typename GeometryTraits::Vector Vector;
147 
148  double d[3], circumradius, potential = prohib_energy, den;
149 
150  Vector ab(b[0] - a[0], b[1] - a[1], b[2] - a[2]),
151  cb(b[0] - c[0], b[1] - c[1], b[2] - c[2]),
152  ca(a[0] - c[0], a[1] - c[1], a[2] - c[2]);
153 
154  // Length of the triangle sides
155  d[0] = gt.length(ab);
156  d[1] = gt.length(ca);
157  d[2] = gt.length(cb);
158 
159  den = std::min< double >(d[2], std::min< double >(d[0], d[1]));
160  if((den > 1e-8) &&
161  !FEVV::Math::Vector::are_collinear< GeometryTraits >(ab, ca))
162  {
163  circumradius = d[0] * d[1] * d[2] /
164  (4.0 * triangle_area< GeometryTraits >(a, b, c, gt));
165  potential = circumradius / den;
166  }
167 
168  if(potential > prohib_energy)
169  potential =
170  prohib_energy; // to truncate the shape error to a managable max value
171  // std::cout << potential << std::endl;
172  return potential;
173 }
174 
175 } // namespace Geometry
176 } // namespace Operators
177 } // namespace FEVV
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::Operators::Geometry::triangle_barycenter
GeometryTraits::Point triangle_barycenter(const typename GeometryTraits::Point &a, const typename GeometryTraits::Point &b, const typename GeometryTraits::Point &c, const GeometryTraits &)
Compute the barycenter/mean position of a triangle (given by 3 points).
Definition: triangles.hpp:37
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Operators::Geometry::triangle_area
double triangle_area(const typename GeometryTraits::Point &a, const typename GeometryTraits::Point &b, const typename GeometryTraits::Point &c, const GeometryTraits &gt)
Compute the area of a triangle (given by 3 points).
Definition: triangles.hpp:106
AngleOperations.hpp
Geometry_traits.h
FEVV::Operators::Geometry::triangle_shape_potential
double triangle_shape_potential(const typename GeometryTraits::Point &a, const typename GeometryTraits::Point &b, const typename GeometryTraits::Point &c, const double prohib_energy, const GeometryTraits &gt)
Compute the shape potential of a triangle (given by 3 points). Triangle "equilateralness" measure.
Definition: triangles.hpp:138
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
FEVV::Operators::Geometry::triangle_perimeter
double triangle_perimeter(const typename GeometryTraits::Point &a, const typename GeometryTraits::Point &b, const typename GeometryTraits::Point &c, const GeometryTraits &gt)
Compute the perimeter of a triangle (given by 3 points).
Definition: triangles.hpp:60
FEVV::Operators::Geometry::triangle_normal_unnormalized
GeometryTraits::Vector triangle_normal_unnormalized(const typename GeometryTraits::Point &a, const typename GeometryTraits::Point &b, const typename GeometryTraits::Point &c, const GeometryTraits &gt)
Compute the unnormalized normal of a triangle (given by 3 points).
Definition: triangles.hpp:83
MatrixOperations.hpp