How to accomplish pendulum effect using the accelerometer in an iOS App
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 e开发者_如何学运维ngine 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,
@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
, where To
is the initial angle (Theta_zero), K
is a proportion constant and Ax
is the horizontal accelerometer measurement. Thus when an impact is sensed, the pendulum starts to oscillate in a magnitude relative to the impact.
The physics aren't too bad for this. A great demo in Java exists here.
精彩评论