私は射撃(射撃運動)によって破壊しなければならない物体を持っているとしましょう。オブジェクトの位置はランダムです(現在のように、整数を簡単にします)。私の '弾丸'が正しい位置にあるように見えても、ループは壊れません。おそらく、プログラムはグラフ1とグラフ2をどの点でも等しく見なさないでしょう。 条件については何も試してみませんでしたが、何もうまくいきませんでした。 誰でも追加/変更が必要なことを教えてもらえますか?なぜグラフの2つの引数が等しいと見なされないのですか?
import matplotlib.pylab as plt
import numpy as np
import random
g = 10
c = []
d = []
fig = plt.figure()
L = random.randint(5.0,18.0)
while True:
try:
#velocity
v = float(input("What is the velocity?\n>"))
#angle
a = np.radians(float(input("What is the angle?\n>")))
z = np.sin(2*a)*v**2/g #max range
h = ((v**2*(np.sin(a))**2)/(2*g)) #max. height
x= np.linspace(0, z, 1000)
#y values
y = (x*np.tan(a) - (g*x**2)/(2*v**2*((np.cos(a))**2)))
ax = plt.axes(xlim=(0, 1.5*L), ylim=(0, 1.2*h))
plt.ion() #interactive graph
#previous tries
plt.plot(c,d, '.', color = 'lightgrey')
plt.pause(0.01)
#enemy object
graph1 = plt.plot(L, 0, 'o', color = 'r', markersize=30)
plt.pause(0.01)
#actual shoot
graph2 = plt.plot(x,y, '.', color = 'b', ms = 7)
plt.pause(0.01)
if np.any(graph2) == np.any(graph1):
print("You have destroyed the enemy object!")
plt.show()
break
else:
print("You've missed. Keep shooting!")
c.append(x)
d.append(y)
plt.show()
continue
except ValueError:
print("Sorry, I can't understand.")
'np.any(graph2 == graph1)'または '(graph1 == graph2).any()'を意味しますか? – mgilson
これらのいずれかが機能するかどうかはわかりません。私はちょうど彼らが本当であるかどうかを認識し、ループを壊したい。 – Tokela