public Triangle(IVector3 v0, IVector3 v1, IVector3 v2) { vert = new Vector3[3]; vert[0] = v0; vert[1] = v1; vert[2] = v2; this.index = 0; getBoundingBox(); GetSideVectors(); normal = v01.Cross(v12); normal.Normalize(); }
/// <summary> /// test if triangle contains point /// </summary> /// <param name="pt"></param> /// <returns></returns> public bool Contains(IVector3 pt) { try { GetSideVectors(); IVector3 v0pt = pt.Minus(vert[0]); IVector3 v1pt = pt.Minus(vert[1]); IVector3 v2pt = pt.Minus(vert[2]); double testSide0 = v01.Cross(v0pt).Dot(Normal); double testSide1 = v12.Cross(v1pt).Dot(Normal); double testSide2 = v20.Cross(v2pt).Dot(Normal); return((testSide0 >= 0) && (testSide1 >= 0) && (testSide2 >= 0)); } catch (Exception) { throw; } }