Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Verlet integration
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Algorithmic representation === Since '''velocity Verlet''' is a generally useful algorithm in 3D applications, a solution written in C++ could look like below. This type of position integration will significantly increase accuracy in 3D simulations and games when compared with the regular Euler method.<syntaxhighlight lang="c++" line="1"> struct Body { Vec3d pos { 0.0, 0.0, 0.0 }; Vec3d vel { 2.0, 0.0, 0.0 }; // 2 m/s along x-axis Vec3d acc { 0.0, 0.0, 0.0 }; // no acceleration at first double mass = 1.0; // 1kg /** * Updates pos and vel using "Velocity Verlet" integration * @param dt DeltaTime / time step [eg: 0.01] */ void update(double dt) { Vec3d new_pos = pos + vel*dt + acc*(dt*dt*0.5); Vec3d new_acc = apply_forces(); Vec3d new_vel = vel + (acc+new_acc)*(dt*0.5); pos = new_pos; vel = new_vel; acc = new_acc; } /** * To apply velocity to your objects, calculate the required Force vector instead * and apply the accumulated forces here. */ Vec3d apply_forces() const { Vec3d new_acc = Vec3d{0.0, 0.0, -9.81 }; // 9.81 m/sΒ² down in the z-axis // Apply any other forces here... // NOTE: Avoid depending on `vel` because Velocity Verlet assumes acceleration depends on position. return new_acc; } }; </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)