我认为如果我了解什么
np.linalg.norm(A)
np.linalg.det([t, _A, cross])
np.cross(_A, _B)
做
Python代码在此处成立6. @fnord的答案
我在看他们的文档,但我不明白这是比MSDN Doc
最糟糕的事情编辑:
我删除了我的代码,因为我的假设完全不正确。
即使我最初的问题没有回答,我的原始问题也得到了解决。
问题:
如何在3D
中的两个偏斜线之间找到2个最接近的点如果我了解如何以编程方式学习t和s是什么。
您不需要重写这些方法,因为已经内置了等效方法。
例如,要获取两个3维向量之间的距离,您可以使用Vector3.Distance
(Unity Antry)
float distance = Vector3.Distance(someVector, anotherVector);
如果您想找到两个最接近的要点,也应该能够使用其他向量方法来完成此操作。
这是如何使用方法在两个差异线上找到最接近点的示例(取自Unity Wiki)。它仍然使用决定因素来计算这一点。有关为什么有效的解释,您需要了解向量的基本线性代数。
//Two non-parallel lines which may or may not touch each other have a point on each line which are closest
//to each other. This function finds those two points. If the lines are not parallel, the function
//outputs true, otherwise false.
public static bool ClosestPointsOnTwoLines(out Vector3 closestPointLine1, out Vector3 closestPointLine2, Vector3 linePoint1, Vector3 lineVec1, Vector3 linePoint2, Vector3 lineVec2){
closestPointLine1 = Vector3.zero;
closestPointLine2 = Vector3.zero;
float a = Vector3.Dot(lineVec1, lineVec1);
float b = Vector3.Dot(lineVec1, lineVec2);
float e = Vector3.Dot(lineVec2, lineVec2);
float d = a*e - b*b;
//lines are not parallel
if(d != 0.0f){
Vector3 r = linePoint1 - linePoint2;
float c = Vector3.Dot(lineVec1, r);
float f = Vector3.Dot(lineVec2, r);
float s = (b*f - c*e) / d;
float t = (a*f - c*b) / d;
closestPointLine1 = linePoint1 + lineVec1 * s;
closestPointLine2 = linePoint2 + lineVec2 * t;
return true;
}
else{
return false;
}
}