计算两个向量之间的角度

Vec*_*boy 1 c# math vector angle

我想计算两个 System.Numerics.Vector3 之间的角度,但我找不到任何函数。Google 仅查找 2d 点的结果。我想在c#中实现这个。

Jon*_*asH 5

var v = new Vector3(1, 2, 3);
var u = new Vector3(4, 5, 6);
var angleInRadians = Math.Acos(Vector3.Dot(v, u) / (v.Length() * u.Length()));
Run Code Online (Sandbox Code Playgroud)

请记住,ACos 返回弧度,因此您可能需要将其转换为度数。结果值应介于 0 到 180 度之间。您还应该确保向量的长度不为零。

来源:

https://math.stackexchange.com/questions/974178/how-to-calculate-the-angle- Between-2-vectors-in-3d-space-given-a-preset-function