本文整理汇总了Python中vector.Vector.x方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.x方法的具体用法?Python Vector.x怎么用?Python Vector.x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def __init__(self, minimum, maximum, target_minimum=None, target_maximum=None, ratio=None):
self.minimum = minimum
self.maximum = maximum
if not target_minimum:
target_minimum = Vector()
if not target_maximum:
target_maximum = maximum - minimum
space = Vector()
if ratio:
if ratio == 'geo':
ratio = math.sin((90.0 - ((self.maximum.y + self.minimum.y) / 2.0)) / 180.0 * math.pi)
current_ratio = (self.maximum.x - self.minimum.x) * ratio / (self.maximum.y - self.minimum.y)
target_ratio = (target_maximum.x - target_minimum.x) / (target_maximum.y - target_minimum.y)
if current_ratio >= target_ratio:
n = (target_maximum.x - target_minimum.x) / (maximum.x - minimum.x) / ratio
space.y = ((target_maximum.y - target_minimum.y) - (maximum.y - minimum.y) * n) / 2.0
space.x = 0
else:
n = (target_maximum.y - target_minimum.y) / (maximum.y - minimum.y)
space.x = ((target_maximum.x - target_minimum.x) - (maximum.x - minimum.x) * n) / 2.0
space.y = 0
target_minimum.x += space
target_maximum.x += space
self.target_minimum = target_minimum
self.target_maximum = target_maximum
示例2: line_center
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def line_center(node_ids):
ma = Vector()
mi = Vector(10000, 10000)
for node_id in node_ids:
node = node_map[node_id]
flinged = flinger.fling(Geo(node['lat'], node['lon']))
if flinged.x > ma.x: ma.x = flinged.x
if flinged.y > ma.y: ma.y = flinged.y
if flinged.x < mi.x: mi.x = flinged.x
if flinged.y < mi.y: mi.y = flinged.y
return Vector((ma.x + mi.x) / 2.0, (ma.y + mi.y) / 2.0)
示例3: apply
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def apply(boid, xmin, xmax, ymin, ymax):
v = Vector()
position = boid.position
if position.x < xmin:
v.x = 10
elif position.x > xmax:
v.x = -10
if position.y < ymin:
v.y = 10
elif position.y > ymax:
v.y = -10
return v
示例4: test_eq
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def test_eq(self):
v5 = Vector(0,0)
v5.x = 5
v5.y = 5
#self.assertEqual(v5,self.vec5)
self.assertTrue(v5 == self.vec5)
self.assertTrue((v5 == self.vec1) is False)
示例5: test_ne
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def test_ne(self):
v5 = Vector(0,0)
v5.x = 5
v5.y = 5
self.assertEqual(v5,self.vec5)
self.assertTrue(v5 != self.vec1)
self.assertTrue((v5 != self.vec5) is False)
示例6: collideWith
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def collideWith(self, foe):
"""assumed cells are colliding"""
#get distance between cell radii as a vector
selfPos = self.pos
foePos = foe.pos
xDiff = selfPos.x - foePos.x
yDiff = selfPos.y - foePos.y
dist = math.sqrt(xDiff**2 + yDiff**2)
dist += 5
distVec = Vector(xDiff, yDiff)
distVec.x = round(distVec.x,3)
distVec.y = round(distVec.y,3)
unitVec = distVec/dist
unitVec.x = round(unitVec.x, 3)
unitVec.y = round(unitVec.y, 3)
#make a force vector
forcApp = 1/dist
forcApp = round(forcApp, 3)
forcVec = unitVec * forcApp
forcVec.x = round(forcVec.x, 3)
forcVec.y = round(forcVec.y, 3)
#apply the force vector to other cell
#the target's acceration is changed
#by F/target's mass
targetPushVec = forcVec/foe.mass
targetPushVec.x = round(targetPushVec.x, 3)
targetPushVec.y = round(targetPushVec.y, 3)
foe.acl += -targetPushVec
示例7: test_vec_coords_2d
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def test_vec_coords_2d(self):
v = Vector(1, 2)
self.assertEqual(v.x, 1)
self.assertEqual(v.y, 2)
self.assertEqual(v.z, None)
v.x, v.y = 3, 4
self.assertEqual(v.x, 3)
self.assertEqual(v.y, 4)
示例8: ehrefest_force
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def ehrefest_force(dBz, pos, psi):
force = Vector([0., 0., 0.])
force.x = np.dot(psi.conj().transpose(),
np.dot(force_evolution_operator_x(dBz, pos), psi)).real
force.y = np.dot(psi.conj().transpose(),
np.dot(force_evolution_operator_y(dBz, pos), psi)).real
force.z = np.dot(psi.conj().transpose(),
np.dot(force_evolution_operator_z(dBz, pos), psi)).real
return force
示例9: test_accessors
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def test_accessors(self):
v = Vector(11, 12)
self.assertEqual(v.x, 11)
self.assertEqual(v.y, 12)
self.assertEqual(v[0], 11)
self.assertEqual(v[1], 12)
v[0] = 13
self.assertEqual(v.x, 13)
v[1] = -7
self.assertEqual(v.y, -7)
v.x = 1
self.assertEqual(v[0], 1)
v.y = 0
self.assertEqual(v[1], 0)
示例10: test_vec_coords_3d
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def test_vec_coords_3d(self):
v = Vector(1, 2, 3)
self.assertEqual(v.x, 1)
self.assertEqual(v.y, 2)
self.assertEqual(v.z, 3)
v.x, v.y, v.z = 4, 5, 6
self.assertEqual(v.x, 4)
self.assertEqual(v.y, 5)
self.assertEqual(v.z, 6)
v = Vector(7, 8)
v.z = 9
self.assertEqual(v.x, 7)
self.assertEqual(v.y, 8)
self.assertEqual(v.z, 9)
示例11: draw
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def draw(self):
w,h = self.width,self.height
#w,h = screenwidth/2,screenheight/2
self.image = pygame.Surface( (w,h) )
self.image.fill(bgcolor)
self.image.set_colorkey(bgcolor)
self.image = self.image.convert_alpha()
self.rect = self.image.get_rect()
# draw coordinates
pygame.draw.line(self.image,gridcolor,self.rect.midleft,self.rect.midright,1) # x-coord
pygame.draw.line(self.image,gridcolor,self.rect.midtop,self.rect.midbottom,1) # y-coord
# draw circle
r = int(w/4)
pygame.draw.circle(self.image,gridcolor,self.rect.center, r, 1)
# draw angle
vd = Vector(0,0)
vd.x = cos(30*GRAD)
vd.y = -sin(30*GRAD)
pos1 = Vector(self.rect.center) + vd* r
pos1 = int(pos1.x),int(pos1.y)
print pos1
pygame.draw.line(self.image,blue,self.rect.center,pos1,2)
# draw frame
pygame.draw.rect(self.image,gridcolor,self.rect,1)
# x,y
xsurf = write('x',blue,26)
xrect = xsurf.get_rect()
xrect.center = self.rect.right - 20, self.rect.centery
self.image.blit(xsurf,xrect)
ysurf = write('+y',blue,26)
yrect = ysurf.get_rect()
yrect.center = self.rect.centerx, self.rect.bottom - 20
self.image.blit(ysurf,yrect)
# draw Tank
tanksurf,a,b = drawTank(w/8,h/8,green)
tankrect = tanksurf.get_rect()
tankrect.center = self.rect.center
self.image.blit(tanksurf,tankrect)
# draw Cannon
cannonsurf = drawCannon(self.width/4,self.height/4)
cannonrect = cannonsurf.get_rect()
#pygame.draw.rect(cannonsurf,red,cannonrect,2) frame
cannonrect.center = self.rect.center
self.image.blit(cannonsurf,cannonrect)
# Tank Forward direction
dh=14; dw = dh*6
drect = self.rect.centerx+r/2, self.rect.centery-dh/2,dw,dh
drect = pygame.Rect(drect)
pygame.draw.rect(self.image,red,drect)
# draw Forward arrow
endpoint = drect.midright[0]+14,drect.midright[1]
toppoint = endpoint[0]-20,endpoint[1]- 14
bottompoint = endpoint[0]-20,endpoint[1]+ 14
pointlist = endpoint,toppoint,bottompoint
pygame.draw.polygon(self.image,red,pointlist)
self.drawText((20,20),'Instructions',black,32)
self.drawText((20,100),'move Forward : K',black)
self.drawText((20,120),'move Backward : J',black)
self.drawText((20,140),'rotate Tank Left: A',black)
self.drawText((20,160),'rotate Tank Right: S',black)
self.drawText((20,180),'rotate Cannon Left: D',black)
self.drawText((20,200),'rotate Cannon Right: F',black)
self.drawText((20,220),'fire Cannon: SPACE',black)
self.drawText((20,240),'fire Machine Gun: L',black)
示例12: Vector
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
# size = 0
# s_size = 0
print "TIME_WINDOW_MIN: ", TIME_WINDOW_MIN
print "TIME_WINDOW_MAX: ", TIME_WINDOW_MAX
print "PRECISION: ", PRECISION
two_seconds_elapsed = time.time()
while True:
if sample_size == SAMPLE_SIZE:
sample_size = 0
# print "--------------------------------- finished 50 samples \n"
dynamic_threshold.x = (accel_max.x + accel_min.x) / 2
dynamic_threshold.y = (accel_max.y + accel_min.y) / 2
dynamic_threshold.z = (accel_max.z + accel_min.z) / 2
accel_max = Vector(0, 0, 0)
accel_min = Vector(sys.maxint, sys.maxint, sys.maxint)
first_time = False
# filter accelerometer values
accel_xout = read_word_2c(mpu_address, 0x3B)
accel_yout = read_word_2c(mpu_address, 0x3D)
accel_zout = read_word_2c(mpu_address, 0x3F)
accel_val = Vector(accel_xout, accel_yout, accel_zout)
示例13: while
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
most_axis_axis = 1
first_time = True
print "TIME_WINDOW: ", TIME_WINDOW
print "PRECISION: " , PRECISION
two_seconds_elapsed = time.time()
while(True):
if(sample_size == 50):
sample_size = 0
# print "--------------------------------- finished 50 samples \n"
dynamic_threshold.x = (accel_sum.x) / SAMPLE_SIZE
dynamic_threshold.y = (accel_sum.y) / SAMPLE_SIZE
dynamic_threshold.z = (accel_sum.z) / SAMPLE_SIZE
accel_sum.x = 0
accel_sum.y = 0
accel_sum.z = 0
first_time = False
accel_xout = read_word_2c(0x3b)
accel_yout = read_word_2c(0x3d)
accel_zout = read_word_2c(0x3f)
accel_val = Vector(accel_xout, accel_yout, accel_zout)
示例14: open
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
first_time = True
accel_graph = open('accel_graph-stride_length.txt', 'w')
# execution stage
time_elapsed = time.time()
while(time.time() - time_elapsed <= 15):
# filter accelerometer values
accel_xout = read_word_2c(mpu_address, 0x3b) - accel_offset_x
accel_yout = read_word_2c(mpu_address, 0x3d) - accel_offset_y
accel_zout = read_word_2c(mpu_address, 0x3f) - accel_offset_z
accel_val = Vector(accel_xout, accel_yout, accel_zout)
gravity.x = HIGH_PASS * gravity.x + (1 - HIGH_PASS) * accel_val.x
gravity.y = 0
gravity.z = HIGH_PASS * gravity.z + (1 - HIGH_PASS) * accel_val.z
accel_val.x = accel_val.x - gravity.x
accel_val.y = accel_val.y - gravity.y
accel_val.z = accel_val.z - gravity.z
accel_val.x = (accel_filter_list[0].x + accel_filter_list[1].x + accel_filter_list[2].x + accel_filter_list[3].x + accel_val.x) / 5
accel_val.y = (accel_filter_list[0].y + accel_filter_list[1].y + accel_filter_list[2].y + accel_filter_list[3].y + accel_val.y) / 5
accel_val.z = (accel_filter_list[0].z + accel_filter_list[1].z + accel_filter_list[2].z + accel_filter_list[3].z + accel_val.z) / 5
accel_filter_list.insert(moving_index, accel_val)
moving_index = (moving_index + 1) % 4
示例15: TargetFuncDerivative3
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import x [as 别名]
def TargetFuncDerivative3( vec ):
brace = vec.y - vec.x ** 2
rez = Vector()
rez.x = -400 * vec.x * brace - 2 * ( 1 - vec.x )
rez.y = 200 * brace
return rez