private bool isCornerInsideTriangle(ref Vector3 p, ref Vector3 u, ref Vector3 v, ref Vector3 w, ref Vector3[] qs)
{
Vector3 rst;
float det = u.X * (w.Z * v.Y - v.Z * w.Y) -
u.Y * (w.Z * v.X - v.Z * w.X) +
u.Z * (w.Y * v.X - v.Y * w.X);
// If plane and ray are parallel
if (det < Utility.GeometricUtils.Epsilon && det > -Utility.GeometricUtils.Epsilon)
return false;
det = 1f / det;
Matrix inv = new Matrix();
inv.M11 = det * (w.Z * v.Y - v.Z * w.Y); inv.M21 = -det * (w.Z * v.X - v.Z * w.X); inv.M31 = det * (w.Y * v.X - v.Y * w.X);
inv.M12 = -det * (w.Z * u.Y - u.Z * w.Y); inv.M22 = det * (w.Z * u.X - u.Z * w.X); inv.M32 = -det * (w.Y * u.X - u.Y * w.X);
inv.M13 = det * (v.Z * u.Y - u.Z * v.Y); inv.M23 = -det * (v.Z * u.X - u.Z * v.X); inv.M33 = det * (v.Y * u.X - u.Y * v.X);
inv.M44 = 1f;
for (int i = 0; i < qs.Length; i++)
{
rst = Vector3.TransformCoordinate(qs[i] - p, inv);
if ((rst.X > 0) && (rst.Y > 0) && ((rst.X + rst.Y) < 1))
return true;
}
return false;
}