Skip to content

Bug : CanonicalBox3-Cylinder3 intersection has bugs in my test case! #111

@ottoGithub

Description

@ottoGithub

Version Is The Newest.
File Version: 8.0.2025.05.10

TestCase:

void IntersectBoxCylinderWindow3::myTestIntersection1()
{
    Cylinder3<double> cylinder;
    cylinder.axis.origin = { 1434.5667763484134, 389.35568672554501, 92.150001483748767 };
    cylinder.axis.direction = { 0.0f, 0.0f, 1.0f };
    cylinder.radius = 150.0f;
    cylinder.height = 10.0f;

    OrientedBox3<double> box;
    box.center = { 503.48061758921818, 510.45977283453658, 70.752710265075905 };
    box.axis[0] = { 1.0f, 0.0f, 0.0f };
    box.axis[1] = { 0.0f, 1.0f, 0.0f };
    box.axis[2] = { 0.0f, 0.0f, 1.0f };
    box.extent = { 10.7810440, 10.7810440, 25.5310440 };

    // roll, pitch, yaw
    Quaternion<double> incr = Rotation<3, double>(EulerAngles<double>(0, 1, 2, 0.20377350194043725 * GTE_C_DEG_TO_RAD, -4.3779816887311274 * GTE_C_DEG_TO_RAD, 78.185201704856738 * GTE_C_DEG_TO_RAD));
    for (int32_t i = 0; i < 3; ++i)
    {
        box.axis[i] = HProject(
            gte::Rotate(incr, HLift(box.axis[i], 0.0)));
    }


    TIQuery<double, OrientedBox3<double>, Cylinder3<double>> bcQuery;
    bool result = bcQuery(box, cylinder).intersect;
    printf("myTestIntersection: %d\n", result);  // result is true!
}

=====================
The intersect result is TRUE! It's obviously not right.

The distance cylinder2box is: 939.1728
the bounding sphere of cylinder is less than 160
the bounding sphere of box is less than 45
cylinder is to far away from box that they can not be intersect.

But the result is true.

========================
Debuging :

result.intersect = DoQueryNoZeros(C, D, r, hDiv2, E); // return true!
function: DoQueryNoZeros
    // (U2, -D)
    lower = (s5p >= zero ? -E[1] : -E[1] - s5p / D[2]);
    upper = (s6p <= zero ? +E[1] : +E[1] - s6p / D[2]);
    if (lower <= upper)
    {
        if (s5p >= zero)
        {
            P0 = { +E[0] - s5p / D[0], -E[1], +E[2] };
        }
        else
        {
            P0 = { +E[0], -E[1] - s5p / D[1], +E[2] };
        }

        if (s6p <= zero)
        {
            P1 = { -E[0] - s6p / D[0], +E[1], +E[2] };
        }
        else
        {
            P1 = { -E[0], E[1] - s6p / D[1], +E[2] };
        }
// HERE return true:

        sqrDistance = ComputeSqrDistance(P0, P1, C, W0, W1);
        if (sqrDistance <= sqrRadius)
        {
            return true;
        }
    }

sqrDistance: 22083.197885594218
sqrRadius: 22500

How to fix it?
mybe construct line segments using 'projection' is not correct?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions