8 #ifndef META_OCEAN_MATH_CONE_3_H
9 #define META_OCEAN_MATH_CONE_3_H
139 template <
typename T>
144 minSignedDistanceAlongAxis_(minSignedDistanceAlongAxis),
145 maxSignedDistanceAlongAxis_(maxSignedDistanceAlongAxis)
152 template <
typename T>
158 template <
typename T>
164 template <
typename T>
167 ocean_assert(cosSquaredHalfApexAngle_ >=
Scalar(0.0));
171 template <
typename T>
174 return maxSignedDistanceAlongAxis_;
177 template <
typename T>
180 return minSignedDistanceAlongAxis_;
183 template <
typename T>
186 ocean_assert(isValid() && ray.
isValid());
200 const T& m = cosSquaredHalfApexAngle_;
202 const T d_dot_q = d * q;
203 const T d_dot_d = d.
sqr();
204 const T V_dot_q = V * q;
205 const T V_dot_d = V * d;
206 const T V_dot_V = V.
sqr();
208 T a = d_dot_q * d_dot_q - m * d_dot_d;
209 T b = T(2.0) * (V_dot_q * d_dot_q - m * V_dot_d);
210 T c = V_dot_q * V_dot_q - m * V_dot_V;
221 T minDistance = T(-1.0);
222 T maxDistance = T(-1.0);
229 minDistance = -c / b;
230 maxDistance = minDistance;
235 if (minDistance > maxDistance)
237 std::swap(minDistance, maxDistance);
243 if (minDistance < T(0.0))
248 point = ray.
point(minDistance);
250 const T minIntersectionDistanceAlongAxis = (point - apex_) * axis_;
252 bool intersectionIsValid = minIntersectionDistanceAlongAxis >= minSignedDistanceAlongAxis_ && minIntersectionDistanceAlongAxis <= maxSignedDistanceAlongAxis_;
273 if (maxDistance > minDistance)
276 const T maxIntersectionDistanceAlongAxis = (maxPoint - apex_) * axis_;
281 intersectionIsValid = !intersectionIsValid && maxIntersectionDistanceAlongAxis >= minSignedDistanceAlongAxis_ && maxIntersectionDistanceAlongAxis <= maxSignedDistanceAlongAxis_;
285 return intersectionIsValid;
288 template <
typename T>
291 return cosSquaredHalfApexAngle_ > T(0.0) && maxSignedDistanceAlongAxis_ > minSignedDistanceAlongAxis_ &&
NumericT<T>::isEqual(axis_.
sqr(), T(1.0));
This class implements a (possibly truncated) 3D cone.
Definition: Cone3.h:59
T cosSquaredHalfApexAngle_
Cosine-squared of half of the cone's apex angle.
Definition: Cone3.h:130
bool isValid() const
Returns whether this cone is valid.
Definition: Cone3.h:289
T minSignedDistanceAlongAxis_
Minimum signed truncation distance along the cone's axis.
Definition: Cone3.h:133
T maxSignedDistanceAlongAxis_
Maximum signed truncation distance along the cone's axis.
Definition: Cone3.h:136
ConeT3()=default
Creates an invalid cone.
T apexAngle() const
Returns the angle made between diametrically opposite points on the cone and the apex.
Definition: Cone3.h:165
VectorT3< T > apex_
Cone tip.
Definition: Cone3.h:124
const VectorT3< T > & axis() const
Returns the unit-length axis of the cone.
Definition: Cone3.h:159
VectorT3< T > axis_
Cone axis, a unit vector.
Definition: Cone3.h:127
const VectorT3< T > & apex() const
Returns the tip of the cone.
Definition: Cone3.h:153
const T & maxSignedDistanceAlongAxis() const
Returns the maximum signed truncation distance along the cone's axis.
Definition: Cone3.h:172
const T & minSignedDistanceAlongAxis() const
Returns the minimum signed truncation distance along the cone's axis.
Definition: Cone3.h:178
bool nearestIntersection(const LineT3< T > &ray, VectorT3< T > &point) const
Returns the closest point of intersection of a ray with the outer surface of the cone,...
Definition: Cone3.h:184
This class provides several functions to solve equations with different degree using floating point v...
Definition: Equation.h:53
This class implements an infinite line in 3D space.
Definition: Line3.h:70
bool isValid() const
Returns whether this line has valid parameters.
Definition: Line3.h:303
const VectorT3< T > & direction() const
Returns the direction of the line.
Definition: Line3.h:284
const VectorT3< T > & point() const
Returns a point on the line.
Definition: Line3.h:271
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static constexpr T sign(const T &value)
Returns the sign of a given value by either returning -1, 0, or +1.
Definition: Numeric.h:3256
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition: Numeric.h:2386
static T acos(const T value)
Returns the arccosine of a given value.
Definition: Numeric.h:2907
This class implements a vector with three elements.
Definition: Vector3.h:97
T sqr() const
Returns the square of the vector length.
Definition: Vector3.h:670
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition: base/Utilities.h:1029
ConeT3< Scalar > Cone3
Definition of the Cone3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition: Cone3.h:23
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Cone3 > Cones3
Definition of a vector holding Cone3 objects.
Definition: Cone3.h:51
ConeT3< double > ConeD3
Definition of a 3D cone with double values.
Definition: Cone3.h:37
ConeT3< float > ConeF3
Definition of a 3D cone with float values.
Definition: Cone3.h:44
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15