Commit 2582a89a authored by Julian Schakib's avatar Julian Schakib
Browse files

intersection tests plane-cylinder

parent 76a53023
Pipeline #13555 failed with stage
in 6 minutes and 19 seconds
typed-geometry @ b86bc12e
Subproject commit b2ed42c02755624e1e53062efaa2905c14a489da
Subproject commit b86bc12eafc2c06b37b015b3e92871dfceb9f7b4
......@@ -13,7 +13,7 @@ TG_FUZZ_TEST(Plane, Intersect)
auto const p = l[uniform(rng, -10.0f, 10.0f)];
// divide by 10 as eps
// divide by 10 for further tolerance
CHECK(distance(p, p0) / 10 == approx(0));
CHECK(distance(p, p1) / 10 == approx(0));
}
......@@ -53,14 +53,72 @@ TG_FUZZ_TEST(Plane, Intersect)
{
auto const box = tg::aabb3(tg::pos3(-10.0f), tg::pos3(10.0f));
// inf_boundary
auto c = tg::inf_cylinder_boundary<3, tg::f32>(tg::line3(tg::uniform(rng, box), tg::uniform<tg::dir3>(rng)), tg::uniform(rng, 0.1f, 10.0f));
{
// plane and cylinder have *parallel* normals
// confirm center position and circle shape of intersection
auto const p = tg::plane3(tg::dir3::pos_y, tg::pos3::zero);
auto const r = tg::uniform(rng, 0.1f, 10.0f);
auto const d = tg::uniform<tg::dir3>(rng);
auto ellipse = tg::intersection(p, c);
auto const center = uniform(rng, box);
// TODO what to check?
(void)ellipse;
auto const c = tg::inf_cylinder_boundary<3, tg::f32>(tg::line3(center, d), r);
{
auto const p = tg::plane3(d, center);
// the cut should be a circle with radius r with center zero
auto const ellipse = tg::intersection(p, c);
// check center, directions of normal and length
CHECK(distance(ellipse.center, center) == approx(0));
CHECK(dot(ellipse.axisA, p.normal) == approx(0)); // orthogonal
CHECK(length(ellipse.axisA) - length(ellipse.axisB) == approx(0));
}
// as above, flipped d
{
auto const p = tg::plane3(-d, center);
// the cut should be a circle with radius r with center zero
auto const ellipse = tg::intersection(p, c);
// check center, directions of normal and length
CHECK(distance(ellipse.center, center) == approx(0));
CHECK(dot(ellipse.axisA, p.normal) == approx(0)); // orthogonal
CHECK(length(ellipse.axisA) - length(ellipse.axisB) == approx(0));
}
}
{
// cylinder simply up, plane slanted
// confirm there is a non-deformed ellipse
auto const r = tg::uniform(rng, 0.1f, 10.0f);
auto const center = tg::pos3::zero; // uniform(rng, box);
// TODO identical centers result in delta = 0? issue? -> no.
auto const c = tg::inf_cylinder_boundary<3, tg::f32>(tg::line3(center /* + tg::vec3(1, 0, 0)*/, tg::dir3::pos_y), r);
auto const p = tg::plane3(normalize(tg::vec3(1, 1, 0)), center);
// the cut should be a circle with radius r with center zero
auto const ellipse = tg::intersection(p, c);
// existing axes
CHECK(length(ellipse.axisA) > 0);
CHECK(length(ellipse.axisB) > 0);
}
{
// random cylinder and planes
// check if ellipse properties are meaningful
auto const c = tg::inf_cylinder_boundary<3, tg::f32>(tg::line3(tg::uniform(rng, box), tg::uniform<tg::dir3>(rng)), tg::uniform(rng, 0.5f, 10.0f));
auto const p = tg::plane3(tg::uniform<tg::dir3>(rng), tg::uniform(rng, box));
auto const ellipse = tg::intersection(p, c);
// existing axes
CHECK(length(ellipse.axisA) > 0);
CHECK(length(ellipse.axisB) > 0);
}
}
}
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