Ballistics python
Bonjour,
Je dois rendre ce projet dans 2 semaines et je n'ai aucune idée par où commencer et comment, si quelqu'un peut m'aider ça serait génial ^^
Enoncé : The Ballistic game puts two player separated by a large distance. Each
player, one after another, send a ball toward its opponent by specifying its
initial velocity and angle with the horizontal. If the ball hits the opponent,
the player wins. Of course the ball experiences the gravity and will follow a
ballistic trajectory. Furthermore additional physics can be included such as
wind friction, rebounds, etc... Typical games similar to this are “Gorilla”
or “Angry birds”
Pour l'instant, j'ai ça mais ça ne marche pas:
message d'erreur :
Je dois rendre ce projet dans 2 semaines et je n'ai aucune idée par où commencer et comment, si quelqu'un peut m'aider ça serait génial ^^
Enoncé : The Ballistic game puts two player separated by a large distance. Each
player, one after another, send a ball toward its opponent by specifying its
initial velocity and angle with the horizontal. If the ball hits the opponent,
the player wins. Of course the ball experiences the gravity and will follow a
ballistic trajectory. Furthermore additional physics can be included such as
wind friction, rebounds, etc... Typical games similar to this are “Gorilla”
or “Angry birds”
Pour l'instant, j'ai ça mais ça ne marche pas:
import numpy as np import math as mt import matplotlib.pyplot as plt X = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) v0 = 10 O = 45 g = 9,81 t = range(0, 100) dx = v0 * np.cos(O) dy = 0 -(g) * t + v0 * np.sin(O)
message d'erreur :
TypeError Traceback (most recent call last)
<ipython-input-39-83b88550cace> in <module>()
8 t = range(0, 10000)
9 dx = v0 * np.cos(O)
---> 10 dy = 0 -(g) * t + v0 * np.sin(O)
TypeError: can't multiply sequence by non-int of type 'range'
| EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI Merci d'y penser dans tes prochains messages. |
Configuration: Windows / Chrome 100.0.4896.127
A voir également:
- Ballistics python
- Citizen code python avis - Accueil - Outils
- \R python ✓ - Forum Python
- Citizen code python solution - Forum Python
- Python est introuvable. exúcutez sans argument pour procúder ó l ✓ - Forum Python
- Python par la pratique : 101 exercices corrigés pdf - Forum Python
2 réponses
Bonjour,
Tu initialises
Ensuite, comme le souligne Phil, tu multiplies
Ensuite je trouve maladroit d'utiliser une variable
Enfin :
Bonne chance
Tu initialises
gà
9, 81c'est-à-dire avec le couple
(9, 81), alors que tu veux probablement l'initialiser avec le réel 9,81 ce qui s'écrit
g = 9.81(avec un point, pas une virgule).
Ensuite, comme le souligne Phil, tu multiplies
gpar
t(de type
range) or cette opération n'a pas de sens en python, que
gsoit un couple ou un flottant. Tout dans le calcul laisse penser que
dydevrait être un flottant, donc il faudrait initialiser
tavec une valeur réelle.
Ensuite je trouve maladroit d'utiliser une variable
O, c'est confusant avec
0, peut-être devrais-tu utiliser un autre nom (par exemple
angle).
Enfin :
- tu peux initialiser
X
avecX = np.arange(1, 11)
(et n'est pas utilisée pour le moment), - le
0
au début du calcul dedy
ne sert à rien, - le paquet
math
etmatplotlib
ne sont pas utilisés, donc pas besoin de l'importer pour le moment.
import numpy as np
#import math as mt
#import matplotlib.pyplot as plt
#X = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
v0 = 10
angle = 45
g = 9.81
dx = v0 * np.cos(angle)
for t in range(0, 100):
dy = -g * t + v0 * np.sin(angle)
print(dy)
Bonne chance