//TODO: I can use CheckNotTriangleException but i don't know is it neccessary private void CheckNotTriangleException(FixedVertex2D a, FixedVertex2D b, FixedVertex2D c) { FixedVector2 ab = a.GetDirectionTo(b); FixedVector2 ac = a.GetDirectionTo(c); if ((ab.x * ac.y - ab.y * ac.x).IsZero()) { throw new System.ArgumentException("This set of vertices can't form the triangle"); } }
public bool IsInTriangle(FixedVector2 p) { RecalculateDirectionalVectors(); FixedVector2 ap = a.GetDirectionTo(p); FixedVector2 bp = b.GetDirectionTo(p); FixedVector2 cp = b.GetDirectionTo(p); Fixed bpXab = FixedVector2.PseudoscalarMultiplication(bp, ab); Fixed cpXbc = FixedVector2.PseudoscalarMultiplication(cp, bc); Fixed apXca = FixedVector2.PseudoscalarMultiplication(ap, ca); //this return means that sign of the pseudoscalar multiplications is equal return (apXca.IsZero() || bpXab.IsZero() || cpXbc.IsZero() || (apXca.IsNegative() == bpXab.IsNegative() && apXca.IsNegative() == cpXbc.IsNegative())); }