0
我在學校學習一些關於重心座標的東西,我發現下面的代碼會計算出點是否在三角形中。但我不知道如何更改代碼,所以我可以輸入來自標準輸入的點的值。我該怎麼辦?用於計算重心座標的C#輸入矢量3
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);
}
你說的「從標準輸入」是什麼意思? – Tipx
從控制檯... – skywlk
你的意思是「你不想用'ref'參數嗎? – Tipx