Ocean
Quadric.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_GEOMETRY_CONE_H
9 #define META_OCEAN_GEOMETRY_CONE_H
10 
12 
15 #include "ocean/math/Vector3.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Geometry
21 {
22 
23 /**
24  * This class implements the base for all quadric object.
25  * @ingroup geometry
26  */
27 class OCEAN_GEOMETRY_EXPORT Quadric
28 {
29  public:
30 
31  /**
32  * Creates an invalid quadric.
33  */
35 
36  /**
37  * Returns whether a given point lies inside or on the surface of the cone.
38  * @param point Point to check
39  * @return True, if so
40  */
41  bool isInside(const Vector3& point) const;
42 
43  /**
44  * Returns whether a given point lies on the surface of the cone.
45  * @param point Point to check
46  * @return True, if so
47  */
48  bool isOnSurface(const Vector3& point) const;
49 
50  /**
51  * Returns the quadric value for a given point.
52  * @param point Point to check
53  * @return Quadric value
54  */
55  Scalar value(const Vector3& point) const;
56 
57  protected:
58 
59  /**
60  * Creates the combination of quadric and transformation matrix.
61  * @param quadric Quadric matrix
62  * @param transformation Transformation matrix to be combined with the quadric
63  */
64  void createCombinedQuadric(const SquareMatrix4& quadric, const HomogenousMatrix4 &transformation);
65 
66  protected:
67 
68  /// Holds the combined quadric and transformation matrix.
70 };
71 
72 /**
73  * This class implements a cone quadric.
74  * Quadric for cone Q:
75  * Cone apex at: (m_x, m_y, m_z)
76  * Cone angle: a
77  *
78  * [ 1 0 0 -m_x ]<br>
79  * [ 0 1 0 -m_y ]<br>
80  * [ 0 0 -tan^2(a) m_z tan^2 ]<br>
81  * [ -m_x -m_y m_z tan^2(a) (m_x^2 + m_y^2 - m_z^2 tan^2(a)) ]<br>
82  *
83  * Inside test: p^T * Q * p <= 0.0
84  * @ingroup geometry
85  */
86 class OCEAN_GEOMETRY_EXPORT Cone : public Quadric
87 {
88  public:
89 
90  /**
91  * Creates an invalid cone.
92  */
93  Cone();
94 
95  /**
96  * Creates a cone by a given dihedral angle and a transformation.
97  * @param angle Dihedral angle of the cone in radian, which is half of the aperture (aperture = 2 * angle)
98  * @param transformation Transformation to transform the default cone defined about the z axis
99  */
100  Cone(const Scalar angle, const HomogenousMatrix4 &transformation);
101 };
102 
103 /**
104  * This class implements a sphere quadric.
105  * Quadric for sphere Q:
106  * Sphere midpoint at: (m_x, m_y, m_z)
107  * Sphere radius: r
108  *
109  * [ 1 0 0 -m_x ]<br>
110  * [ 0 1 0 -m_y ]<br>
111  * [ 0 0 1 -m_z ]<br>
112  * [ -m_x -m_y -m_z (m_x^2 + m_y^2 - m_z^2 - r^2) ]<br>
113  *
114  * Inside test: p^T * Q * p <= 0.0
115  * @ingroup geometry
116  */
117 class OCEAN_GEOMETRY_EXPORT Sphere : public Quadric
118 {
119  public:
120 
121  /**
122  * Creates an invalid sphere.
123  */
125 
126  /**
127  * Creates a sphere by a given radius and a transformation.
128  * @param radius Radius of the sphere
129  * @param transformation Transformation to transform the default sphere defined with midpoint at (0, 0, 0)
130  */
131  Sphere(const Scalar radius, const HomogenousMatrix4 &transformation);
132 };
133 
134 }
135 
136 }
137 
138 #endif // META_OCEAN_GEOMETRY_CONE_H
This class implements a cone quadric.
Definition: Quadric.h:87
Cone(const Scalar angle, const HomogenousMatrix4 &transformation)
Creates a cone by a given dihedral angle and a transformation.
Cone()
Creates an invalid cone.
This class implements the base for all quadric object.
Definition: Quadric.h:28
Scalar value(const Vector3 &point) const
Returns the quadric value for a given point.
bool isInside(const Vector3 &point) const
Returns whether a given point lies inside or on the surface of the cone.
bool isOnSurface(const Vector3 &point) const
Returns whether a given point lies on the surface of the cone.
Quadric()
Creates an invalid quadric.
SquareMatrix4 combinedQuadric
Holds the combined quadric and transformation matrix.
Definition: Quadric.h:69
void createCombinedQuadric(const SquareMatrix4 &quadric, const HomogenousMatrix4 &transformation)
Creates the combination of quadric and transformation matrix.
This class implements a sphere quadric.
Definition: Quadric.h:118
Sphere(const Scalar radius, const HomogenousMatrix4 &transformation)
Creates a sphere by a given radius and a transformation.
Sphere()
Creates an invalid sphere.
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15