MEPP2 Project
ClippingAndIntersection.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 
14 
15 namespace FEVV {
16 namespace Operators {
17 
18 namespace Geometry {
19 
37 template< typename GeometryTraits >
38 static bool
40  const typename GeometryTraits::Point &center,
41  double r,
42  const typename GeometryTraits::Point &p,
43  typename GeometryTraits::Vector &v,
44  const GeometryTraits &gt)
45 {
46  typedef typename GeometryTraits::Vector Vector;
47  if(r < 0)
48  r = -r; // the radius cannot be negative
49 
50  Vector w = gt.sub_p(p, center); // direction towards P from the sphere center
51  double a = gt.dot_product(v, v);
52 
54  return false;
55 
56  double b = 2.0 * gt.dot_product(v, w);
57  double c = gt.dot_product(w, w) - r * r;
58  double delta = b * b - 4. * a * c;
59  if(delta < 0.)
60  {
61  // Should not happen when p is inside the sphere, but happens sometimes
62  // (numerical precision)
63  return true;
64  }
65 
66  double t1 = (-b + ::sqrt(delta)) /
67  (2.0 * a) /*, t2 = (-b - ::sqrt(delta)) / (2.0 * a)*/;
68 
69  if(t1 >= 1.)
70  {
71  // Inside the sphere
72  return false;
73  }
74 
75  // if (t1 < 0.) {
76  // Should not happen, but happens sometimes (numerical precision or P not
77  // inside the sphere)
78  // return true;
79  //}
80 
81  v = gt.scalar_mult(v, t1);
82 
83  return true;
84 }
85 } // namespace Geometry
86 
87 } // namespace Operators
88 } // namespace FEVV
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::Operators::Geometry::sphere_clip_vector
static bool sphere_clip_vector(const typename GeometryTraits::Point &center, double r, const typename GeometryTraits::Point &p, typename GeometryTraits::Vector &v, const GeometryTraits &gt)
Compute the intersection of a sphere (center + radius) with a ray/line (starting point + direction ve...
Definition: ClippingAndIntersection.hpp:39
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
FEVV::Filters::fabs
double fabs(const v_Curv< HalfedgeGraph > &input)
Definition: curvature.hpp:54
MatrixOperations.hpp
epsilon
const float epsilon
Definition: core.h:51