如何在 iOS 应用程序中使用加速度计实现钟摆效果
我绝不是物理学专家。我正在编写一个 iOS(准确地说是 iPad)应用程序,它将显示一个门把手标志,挂在一个(令人惊讶的)门把手上。我需要完成的是每当设备使用加速度计移动时模拟标志上的钟摆效应。
我是否有必要为此使用成熟的物理引擎?如果是这样,您会推荐哪一个?或者我可以只使用几个众所周知的和定义的公式吗?
和往常一样,谢谢大家。
最好的,
By no means I am a physics expert. I am writing an iOS (iPad to be precise) App which will present a door knob sign, hanging off a (surprise) door knob. What I need to accomplish is to simulate a pendulum effect on the sign whenever the device gets moved around using the accelerometer.
Is it necessary for me to use a full-blown physics engine for this? If so, which one would you recommend? Or can I just make use of a couple of well-known and defined formula?
As usual, thanks to you all.
Best,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Kevin Sylvestre 的指针对于设置枢轴点和起始头角度后计算摆运动给出了很好的解释。您应该在模拟中添加初始角度对水平加速度计测量的加速度大小的依赖性。一个非常简单的关系是设置
To = K*Ax
,其中To
是初始角度 (Theta_zero),K
是比例常数,Ax
是水平加速度计测量值。因此,当感测到冲击时,摆锤开始以相对于冲击的幅度振荡。@Kevin Sylvestre's pointer gives a good explanation for calculating the pendulum motion once the pivot point and the starting head angle are set. What you should add to your simulation is a dependency of the initial angle on the magnitude of acceleration that is measured with the horizontal accelerometer. A very simple relationship is to set
To = K*Ax
, whereTo
is the initial angle (Theta_zero),K
is a proportion constant andAx
is the horizontal accelerometer measurement. Thus when an impact is sensed, the pendulum starts to oscillate in a magnitude relative to the impact.物理学对此来说并不算太糟糕。 此处提供了一个很棒的 Java 演示。
The physics aren't too bad for this. A great demo in Java exists here.