问题描述
我目前正在寻找一种方法,让物体绕矢量坐标 0,0,0 运行.例如,如果对象位于 X300、Y50、Z200 处,我希望它围绕 0,0,0 旋转,但我不想调整 Y 轴.我不太擅长数学,事实证明这很难掌握.
I am currently looking for a way to have an object orbit the vector coordinates 0,0,0.For instance if the object is located at X300,Y50,Z200 than I would like it to revolve around 0,0,0 but I don't want to adjust the Y axis. I'm not great with math and this is proving to be very difficult to grasp.
推荐答案
轨道意味着你有一个轴.(0, 0, 0) 只是 3D 空间中的一个点,因此您需要另一个点 ( -3, 8, 4 ) 然后从中创建归一化轴.如果您使用 Three.js Object3D
,您可以简单地规范化 objects.up
属性.但我离题了,这是一个简单的向量示例:
Well an orbit implies you have an axis. (0, 0, 0) is just a point in 3D space, so you'll need either another point ( -3, 8, 4 ) to then create a normalized axis from. If you use a Three.js Object3D
you can simply normalize the objects.up
property. But I digress, here's a simple vector example:
var startPoint = new THREE.Vector3( 0, 0, 0 );
var axisVector = new THREE.Vector3( -3, 8, 4);
var endPoint = new THREE.Vector3( 300, 50, 200 );
var rotation = 0.05;
var axis = startPoint.clone().sub(axisVector).normalize();
endPoint.applyAxisAngle( axis, rotation );
这是一个使用两个立方体代替裸 Vector3
的 here 的小提琴这有帮助!
Here's a fiddle using two cubes instead of bare Vector3
's here Hope that helps!
这篇关于让对象围绕矢量点旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!