如果矢量有4个分量,则将矢量映射到y轴 [英] Mapping a vector across the y-axis if it has 4 components

查看:118
本文介绍了如果矢量有4个分量,则将矢量映射到y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在节点上施加力和扭矩。这是我的代码:

I am applying a force and a torque on an node. This is my code:

myNode?.physicsBody?.applyForce(SCNVector3Make(0, -6, 4), atPosition: SCNVector3Make(0, 1, -1), impulse: true)
myNode?.physicsBody?.applyForce(SCNVector3Make(0, -2, 10), impulse: true)
myNode?.physicsBody?.applyTorque(SCNVector4Make(4, 2, 2.5, 1.6), impulse: true)

对象现在倒下了之后从左向右移动。我希望它从右向左移动(基本上反映了第一次移动穿过y轴)。我发现我对前2行代码的处理很少,因为力没有x分量。最后一行 applyTorque 是我需要操作的那一行。如果向量有4个组件,你如何映射y轴?我对数学有点生疏

The object now falls down and moves from left to right afterwards. I want it fall down and move from right to the left(basically a reflection of the first movement across y-axis). I figured it out that there is very little I can do about the first 2 lines of code, because the force has no x-component. The last line, applyTorque, is the one I need to manipulate. How do you map across the y-axis if the vector has 4 components? I am a little rusty with math

推荐答案

我假设x轴是水平的,y轴是垂直的z轴指向你(见下面的黑色箭头):

I am assuming that the x-axis is horizontal and the y-axis is vertical and the z-axis points straight at you (see the black arrows below):

我找到了证据在SceneKit中确实如此。

I found evidence that this is indeed the case in SceneKit.

如果

applyTorque(SCNVector4Make(x, y, z, w), impulse: boolean)

是正确的用法,然后 x 是围绕x轴逆时针旋转的量(参见绿色圆圈箭头),同样 y z 。同样,这是我最好的猜测,SceneKit可能使用顺时针旋转。因此, x y z 一起确定扭转力的旋转轴。

is the correct usage, then x is the amount of counter-clockwise rotation around the x-axis (see green circle arrow), and similarly for y and z. Again, this is my best guess, and it is possible that SceneKit uses clockwise rotation. Therefore, x, y, and z together determine the axis of rotation of the torsional force.

这是一种更简单的思考方式。 x y z 在上面描述的3D空间。对象将围绕此向量逆时针旋转。

Here is a simpler way to think of it. x, y, and z create a vector in the 3D space described above. The object will rotate counter-clockwise around this vector.

w 另一方面,是扭矩的大小,与旋转轴无关。

w on the other hand, is the magnitude of the torque, and has nothing to do with the axis of rotation.

您对在y轴上映射矢量的请求实际上是横跨yz平面的反射。如果你考虑一下,你想要的是围绕y轴旋转相反的方向(否定 y )和z相同的方向。

Your request to "map vector across the y-axis" is actually a reflection across the yz-plane. If you think about it, what you want is to rotate the opposite direction around the y-axis (negate y) and the same for z.

所以答案应该是:

myNode?.physicsBody?.applyTorque(SCNVector4Make(4, -2, -2.5, 1.6), impulse: true)

这篇关于如果矢量有4个分量,则将矢量映射到y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆