控制绕球体运行的物体 [英] Controlling an object orbiting a sphere

查看:45
本文介绍了控制绕球体运行的物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让用户控制在静态球体表面上移动的对象.使用两个按钮顺时针和逆时针旋转物体的方向,因为它像小行星一样不断向前移动.

I want to let the user control an object moving over the surface of a static sphere. Using two buttons to rotate the direction of the object clockwise and anti-clockwise as it constantly moves forward similar to asteroids.

在场景套件中,SCNNode 有三种不同的方向属性,我真的不知道从哪里开始.我了解如何执行除围绕球体旋转之外的所有内容.

In scene kit there are three different orientation properties for an SCNNode and I really don't know where to start. I understand how to execute everything except the rotation around the sphere.

推荐答案

您正在寻找球体表面的参数化.您可以在网上找到它(但如果您不知道要为搜索输入的魔法词,这可能会很棘手).查看 MathWorld 上的条目.

You're looking for a parameterization of the surface of the sphere. You can find this online (but it can be tricky if you don't know the magic words to enter for your searches). Check out the entry on MathWorld.

球体的表面由两个角度变量参数化,分别称为st.请注意,一个变量将从零运行到 2 pi,而另一个将仅从零运行到 pi.这是一个很容易错过的问题.要将这些角度转换为矩形 (x, y, z) 坐标,请使用以下公式:

The surface of the sphere is parameterized by two angle variables, call them s and t. Note that one variable will run from zero to 2 pi, and the other will run only from zero to pi. This is a gotcha that can be easy to miss. To convert these angles to rectangular (x, y, z) coordinates, you use the formula:

x = r cos(s) sin(t)
y = r sin(s) sin(t) // Yes it's sin(t) twice, that's not a typo.
z = r cos(t)

我发现以下可视化很有帮助.平面(例如 xy 平面)中的曲线从 0 到 pi 扫出一个角度,旋转半圈,对应于参数 s.如果你设置 t 等于 pi/2,所以 sin(t) = 1,那么你可以看到 x 和 y 如何变成圆形截面的标准直角坐标.s参数扫出半圆后,可以将那半圆一直绕从零旋转到2圆周率,形成一个完整的球体,然后全扫对应参数t.

I find the following visualization helpful. A curve in a plane (the xy-plane, for example) sweeps out an angle from zero to pi, half a rotation and corresponds to the parameter s. If you set t equal to pi/2, so sin(t) = 1, then you can see how x and y turn into standard rectangular coordinates for a circular section. After the s parameter sweeps out half a circle, you can rotate that half circle all the way around from zero to 2 pi, to form a full sphere, and that full sweep corresponds to the parameter t.

如果您用坐标(s, t) 表示对象的位置,那么在大多数情况下,您可以使用上述公式安全地转换为直角坐标,而无需担心任一参数的定义域;然而,如果 st 无限制地增长(例如,因为您的物体连续运行很长时间),那么对参数进行归一化的额外努力可能是值得的.我不确定 sincos 对于非常大的输入是如何表现的.

If you represent your object's position by coordinates (s, t) then you can, for the most part, safely convert to rectangular coordinates using the formula above without worrying about the domain of either parameter; however if s or t grow without bound (say, because your object orbits continuously for a long time) it might be worth the small extra effort to normalize the parameters. I'm not sure how sin or cos behave for very large inputs.

这篇关于控制绕球体运行的物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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