Commit 05a25760 authored by Aaron Grabowy's avatar Aaron Grabowy
Browse files

Added ellipse2in3 intersection

parent a59574fb
......@@ -8,6 +8,7 @@
#include <typed-geometry/types/objects/box.hh>
#include <typed-geometry/types/objects/capsule.hh>
#include <typed-geometry/types/objects/cylinder.hh>
#include <typed-geometry/types/objects/ellipse.hh>
#include <typed-geometry/types/objects/halfspace.hh>
#include <typed-geometry/types/objects/hemisphere.hh>
#include <typed-geometry/types/objects/inf_cone.hh>
......@@ -732,13 +733,16 @@ template <class ScalarT>
auto const b = ScalarT(2) * (dv * cov - dot(l.dir, co) * cos2);
auto const c = cov * cov - dot(co, co) * cos2;
auto const inter = detail::solve_quadratic(a, b, c);
if (!inter.any())
return inter;
// exclude intersections with mirrored cone
ScalarT hits[2];
auto numHits = 0;
if (dot(l[inter[0]] - ic.apex, ic.opening_dir) >= ScalarT(0))
auto const coneDir = ic.opening_angle > 180_deg ? -ic.opening_dir : ic.opening_dir;
if (dot(l[inter[0]] - ic.apex, coneDir) >= ScalarT(0))
hits[numHits++] = inter[0];
if (dot(l[inter[1]] - ic.apex, ic.opening_dir) >= ScalarT(0))
if (dot(l[inter[1]] - ic.apex, coneDir) >= ScalarT(0))
hits[numHits++] = inter[1];
return {hits, numHits};
......@@ -804,6 +808,26 @@ template <class ScalarT>
return (ScalarT(1) / det) * dot(e2, qvec);
}
// line - ellipse
template <class ScalarT>
[[nodiscard]] constexpr hits<1, ScalarT> intersection_parameter(line<3, ScalarT> const& l, ellipse<2, ScalarT, 3> const& e)
{
const auto t = intersection_parameter(l, plane<3, ScalarT>(normal_of(e), e.center));
if (!t.any()) // line parallel to ellipse plane
return {};
// simplified contains(e, p) without plane check and eps == 0
auto pc = l[t.first()] - e.center;
auto x = dot(pc, e.semi_axes[0]);
auto y = dot(pc, e.semi_axes[1]);
auto a = length_sqr(e.semi_axes[0]);
auto b = length_sqr(e.semi_axes[1]);
if (pow2(x / a) + pow2(y / b) <= ScalarT(1))
return t;
return {};
}
// line - quadric_boundary (as an isosurface, not error quadric)
template <class ScalarT>
[[nodiscard]] constexpr hits<2, ScalarT> intersection_parameter(line<3, ScalarT> const& l, quadric<3, ScalarT> const& q)
......
#pragma once
#include <typed-geometry/types/objects/box.hh>
#include <typed-geometry/types/objects/ellipse.hh>
#include <typed-geometry/types/objects/halfspace.hh>
#include <typed-geometry/types/objects/line.hh>
#include <typed-geometry/types/objects/plane.hh>
......@@ -78,6 +79,12 @@ template <class ScalarT, class TraitsT>
return normalize(cross(b.half_extents[0], b.half_extents[1]));
}
template <class ScalarT, class TraitsT>
[[nodiscard]] constexpr dir<3, fractional_result<ScalarT>> normal_of(ellipse<2, ScalarT, 3, TraitsT> const& e)
{
return normalize(cross(e.semi_axes[0], e.semi_axes[1]));
}
template <class ScalarT>
[[nodiscard]] constexpr dir<3, ScalarT> any_normal(vec<3, ScalarT> const& v)
{
......
Supports Markdown
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