Commit 52b969c4 authored by Julian Schakib's avatar Julian Schakib
Browse files

triangle plane intersection tests

parent 7b572186
Pipeline #13773 passed with stage
in 6 minutes and 17 seconds
typed-geometry @ f98a78e6
Subproject commit f0136489a98723376f10be4ab1ff8e9bae146b6a
Subproject commit f98a78e690b49be701eb4dd6f6415e8c697130fd
......@@ -197,4 +197,67 @@ TG_FUZZ_TEST(Plane, Intersect)
CHECK(intersects(c, p));
}
}
// plane3 - triangle3
{
auto const box = tg::aabb3(tg::pos3(-10.0f), tg::pos3(10.0f));
auto const center = uniform(rng, box);
auto const n = tg::uniform<tg::dir3>(rng);
auto plane = tg::plane3(n, center);
auto const t = any_normal(n);
auto const bi = normalize(cross(n, t));
// coplanar triangle
auto triangle = tg::triangle3(center, center + t, center + bi);
CHECK(intersects(triangle, plane));
// one point of triangle in plane
tg::array<tg::pos3, 3> c = {center, center + n, center + n + t};
// check all possible orders
for (auto i = 0; i < 3; i++)
{
triangle = tg::triangle(c[(i + 0) % 3], c[(i + 1) % 3], c[(i + 2) % 3]);
CHECK(intersects(plane, triangle));
triangle = tg::triangle(c[(i + 1) % 3], c[(i + 0) % 3], c[(i + 2) % 3]);
CHECK(intersects(plane, triangle));
}
// all above triangle in plane
c = {center + n + bi, center + n, center + n + t};
// check all possible orders
for (auto i = 0; i < 3; i++)
{
triangle = tg::triangle(c[(i + 0) % 3], c[(i + 1) % 3], c[(i + 2) % 3]);
CHECK(!intersects(plane, triangle));
triangle = tg::triangle(c[(i + 1) % 3], c[(i + 0) % 3], c[(i + 2) % 3]);
CHECK(!intersects(plane, triangle));
}
// all below triangle in plane
c = {center - n + bi, center - n, center - n + t};
// check all possible orders
for (auto i = 0; i < 3; i++)
{
triangle = tg::triangle(c[(i + 0) % 3], c[(i + 1) % 3], c[(i + 2) % 3]);
CHECK(!intersects(plane, triangle));
triangle = tg::triangle(c[(i + 1) % 3], c[(i + 0) % 3], c[(i + 2) % 3]);
CHECK(!intersects(plane, triangle));
}
// 2 on 1 side
c = {center - n + bi, center + n, center - n + t};
// check all possible orders
for (auto i = 0; i < 3; i++)
{
triangle = tg::triangle(c[(i + 0) % 3], c[(i + 1) % 3], c[(i + 2) % 3]);
CHECK(intersects(plane, triangle));
triangle = tg::triangle(c[(i + 1) % 3], c[(i + 0) % 3], c[(i + 2) % 3]);
CHECK(intersects(plane, triangle));
}
}
}
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