MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / update_velocity

Method update_velocity

physics/n_body_simulation.py:59–84  ·  view source on GitHub ↗

Euler algorithm for velocity >>> body_1 = Body(0.,0.,0.,0.) >>> body_1.update_velocity(1.,0.,1.) >>> body_1.velocity (1.0, 0.0) >>> body_1.update_velocity(1.,0.,1.) >>> body_1.velocity (2.0, 0.0) >>> body_2 = Bod

(
        self, force_x: float, force_y: float, delta_time: float
    )

Source from the content-addressed store, hash-verified

57 return self.velocity_x, self.velocity_y
58
59 def update_velocity(
60 self, force_x: float, force_y: float, delta_time: float
61 ) -> None:
62 """
63 Euler algorithm for velocity
64
65 >>> body_1 = Body(0.,0.,0.,0.)
66 >>> body_1.update_velocity(1.,0.,1.)
67 >>> body_1.velocity
68 (1.0, 0.0)
69
70 >>> body_1.update_velocity(1.,0.,1.)
71 >>> body_1.velocity
72 (2.0, 0.0)
73
74 >>> body_2 = Body(0.,0.,5.,0.)
75 >>> body_2.update_velocity(0.,-10.,10.)
76 >>> body_2.velocity
77 (5.0, -100.0)
78
79 >>> body_2.update_velocity(0.,-10.,10.)
80 >>> body_2.velocity
81 (5.0, -200.0)
82 """
83 self.velocity_x += force_x * delta_time
84 self.velocity_y += force_y * delta_time
85
86 def update_position(self, delta_time: float) -> None:
87 """

Callers 1

update_systemMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected