我在学校学习了一些关于重心坐标的知识,我在下面找到了计算点是否在三角形中的代码。但是我不知道如何更改代码,以便可以从标准输入中输入点的值。我该怎么办?
public static bool PointInTriangle(ref Vector3 A, ref Vector3 B, ref Vector3 C, ref Vector3 P)
{
// Prepare our barycentric variables
Vector3 u = B - A;
Vector3 v = C - A;
Vector3 w = P - A;
Vector3 vCrossW = Vector3.Cross(v, w);
Vector3 vCrossU = Vector3.Cross(v, u);
// Test sign of r
if (Vector3.Dot(vCrossW, vCrossU) < 0)
return false;
Vector3 uCrossW = Vector3.Cross(u, w);
Vector3 uCrossV = Vector3.Cross(u, v);
// Test sign of t
if (Vector3.Dot(uCrossW, uCrossV) < 0)
return false;
// At this piont, we know that r and t and both > 0
float denom = uCrossV.Length;
float r = vCrossW.Length / denom;
float t = uCrossW.Length / denom;
return (r <= 1 && t <= 1 && r + t <= 1);
}