【发布时间】:2019-10-28 18:57:33
【问题描述】:
我尝试计算相交平面和线,但我认为得到错误的结果。 试试这段代码(来自http://wiki.unity3d.com/index.php/3d_Math_functions):
public static bool LinePlaneIntersection(out Vector3 intersection, Vector3 linePoint, Vector3 lineVec, Vector3 planeNormal, Vector3 planePoint)
{
float length;
float dotNumerator;
float dotDenominator;
Vector3 vector;
intersection = Vector3.zero;
//calculate the distance between the linePoint and the line-plane intersection point
dotNumerator = Vector3.Dot((planePoint - linePoint), planeNormal);
dotDenominator = Vector3.Dot(lineVec, planeNormal);
if (dotDenominator != 0.0f)
{
length = dotNumerator / dotDenominator;
vector = SetVectorLength(lineVec, length);
intersection = linePoint + vector;
return true;
}
else
return false;
}
【问题讨论】:
-
如果你这样做是为了学习,那就继续吧。如果你打算在你的游戏中使用它,那么也许你应该停下来,改用 Physics.Raycast/Linecast。
标签: c# unity3d intersection