Bouncing Ball. Making it slow down at peak of height

自闭症网瘾萝莉.ら 提交于 2019-11-27 09:54:12

Use 'real' physics for that.

  1. ball have parameters

    • acceleration a(ax,ay,az) [m/s^2]... this is sum of all forces driving ball divided by its mass
    • velocity v(vx,vy,vz) [m/s]... actual speed = integration of acceleration v += a * dt
    • position p(x,y,z) [m]... actual position = integration of velocity p += v * dt
    • radius r [m]
    • mass m [kg]
    • dt [s] ... iteration step (update time)

    init start a,v values to (0,0,0) and p to start position

  2. apply gravity, friction, collision

    • gravity for example g(gx=0,gy=-9.81,gz=0)
    • friction f2 = -(|v|^2)*c2 * (v/|v|) ... in gas
    • friction f3 = -(|v|^3)*c3 * (v/|v|) ... in liquid

    if position before and after cross collision border reflect velocity * collision coef <=1 by impact normal also you can reflect position if crossing border is not possible.

  3. put it all together in some timer / updating code with dt interval

    a =g+(f2+f3+(driving force))/m
    v+=a*dt
    p+=v*dt
    test_collisions()
    redraw()
    
  4. for manual change of position

    just set p(x,y,z) to new position and also can set v=(0,0,0) to stop the ball

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!