Python:ベクトル演算

python-vector.png
import math;
import numpy;
loc = numpy.array([100., 100.]);
vel = numpy.array([30., 10]);
 
loc += vel
 
# reseting speed to a default value, maintaining direction
numpy.linalg.norm(vel)
print(vel)
vel *= 200
print(vel)
loc += vel
print(loc)
print("x=%d"%loc[0])

サポートサイト Wikidot.com