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

Method update_position

physics/n_body_simulation.py:86–109  ·  view source on GitHub ↗

Euler algorithm for position >>> body_1 = Body(0.,0.,1.,0.) >>> body_1.update_position(1.) >>> body_1.position (1.0, 0.0) >>> body_1.update_position(1.) >>> body_1.position (2.0, 0.0) >>> body_2 = Body(10.,10.,0.

(self, delta_time: float)

Source from the content-addressed store, hash-verified

84 self.velocity_y += force_y * delta_time
85
86 def update_position(self, delta_time: float) -> None:
87 """
88 Euler algorithm for position
89
90 >>> body_1 = Body(0.,0.,1.,0.)
91 >>> body_1.update_position(1.)
92 >>> body_1.position
93 (1.0, 0.0)
94
95 >>> body_1.update_position(1.)
96 >>> body_1.position
97 (2.0, 0.0)
98
99 >>> body_2 = Body(10.,10.,0.,-2.)
100 >>> body_2.update_position(1.)
101 >>> body_2.position
102 (10.0, 8.0)
103
104 >>> body_2.update_position(1.)
105 >>> body_2.position
106 (10.0, 6.0)
107 """
108 self.position_x += self.velocity_x * delta_time
109 self.position_y += self.velocity_y * delta_time
110
111
112class BodySystem:

Callers 1

update_systemMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected