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
2 réponses
-
Bonjour,
t = range(0,100)
Tu essaie de multiplier un réel (g
) par un objet de type range ... -
Bonjour,
Tu initialisesg
à9, 81
c'est-à-dire avec le couple(9, 81)
, alors que tu veux probablement l'initialiser avec le réel 9,81 ce qui s'écritg = 9.81
(avec un point, pas une virgule).
Ensuite, comme le souligne Phil, tu multipliesg
part
(de typerange
) or cette opération n'a pas de sens en python, queg
soit un couple ou un flottant. Tout dans le calcul laisse penser quedy
devrait être un flottant, donc il faudrait initialisert
avec une valeur réelle.
Ensuite je trouve maladroit d'utiliser une variableO
, c'est confusant avec0
, peut-être devrais-tu utiliser un autre nom (par exempleangle
).
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 - tu peux initialiser