# Having some trouble with my frustum checking code

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);
}

static bool SphereIntersectsPlane(DirectX::SimpleMath::Vector3 sphereCentre, Plane p, float radius) {
}

• 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. Jun 4, 2019 at 2:26
• 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. Jun 4, 2019 at 6:05

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

• Thanks Turms I changed the IsSphereInsidePlane to return d < radius and it works. Jun 4, 2019 at 7:43
• Great. If it solved your problem, please mark it as accepted with the green tick! Jun 5, 2019 at 13:09