implemented updateing position of particle
This commit is contained in:
parent
849682b13b
commit
1bb3c84b25
|
@ -52,20 +52,25 @@
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"class Particle:\n",
|
"class Particle:\n",
|
||||||
" def __init__(self, mass, velocity):\n",
|
" def __init__(self, mass, velocity, position):\n",
|
||||||
" self.mass = mass\n",
|
" self.mass = mass\n",
|
||||||
" self.velocity = velocity\n",
|
" self.velocity = velocity\n",
|
||||||
|
" self.position = position\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def momentum(self):\n",
|
" def momentum(self):\n",
|
||||||
" return self.mass * self.velocity\n",
|
" return self.mass * self.velocity\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" def update_position(self, dt):\n",
|
||||||
|
" self.position = self.position + self.velocity * dt\n",
|
||||||
|
" return self.position\n",
|
||||||
|
"\n",
|
||||||
"particle = Particle(mass=2.1, velocity=0.8)\n",
|
"particle = Particle(mass=2.1, velocity=0.8)\n",
|
||||||
"print(particle.momentum())"
|
"print(particle.momentum())"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
|
@ -78,7 +83,8 @@
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"position = 8.2\n",
|
"position = 8.2\n",
|
||||||
"new_position = update_position(particle.velocity, position, dt=0.1)\n",
|
"particle = Particle(2.1, 0.8, position)\n",
|
||||||
|
"new_position = particle.update_position(dt=0.1)\n",
|
||||||
"print(new_position)"
|
"print(new_position)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue