有物体围绕载体点物体、载体

2023-09-08 01:12:11 作者:我打算爱你很久@

我目前正在寻找一种方法来有一个对象轨道上的向量坐标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)仅仅是在三维空间中的一个点,所以你需要或是其他的点(-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's a fiddle using two cubes instead of bare Vector3's here Hope that helps!