且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使一个点绕一条直线,3D

更新时间:2022-01-11 23:27:06

这个问题实际上需要一个非平凡的解决方案.假设您有 U = normalize(L2 - L1) 和两个单位向量 V 和 W,使得 U、V、W 成对正交.

This problem actually requires a nontrivial solution. Suppose you have U = normalize(L2 - L1) and two unit vectors V and W such that U, V, W are pairwise orthogonal.

然后 f(a) = L1 + R * (V * cos(a) + W * sin(a)) 角度 a 是你想要的圆的方程.

Then f(a) = L1 + R * (V * cos(a) + W * sin(a)) for angles a is the equation for the circle you want.

给定 U 和 V,如何找到 W?W 可以只是他们的交叉产品.

How can you find W given U and V? W can just be their cross product.

给定U,你如何找到V?这是不简单的地方.有一整圈这样的 V 可以选择,所以我们不能只求解the"解.

How can you find V given U? This is where it's not straightforward. There are a whole circle of such V that could be chosen, so we can't just solve for "the" solution.

这是找到这样一个 V 的过程.让 U = (Ux, Uy, Yz).

Here's a procedure for finding such a V. Let U = (Ux, Uy, Yz).

如果 Ux != 0 或 Uy != 0,则 V = normalize(cross(U, (0,0,1)))
否则,如果 Ux != 0 或 Uz != 0,则 V = normalize(cross(U, (0,1,0)))
否则 U = 0,错误

If Ux != 0 or Uy != 0, then V = normalize(cross(U, (0,0,1)))
Else if Ux != 0 or Uz != 0, then V = normalize(cross(U, (0,1,0)))
Else U = 0, error

注意:如果你想让你的点在相反的方向循环,你可以否定 W.

Note: You can negate W if you want your point to cycle in the opposite direction.