Commit 8881f131 authored by Philip Trettner's avatar Philip Trettner
Browse files

Merge branch 'jn/develop' into 'develop'

Add sphere_boundary <-> segment3 intersection test

See merge request !110
parents 1cb70290 e13c60d5
......@@ -1263,6 +1263,36 @@ template <int D, class ScalarT>
return intersection(b, a);
}
// sphere_boundary<3, ScalarT> -- segment3
template <class ScalarT>
[[nodiscard]] constexpr hits<2, tg::pos<3, ScalarT>> intersection(sphere_boundary<3, ScalarT> const& sphere_boundary, segment<3, ScalarT> const& segment)
{
auto const line = line3::from_points(segment.pos0, segment.pos1);
auto const params = intersection_parameter(line, sphere_boundary);
if (!params.any())
return {};
auto const dist = distance(segment.pos0, segment.pos1);
auto n_hits = 0;
tg::pos<3, ScalarT> ps[2];
for (auto i = 0; i < params.size(); ++i)
{
auto const t = params[i];
if (ScalarT(0) <= t && t <= dist)
{
ps[n_hits++] = line[t];
}
}
return hits<2, tg::pos<3, ScalarT>>(ps, n_hits);
}
template <class ScalarT>
[[nodiscard]] constexpr hits<2, tg::pos<3, ScalarT>> intersection(segment<3, ScalarT> const& segment, sphere_boundary<3, ScalarT> const& sphere_boundary)
{
return intersection(sphere_boundary, segment);
}
// ====================================== Checks if Object Intersects aabb ======================================
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment