20 #ifndef ANTKEEPER_GEOM_INTERSECTION_HPP
21 #define ANTKEEPER_GEOM_INTERSECTION_HPP
41 template <
class T, std::
size_t N>
45 if (cos_theta != T{0})
57 template <
class T, std::
size_t N>
73 template <
class T, std::
size_t N>
76 T t0 = -std::numeric_limits<T>::infinity();
77 T t1 = std::numeric_limits<T>::infinity();
79 for (std::size_t i = 0; i < N; ++i)
97 if (t0 > t1 || t1 < T{0})
102 return std::tuple<T, T>{t0, t1};
105 template <
class T, std::
size_t N>
122 template <
class T, std::
size_t N>
136 return std::tuple<T, T>{-
b - sqrt_h, -
b + sqrt_h};
163 const T inverse_det = T{1} / det;
167 const T u =
math::dot(tv, pv) * inverse_det;
168 if (u < T{0} || u > T{1})
176 if (v < T{0} || u + v > T{1})
182 const T t =
math::dot(edge_ac, qv) * inverse_det;
188 return std::tuple<T, T, T>{t, u, v};
205 template <
class T, std::
size_t N>
208 return a.intersects(
b);
220 template <
class T, std::
size_t N>
224 for (std::size_t i = 0; i < N; ++i)
241 template <
class T, std::
size_t N>
256 template <
class T, std::
size_t N>
259 return a.intersects(
b);
constexpr int difference(T x, T y) noexcept
Returns the number of differing bits between two values, known as Hamming distance.
constexpr std::optional< T > intersection(const ray< T, N > &ray, const hyperplane< T, N > &hyperplane) noexcept
Ray-hyperplane intersection test.
constexpr T sqr_distance(const vector< T, N > &p0, const vector< T, N > &p1) noexcept
Calculates the square distance between two points.
constexpr vector< T, N > max(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the maximum elements of two vectors.
constexpr vector< T, 3 > cross(const vector< T, 3 > &x, const vector< T, 3 > &y) noexcept
Calculates the cross product of two vectors.
vector< T, N > sqrt(const vector< T, N > &x)
Takes the square root of each element.
constexpr T dot(const quaternion< T > &a, const quaternion< T > &b) noexcept
Calculates the dot product of two quaternions.
constexpr vector< T, N > min(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the minimum elements of two vectors.
constexpr T distance(const vector_type &point) const noexcept
Calculates the signed distance from the hyperplane to a point.
vector_type normal
Hyperplane normal.
n-dimensional axis-aligned rectangle.
vector_type min
Minimum extent of the hyperrectangle.
vector_type max
Maximum extent of the hyperrectangle.
vector_type center
Hypersphere center.
T radius
Hypersphere radius.
Half of a line proceeding from an initial point.
vector_type direction
Ray direction vector.
vector_type origin
Ray origin position.