本文整理汇总了Python中vector.Vector.angle方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.angle方法的具体用法?Python Vector.angle怎么用?Python Vector.angle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.angle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scan
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angle [as 别名]
def scan(self, bot):
# menor distancia ate agora
menor = VISAO
ind = -1
# itera todos bots
for b in self.bots:
# se nao eh o proprio e esta ativo
if b is not bot and b.ativo:
# calcula distancia entre os bots
distancia = (bot.posicao - b.posicao).length()
# verifica se a distancia esta dentro do limiar aceitavel
# e eh menor que a menor encontrada ate agora
if distancia-RAIO <= VISAO and distancia < menor:
vet_canhao = Vector(cos(bot.direcao + bot.canhao), sin(bot.direcao + bot.canhao))
vet_alvo = b.posicao - bot.posicao
angulo = vet_canhao.angle(vet_alvo)
if angulo <= mod(bot.arco/2.0 + atan2(RAIO, (bot.posicao - b.posicao).length()), PI):
ind = b.indice
menor = distancia
return menor, ind
示例2: test_float_angle
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angle [as 别名]
def test_float_angle():
v1 = Vector(3.183, -7.627)
v2 = Vector(-2.668, 5.319)
assert v1.angle_in_radians(v2) == 3.0720263098372476
v1 = Vector(7.35, 0.221, 5.188)
v2 = Vector(2.751, 8.259, 3.985)
assert v1.angle(v2) == 60.27581120523091
示例3: test_rotation
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angle [as 别名]
def test_rotation(self):
for _ in range(10):
a = random.uniform(0, math.pi)
x = random.uniform(0, 1)
y = random.uniform(0, 1)
r = Matrix.rotation(a, 0, 0, 1)
u = Vector([x, y, 0])
v = r * u
self.assertAlmostEqual(a, u.angle(v))
m = Matrix([
[0.33482917221585295, 0.8711838511445769, -0.3590656248350022],
[-0.66651590413407, 0.4883301324737331, 0.5632852130622015],
[0.6660675453507625, 0.050718627969319086, 0.7441650662368666],
])
r = Matrix.rotation(5, 1, 2, 3)
self.assertAlmostEqual(r, m)
示例4: test_angle_in_radians
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angle [as 别名]
def test_angle_in_radians(self):
v = Vector([3.183, -7.627])
w = Vector([-2.668, 5.319])
self.assertEqual(round(v.angle(w), 5), 3.07203)
self.assertEqual(v.angle(w), w.angle(v))
示例5: __init__
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angle [as 别名]
class Ship:
def __init__(self, x=50, y=50):
self.pos = Vector(x, y);
self.speed = Vector();
self.accel = Vector();
self.angle = 0;
self.tmpAngle = 0;
self.canShoot = 1;
self.shootLimiter = Timer(2);
self.keyb = 1;
self.keys = {
"up":0,
"down":0,
"left":0,
"right":0,
"shoot":0
};
self.mouse = Vector(0,0);
self.mShoot = 0;
self.accel.x = 1;
self.points = (
Vector(0,-10),
Vector(0,10),
Vector(30,0)
);
def update(self, shoot_function, index):
if self.canShoot:
self.shootLimiter.reset();
else:
self.canShoot = self.shootLimiter.update();
if self.keyb:
if self.keys["up"]: self.accel.y = -0.5;
elif self.keys["down"]: self.accel.y = 0.5;
else:
self.accel.y = 0;
self.speed.y *= 0.98;
if self.keys["left"]: self.accel.x = -0.5;
elif self.keys["right"]: self.accel.x = 0.5;
else:
self.accel.x = 0;
self.speed.x *= 0.98;
if self.keys["shoot"] and self.canShoot:
self.canShoot = 0;
self.shootLimiter.reset();
shoot_function(index);
else:
if self.accel.hyp() < 1: self.accel = Vector(0,1);
self.accel.rot_to(self.mouse.minus(self.pos).angle());
if self.mshoot and self.canShoot:
self.canShoot = 0;
self.shootLimiter.reset();
shoot_function(index);
if not self.accel.isNull(): self.angle = self.accel.angle();
self.speed.add(self.accel);
if not self.speed.isNull():
hyp = self.speed.hyp();
if hyp > 10:
self.speed.set_length(10);
self.pos.add(self.speed);
bounce = self.pos.moveWithinBounds(Vector(800, 600));
if bounce:
if bounce == 1: self.speed.x = -self.speed.x;
elif bounce == 2: self.speed.y = -self.speed.y;
def hit(self):
pass;
def set_keys(self, up, down, left, right, shoot):
self.keyb = 1;
self.keys["up"] = up;
self.keys["down"] = down;
self.keys["left"] = left;
self.keys["right"] = right;
self.keys["shoot"] = shoot;
def set_mouse(self, mpos, mshoot):
self.keyb = 0;
self.mouse.x = mpos[0];
self.mouse.y = mpos[1];
self.mshoot = mshoot;
def net_data(self):
# [0] = ( posX, posY )
# [1] = ( speedX, speedY )
# [2] = angle
# ( ( posX, posY ), ( speedX, speedY ), angle )
return (self.pos.get(1), self.speed.get(1), int(self.angle * 100));
@staticmethod
def collide(ships, shots, explosions=0):
for i in ships:
for shot in shots:
if ships[i].pos.dist_to(shot.pos) < 10:
ships[i].hit();
#.........这里部分代码省略.........
示例6: test_int_angle
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angle [as 别名]
def test_int_angle():
v1 = Vector(1, 2, -1)
v2 = Vector(3, 1, 0)
assert v1.angle(v2) == 49.79703411343022
示例7: Vector
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angle [as 别名]
if __name__ == '__main__' else ""
stdout.write(authorship_string)
from vector import Vector
from matrix import Matrix
v = Vector(1, 2, 3, 4, 5)
u = Vector(0, 1, 2, 3, 4)
w = Vector(-1, -2, -3, -4, -5)
z = Vector(1, 2)
print v + u
print
print v.dot(u)
print
print u.angle(w)
print
a = Matrix((1, 2, 3), (2, 3, 4))
b = Matrix((0, 1, 2), (1, 2, 3))
c = -a
d = Matrix((1, 2, 3), (2, 3, 4), (5, 6, 7))
e = Matrix((1, 2), (3, 4), (5, 6))
f = Matrix((1, 2), (3, 4))
g = Matrix((8, 0, 0, 0), (0, 0, 1, 5), (3, 0, 1, 1), (5, 10, 0, 2))
h = Matrix((0, 0, 0), (0, 1, 5), (3, 1, 1))
i = Matrix((0, 0, 0), (0, 0, 0), (0, 0, 0))
j = Matrix((5, 8, 3, 4, 0),
(5, 9, 4, 4, 8),
(4, 11, 15, 4, 7),
(1, 0, 0, 4, 3),
示例8: getcontext
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import angle [as 别名]
getcontext().prec = 30
####################################################################
#Par projection two is_paralel_to vectors
x = Vector([0,1])
y = Vector([0,-1])
print x.par_proj(y)
print x.ort_proj(y)
print x.angle(y)
print x.angle(y) / math.pi
print x.is_paralel_to(y)
# Vector product
a,b = Vector([8.462,7.893,-8.187]),Vector([6.984,-5.975,4.778])
c,d = Vector([-8.987,-9.838,5.031]),Vector([-4.268,-1.861,-8.866])
e,f = Vector([1.5,9.547,3.691]),Vector([-6.007,0.124,5.772])
print a.cross_product(b)
print c.cross_product(d).magnitude()
print e.cross_product(f).magnitude() /2
# coding vector projecttions