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)
| 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 | |
| 112 | class BodySystem: |