0
\$\begingroup\$

I'm trying to check if a bounding sphere is either within or intersecting my frustum. It mostly works but there are cases where it should and it doesn't. The frustum is made up of 6 planes which have a position, direction and normal vector. Sphere has a center and radius value. The frustum is created from translating the mouse coordinates into 3d. If anyone can point me in the right direction it would be greatly appreciated. I'm not great at Maths either.

static float DistanceFromPointToPlane(Plane p, DirectX::SimpleMath::Vector3 point) {
    float distance = p.normal.Dot(point - p.position);

    return distance;
}

static bool IsSphereInsidePlane(DirectX::SimpleMath::Vector3 sphereCentre, Plane p, float radius) {
    float d = DistanceFromPointToPlane(p, sphereCentre);
    return -d > radius;
}

static bool SphereIntersectsPlane(DirectX::SimpleMath::Vector3 sphereCentre, Plane p, float radius) {
        return fabs(DistanceFromPointToPlane(p, sphereCentre)) <= radius;
    }
\$\endgroup\$
  • 1
    \$\begingroup\$ There are two functions here, that return whether the sphere intersects the plane. Which one do you use? The second one seems to be correct, not sure if the same thing can be said of the first one though. \$\endgroup\$ – Bálint Jun 4 '19 at 2:26
  • \$\begingroup\$ Assuming the "inside" of a plane is the opposite side of the plane.normal, the function IsSphereInsidePlane correctly determines if the sphere is completely inside the plane. The second function correctly determines if the sphere is intersecting. You should either: use both functions to determine if the sphere is inside OR intersect, or better you should change the return value of IsSphereInsidePlane to return d < radius and use only this function, forgetting about the other one. \$\endgroup\$ – Turms Jun 4 '19 at 6:05
2
\$\begingroup\$

Assuming the "inside" of a plane is the opposite side of the plane.normal, the function IsSphereInsidePlane correctly determines if the sphere is completely inside the plane. The second function correctly determines if the sphere is intersecting.

You should either: use both functions to determine if the sphere is inside OR intersect, or better you should change the return value of IsSphereInsidePlane to return d < radius and use only this function, forgetting about the other one

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks Turms I changed the IsSphereInsidePlane to return d < radius and it works. \$\endgroup\$ – Hayden Morris Jun 4 '19 at 7:43
  • \$\begingroup\$ Great. If it solved your problem, please mark it as accepted with the green tick! \$\endgroup\$ – Turms Jun 5 '19 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.