I want to check if a point Q is inside a circle (P1, P2, P3) but im having problems when the point is part of the circle because the last condition return it as flase when it should be true, this is because of float precission.
public static bool QTest(Vector3 P1 ,Vector3 P2, Vector3 P3, Vector3 Q)//Test if the point Q is inside the circumcircle of P1, P2, P3
{
Vector3 midPoint1 = MidPoint(P1, P2);
float pSlope = -1 / ((P2.z - P1.z) / (P2.x - P1.x));
Vector3 midPoint2 = MidPoint(P2, P3);
float pSlope2 = -1 / ((P3.z - P2.z) / (P3.x - P2.x));
//formula y - midPoint.z = perpendicularSlope * (x - midPoint.x)
float x = (- pSlope2 * midPoint2.x + midPoint2.z + pSlope * midPoint1.x - midPoint1.z) / (pSlope - pSlope2);
float y = pSlope * (x - midPoint1.x) + midPoint1.z;
Vector3 center = new(x, 0, y);
float epsilon = 1e-3f;
float radius = (center - P1).sqrMagnitude;
float distance2 = (center - Q).sqrMagnitude;
if (distance2 < radius - epsilon) return false;
return true;
}