本文整理汇总了Python中Point.Point类的典型用法代码示例。如果您正苦于以下问题:Python Point类的具体用法?Python Point怎么用?Python Point使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Point类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDistanceTo
def testDistanceTo(self):
p = Point(3,4)
q = Point(4,5)
self.assertEquals(p.distanceTo(q), q.distanceTo(p))
self.assertEquals(p.distanceTo(q), math.sqrt(2))
self.assertEquals(p.distanceTo(self.p0), 5.0)
示例2: isBallInFrontOfRobot
def isBallInFrontOfRobot(robotState,ball,param_x = .5, param_y = .04, behind_x = 0):
refPoint = Point(ball.x-robotState.x,ball.y - robotState.y)
if refPoint.x < 0:
if abs(refPoint.x) < behind_x:
print "behind ball %.2f m but still rushing" %(abs(refPoint.x))
refPoint.x = -refPoint.x
else:
print "ball is too far behind, stopping rush"
return False
#print "refence from robot: %f, %f" % (refPoint.x,refPoint.y)
#print "angle: %f" % robotState.theta
rotatedPoint = MotionSkills.rotatePointByAngle(refPoint, robotState.theta)
#print "rotatedPoint to robot frame: %f, %f" % (rotatedPoint.x,rotatedPoint.y)
angleToGoal = MotionSkills.angleBetweenPoints(robotState, HOME_GOAL)
angleDiff = abs(angleToGoal-robotState.theta)
if angleDiff > math.pi:
angleDiff = (2*math.pi - angleDiff)
#print 'angle difference: %d' %((angleDiff/math.pi)*180)
if rotatedPoint.x > 0 and rotatedPoint.x < param_x and rotatedPoint.y < param_y and rotatedPoint.y > -param_y:
#print "Behind Ball!"
if angleDiff < 0.15:
#print "Angled toward Goal"
return True
print "Not angled to goal!"
return False
print "Not Behind Ball!"
return False
示例3: getVelocity
def getVelocity(self, at):
#Get the location of the sphero
spheroPoint = Point(at.x, at.y)
#Get the vector towards the goal.
#path should be set by set by the pathfinder?
if spheroPoint.distanceTo(self.path[self.current]) < SIZE_OF_GRID:
if self.current >= len(self.path) - 1:
self.current = 0
else:
self.current += 1
dest = self.path[self.current]
x = y = 0
up = Point(dest.x, dest.y - 1)
left = Point(dest.x - 1, dest.y)
down = Point(dest.x, dest.y + 1)
right = Point(dest.x + 1, dest.y)
poly = [up, left, down, right]
wayPoint = AttractiveField(-1, 80, 1, poly)
tmpPoint = wayPoint.getVect(spheroPoint).getPoint()
x += tmpPoint.x
y += tmpPoint.y
#print "fields: " + str(self.fields)
for field in self.fields:
if type(field) is AttractiveField and field.inCircle(spheroPoint):
return Point(0, 0)
tmpPoint = field.getVect(spheroPoint).getPoint()
print "vector" + str(field.id) + "=" + str(tmpPoint)
x += tmpPoint.x
y += tmpPoint.y
point = Point(x, y)
#print "velocity= " + str(point)
return point
示例4: do_parse_vessel_file
def do_parse_vessel_file(self):
# print "ok"
start = time.time()
with open(self.filePath, "r+b") as f:
# memory-mapInput the file, size 0 means whole file
map_input = mmap.mmap(f.fileno(), 0)
# read content via standard file methods
for s in iter(map_input.readline, ""):
s = s.translate(None, "\r\n")
# print s
a_line_of_values = s.split(" ")
# print a_line_of_values
point = Point()
if len(a_line_of_values) == 5:
point.set_reference_point(float(a_line_of_values[0]), float(a_line_of_values[1]),
float(a_line_of_values[2]), float(a_line_of_values[3]),
float(a_line_of_values[4]))
# print point.get_x()
elif len(a_line_of_values) == 3:
point.set_centerline_point(float(a_line_of_values[0]), float(a_line_of_values[1]),
float(a_line_of_values[2]))
# print point.get_x()
self.vesselValues.append(point)
map_input.close()
end = time.time()
print "Time for completion", end - start
示例5: read_vertices
def read_vertices(filename, ):
""" spara resultatet av liknande fråga som denna som csv. X;Y;Z ingen header
select x,y, id /*, sdo_geom.validate_geometry_with_context(y.shape, 0.0005), t1.* */ from setfast.fastomry y
, TABLE(sdo_util.getvertices(
sdo_util.extract(y.shape,1,1)
)) t1
where y.objectid = 34486581
"""
points = []
f = open(filename, 'r')
for row in f.readlines():
if( row[0] == '\n' ):
break
cols = row.split(';')
cols = map(lambda x: float(str.replace(x, ',', '.')), cols)
print cols
p = Point(cols[0], cols[1])
p.id = cols[2]
points.append(p)
segments = []
for p1,p2 in zip(points[:-1], points[1:]):
l = Line(p1,p2)
segments.append(l)
return segments
示例6: center
def center(points):
center_point = Point(0,0,0)
for point in points:
center_point.x += point.x
center_point.y += point.y
center_point.x = center_point.x/float(len(points))
center_point.y = center_point.y/float(len(points))
return center_point
示例7: test_get_distance
def test_get_distance(self):
l = LaserMote()
p = Point()
p.last_seen_x = 20
p.last_seen_y = 20
l.point = p
self.assertAlmostEqual(28.2842712, l.get_distance(40, 40), places=7, msg="get_distance failed test.",
delta=None)
示例8: position_at
def position_at(self, time):
dt = time - self.src_time
if dt > 0.0 and self.total_time > 0.0:
ratio = dt / self.total_time
p = Point()
p.x = self.src.x + self.dx * ratio
p.y = self.src.y + self.dy * ratio
return p
else:
return self.src
示例9: __init__
def __init__(self, name, mass, charge, x, y, velx, vely, accx, accy, fixed):
Point.__init__(self, x, y)
self.name = name
self.mass = mass
self.charge = charge
self.velx = velx
self.vely = vely
self.accx = accx
self.accy = accy
self.rigid = fixed
self.ForceList = []
self.OverrideE = None
self.OverrideG = None
示例10: isIntersected
def isIntersected(line1, line2):
vector1 = Point.getVector(line2.startPoint, line1.startPoint)
vector2 = Point.getVector(line2.startPoint, line1.endPoint)
vector3 = Point.getVector(line2.startPoint, line2.endPoint)
if Point.crossProduct(vector1, vector3) * Point.crossProduct(vector2, vector3) > 0:
return False
vector1 = Point.getVector(line1.startPoint, line2.startPoint)
vector2 = Point.getVector(line1.startPoint, line2.endPoint)
vector3 = Point.getVector(line1.startPoint, line1.endPoint)
if Point.crossProduct(vector1, vector3) * Point.crossProduct(vector2, vector3) > 0:
return False
return True
示例11: pointOrder
def pointOrder(self, G):
factors = ECMath.allFactors(self.order())
a = self.getA()
b = self.getB()
p = self.getP()
temp = Point()
infinity = Point()
multiple = 0
for l in factors:
temp = temp.add(G.mult(l-multiple, a, b, p), a, b, p)
multiple = l
if temp == infinity:
return l
return -1 # error
示例12: cloneLinkedList
def cloneLinkedList(self):
cursor = self.HEAD
# make a copy of the head first:
newHead = Point(cursor.x, cursor.y)
newHead.ear = cursor.ear
newHead.name = cursor.name
# use a loop to create clones of the rest of the points:
cursor = cursor.next
newCursor = newHead
while cursor is not self.HEAD:
newPoint = Point(cursor.x, cursor.y)
newPoint.ear = cursor.ear
newPoint.name = cursor.name
# link the previous point to the new one:
newCursor.next = newPoint
newPoint.prev = newCursor
cursor = cursor.next
newCursor = newPoint # same as: newCursor = newCursor.next
# finally, link the new head and tail before returning the head:
newHead.prev = newCursor
newCursor.next = newHead
return newHead, self.SIZE
示例13: Avoider
class Avoider(Enemy):
def __init__(self, scene, x, y):
super().__init__(scene, x, y)
self._velocity = Point(0, 0)
self.set_shape(sh.STAR_SHAPE, Colors.avoid, True, 5)
def update(self):
player = self._scene.player
vec_to_player = player.position - self.position
dir_to_player = math.atan2(vec_to_player.y, vec_to_player.x)
angle = self._angle_distance(player.direction, dir_to_player)
if angle < math.pi/2:
dirvec = vec_to_player
speed = ACCELERATION
else:
avoid_point = Point(1, 1)
avoid_count = 0
for obj in self.scene.objects:
if isinstance(obj, pl.Bullet):
distance = (obj.position - self.position).length_sqr()
if distance <= DISTANCE_SQR:
avoid_point += obj.position
avoid_count += 1
if avoid_count > 0:
avoid_point /= avoid_count
dirvec = self.position - avoid_point
speed = DODGE
else:
dirvec = vec_to_player
speed = ACCELERATION
self._velocity += dirvec * speed / dirvec.length()
if self._velocity.length_sqr() > SPEED_SQR:
self._velocity.normalize()
self._velocity *= SPEED
self.position += self._velocity
self.direction += ANGULAR_SPEED
super().update()
def _angle_distance(self, alpha, beta):
phi = abs(beta - alpha) % 360
distance = 360 - phi if phi > 180 else phi
return distance
示例14: __init__
def __init__(self, scene, x, y, direction):
super().__init__(scene)
self.position = Point(x, y)
self.set_shape(sh.BULLET_SHAPE, Colors.bullet, True, 5)
self.direction = direction
self._velocity = Point.anglelen(direction, BULLET_SPEED)
self._clamp_inside = False
示例15: __init__
def __init__(self, origin, edge_length, dataset):
self._origin = Point(origin)
self._edge_length = edge_length
self._dataset = dataset
self._set_voxel_datapoints()
self._set_voxel_dataedges()
self._dc_vertices = []