def loadPoints(self,fileName): f = open(fileName,'r') f.readline() #Reading headder size = f.readline()# Reading size of the image width and heigth size = size.split(',') imw = int(size[0]) imh = int(size[1]) # Reading all the points for line in f: vars = line.split(',') x = float(vars[1]) y = float(vars[2]) z = float(vars[3]) if(vars[0] == 'L'): self.leftpts.append(point(x,y,z)) self.lastAdd = 'l' #From what image was the last point added 'l' or 'r' else: self.lastAdd = 'r' #From what image was the last point added 'l' or 'r' self.rightpts.append(point(x,y,z)) # Assigning the depth of the points. This part assumes that the # depth of the left and right image should be the same for the corresponding # points for i in range(min(len(self.leftpts),len(self.rightpts))): self.total += 1 #Total number of landmarks (With depth) self.depth.append(self.rightpts[i].z) return imw, imh
def projectPath(self): self.projected = [] p1 = self.path[-3] p2 = self.path[-2] p3 = self.path[-1] self.horizontalA = self.detectHA(p1,p2,p3) self.verticalA = self.detectVA(p1,p2,p3) while (p2.x > 0 and p2.x < self.screenWidth) and (p2.y > 0 and p2.y < self.screenHeight): newX = int(self.nextX(p1, p2)) newY = int(self.nextY(p1, p2)) p1 = p2 p2 = point(newX, newY) print p2 self.projected.append(point(newX, newY))
def __init__(self, pid, login, game, server, kills, deaths): self.pid, self.login, self.game, self.server, self.map = pid, login, game, server, game.map self.kills = kills; self.deaths = deaths self.health = MAX_HEALTH self.respawn = 1 self.pos = point(0, 0) self.speed = point(0, 0) self.dv = point(0, 0) self.is_start, self.was_action = False, False self.weapon = 'K'; self.last_fire_tick = -INF; self.weapon_angle = -1 self.connects = []
def s_to_Rz( self , s ): N = numpy.size(s) if self.__status: error = ctypes.c_int( 0 ) _error = ctypes.byref( error ) _shotnumber = ctypes.byref(self.__shotnumber) _edition = ctypes.byref(self.__edition) if N == 1: sin = ctypes.c_float( s ) else: sin = (ctypes.c_float*N)() for i in range( N ): sin[i] = s[i] _sin = ctypes.byref( sin ) Raus = (ctypes.c_float*N)() zaus = (ctypes.c_float*N)() aaus = (ctypes.c_float*N)() _Raus = ctypes.byref( Raus ) _zaus = ctypes.byref( zaus ) _aaus = ctypes.byref( aaus ) length = ctypes.c_int( N ) _length = ctypes.byref( length ) lexper = ctypes.c_long( len(self.experiment) ) ldiag = ctypes.c_long( len(self.diagnostic) ) libkk.kkgcsrza_(_error ,self.__exper,self.__diag,_shotnumber,_edition,_length,_sin,_Raus,_zaus,_aaus,lexper,ldiag) output = [] for i in range( N ): output.append( point( zaus[i] , Raus[i] , 0.0 ) ) return output return numpy.nan
def __init__(self): self.foodSpawn = True self.pos = point( random.randrange(1, globs().width // 10) * 10, random.randrange(1, globs().height // 10) * 10)
def read(self): raw = self.accel.readList(self.ADXL345_REG_DATAX0, 6) res = [] for i in range(0, 6, 2): g = raw[i] | (raw[i + 1] << 8) if g > 32767: g -= 65536 res.append(g) return point(res[0], res[1], res[2])
def reset (self, start_point, start_heading): self.alive = True self.set_position(start_point) self.heading = start_heading self.speed = 0 self.moved = False self.steps_without_moving = 0 self.last_position = point(start_point.x, start_point.y)
def random(self): self.list = [] self.clear() os.system('cls') for i in range(50): self.list.append(point()) self.color = "black" self.draw_points()
def read(self): raw = self.accel.readList(self.ADXL345_REG_DATAX0, 6) res = [] for i in range(0, 6, 2): g = raw[i] | (raw[i+1] << 8) if g > 32767: g -= 65536 res.append(g) return point(res[0],res[1],res[2])
def test_get_stats(self): map = ["$......", "#......", "$M#...."] ws1, game, sid1 = self.connect(map) resp = self.recv_ws(ws1) ws2, sid2 = self.connect(game = game) self.move(ws1, resp['tick']) resp1 = self.recv_ws(ws1) while len(resp1['players']) == 1: self.move(ws1, resp1['tick']) resp1 = self.recv_ws(ws1) self.recv_ws(ws2) while True: self.move(ws2, resp['tick'], 1) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) pl = resp['players'][1] if self.equal(pl[X], 1.5): break x = 1.5 v = point(1-1.5, .5-2.5) w = weapons['M'] v = v.scale(w.speed/v.size()) while x +v.x> 1: self.fire(ws2, v.x, v.y) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) x += v.x health = MAX_HEALTH i = 0 while health > 0: print health assert resp['players'][0][HEALTH] == health, (resp['players'][0], health) self.fire(ws2, v.x,v.y) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) if (not i%w.recharge): health -= w.damage i += 1 pl = resp['players'][0] assert pl[HEALTH] == 0 and pl[RESPAWN] == RESP_PLAYER and pl[DEATHS] == 1, pl pl = resp['players'][1] assert pl[KILLS] == 1, pl ws1.close() resp = self.send("leaveGame", {"sid": sid1}) assert resp["result"] == "ok", resp ws2.close() resp = self.send("leaveGame", {"sid": sid2}) assert resp["result"] == "ok", resp resp = self.send("getStats", {"sid": sid1, "game": game}) pls = resp['players'] assert {'login': self.default('user', 2), 'kills': 0, 'deaths': 1} in pls and \ {'login': self.default('user', 1), 'kills': 1, 'deaths': 0} in pls, resp
def check_moved (self): if self.alive and ((self.last_position.x != self.position.x) or \ (self.last_position.y != self.position.y)): self.moved = True else: self.moved = False self.steps_without_moving +=1 self.last_position = point(self.position.x, self.position.y) return self.moved
def render(self, surface): if not self.foodSpawn: self.pos = point( random.randrange(1, globs().width // 10) * 10, random.randrange(1, globs().height // 10) * 10) self.foodSpawn = True self.draw(surface)
def test_reconnection(self): map = ["$......", "#......", "$M#...."] ws1, game, sid1 = self.connect(map) resp = self.recv_ws(ws1) ws2, sid2 = self.connect(game = game) self.move(ws1, resp['tick']) resp1 = self.recv_ws(ws1) while len(resp1['players']) == 1: self.move(ws1, resp1['tick']) resp1 = self.recv_ws(ws1) self.recv_ws(ws2) while True: self.move(ws2, resp['tick'], 1) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) pl = resp['players'][1] if self.equal(pl[X], 1.5): break x = 1.5 v = point(1-1.5, .5-2.5) w = weapons['M'] v = v.scale(w.speed/v.size()) while x +v.x> 1: self.fire(ws2, v.x, v.y) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) x += v.x health = MAX_HEALTH i = 0 while health > 0: assert resp['players'][0][HEALTH] == health, (pl, health) self.fire(ws2, v.x,v.y) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) if (not i%w.recharge): health -= w.damage i += 1 pl = resp['players'][0] assert pl[HEALTH] == 0 and pl[RESPAWN] == RESP_PLAYER and pl[DEATHS] == 1, pl pl = resp['players'][1] assert pl[KILLS] == 1, pl ws1.close() resp = self.send("leaveGame", {"sid": sid1}) assert resp["result"] == "ok", resp self.join_game(game, sid1) ws1 = self.send_ws(action = 'move', params = {'sid': sid1, 'tick': 0, 'dx': 0, 'dy':0}) self.move(ws2) resp = self.recv_ws(ws2) pl = resp['players'][1] assert pl[DEATHS] == 1, pl
def __init__(self): #初始化points数据.. self.start = point() #起点 self.start.loc = (110, 136) self.start.deadline = (0, 3600) self.end = point() #终点 self.end.deadline = (0, 3600) self.end.loc = (487, 535) self.list = [] #遍历点 self.color = "black" #初始颜色 fill填充oval的颜色 self.speed = 4 #速度 for i in range(50): self.list.append(point()) #print("第",i+1,"个点坐标:",self.list[i].loc,",deadline:",self.list[i].deadline) window = Tk() #创建窗口 window.title("TSP Demo") #给窗口命名 #在窗口画布 self.canvas = Canvas(window, width=650, height=650, bg="white") self.canvas.pack() Button(window, text="Random", command=self.random).pack(side=LEFT) #Button(root, text = "Randomise", command = randomise).pack(side = LEFT) Button(window, text="nearest_neighbour", command=self.nearest_neighbour).pack(side=LEFT) Button(window, text="test", command=self.test).pack(side=LEFT) #Button(root, text = "display", command = display).pack(side = LEFT) #self.v = IntVar() #self.num = IntVar() self.accept = IntVar() #Label(window, textvariable = self.v).pack(side = RIGHT) # Label(window, text = "dist:").pack(side = RIGHT) # Label(window, textvariable = self.num).pack(side = RIGHT) # Label(window, text = "num:").pack(side = RIGHT) Label(window, textvariable=self.accept).pack(side=RIGHT) Label(window, text="Acceptance").pack(side=RIGHT) #创建事件循环直到关闭主窗口 window.mainloop()
def draw_it(asteroid): center = point(asteroid.x, asteroid.y) xy_points = [] for p in asteroid.points: l = p[0] a = p[1] x = l*cos(a) y = l*sin(a) x1 = center.x + x y1 = center.y + y xy_points.append(point(x1,y1)) for i in range(1, len(xy_points)): line(xy_points[i].x, xy_points[i].y, xy_points[i-1].x, xy_points[i-1].y) line(xy_points[0].x, xy_points[0].y, xy_points[len(xy_points)-1].x, xy_points[len(xy_points)-1].y)
def avg(array): sumx=0 sumy=0 sumz=0 for x in range (0,len(array)-1): sumx+=array[x].getx() sumy+=array[x].gety() sumz+=array[x].getz() avgX=sumx/len(array) avgY=sumy/len(array) avgZ=sumz/len(array) average=point(avgX,avgY,avgZ) return average
def avg(array): sumx = 0 sumy = 0 sumz = 0 for x in range(0, len(array) - 1): sumx += array[x].getx() sumy += array[x].gety() sumz += array[x].getz() avgX = sumx / len(array) avgY = sumy / len(array) avgZ = sumz / len(array) average = point(avgX, avgY, avgZ) return average
def test_machinegun_hitting(self): map = ["$......", "#......", "$M#...."] ws1, game, sid = self.connect(map) resp = self.recv_ws(ws1) ws2 = self.connect(game = game) self.move(ws1, resp['tick']) resp1 = self.recv_ws(ws1) while len(resp1['players']) == 1: self.move(ws1, resp1['tick']) resp1 = self.recv_ws(ws1) self.recv_ws(ws2) while True: self.move(ws2, resp['tick'], 1) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) pl = resp['players'][1] if self.equal(pl[X], 1.5): break x = 1.5 v = point(1-1.5, .5-2.5) w = weapons['M'] v = v.scale(w.speed/v.size()) while x +v.x> 1: self.fire(ws2, v.x, v.y) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) x += v.x health = MAX_HEALTH i = 0 while health > 0: assert resp['players'][0][HEALTH] == health, (pl, health) self.fire(ws2, v.x,v.y) self.move(ws1) resp = self.recv_ws(ws1) self.recv_ws(ws2) if (not i%w.recharge): health -= w.damage i += 1 pl = resp['players'][0] assert pl[HEALTH] == 0 and pl[RESPAWN] == RESP_PLAYER and pl[DEATHS] == 1, pl pl = resp['players'][1] assert pl[KILLS] == 1, pl
def __init__(self, init_point, init_heading, n_sensors,color=WHITE,sensors_pitch=10,sensors_dist=100): self.alive = True self.speed = 0 self.max_speed = 2 self.heading = init_heading self.position = init_point self.acc = 1 self.turn_rate = np.deg2rad(2) self.n_sensors = n_sensors self.sensors_dist = sensors_dist self.sensors_pitch = sensors_pitch self.calculate_sensor_positions() self.control_func = self.debug_control_func self.color = color self.last_position = point(self.position.x,self.position.y) self.distance_to_finish = 0 self.last_distance_to_finish = 0 self.steps_without_moving = 0
def rotate_sphere(near_spheres, touching_spheres, c): # matrice di ruotazione intorno all'asse u = (ux, uy, uz) # # [ cos(t) + pow(uz,2) * (1 - cos(t)) ux * uy * (1-cos(t)-uz*sin(t) ux*uz*(1-cos(t)) + uy*sin(t) ] # R = [ uy * ux * (1 - cos(t)) + uz * sin(t) cos(t) + pow(uy,2) * (1-cos(t) uy*uz*(1-cos(t)) - ux*sin(t) ] # [ uz * ux * (1 - cos(t)) - uy * sin(t) uz*uy*(1-cos(t)) + ux*sin(t) cos(t)+pow(uz,2)*(1-cos(t)) ] # if (len(touching_spheres) == 1): # una sfera asse passante per il centro della sfera # che tocco. Faccio la ratazione per asse che passa per il centro della # sfera che tocco e poi un punto p0 = touching_spheres[0].get_center() # un punto random fuori dalla sfera che tocco p1x = random.uniform(botx, topx) p1y = random.uniform(boty, topy) p1z = p0.get_z() # un punto random fuori dalla sfera che tocco #p1x = p0.get_x() + 1.0 #p1y = p0.get_y() #p1z = p0.get_z() p1 = point(p1x, p1y, p1z) touching_spheres_now = rotate_as_possible(c, p0, p1, near_spheres, 2) if (len(touching_spheres_now) == 2): p0 = touching_spheres_now[0].get_center() p1 = touching_spheres_now[1].get_center() rotate_as_possible(c, p0, p1, near_spheres, 3) elif (len(touching_spheres) == 2): # la sfera ne tocca altre due quindi routa intorno all'asse che unisce # le due che tocca p0 = touching_spheres[0].get_center() p1 = touching_spheres[1].get_center() touching_spheres_now = rotate_as_possible(c, p0, p1, near_spheres, 3) return
def move(self, food): if self.action == Action.MOVE_RIGHT: self.head.x += 10 elif self.action == Action.MOVE_LEFT: self.head.x -= 10 elif self.action == Action.MOVE_UP: self.head.y -= 10 elif self.action == Action.MOVE_DOWN: self.head.y += 10 x = self.head.x y = self.head.y self.body.insert(0, point(x, y)) if (self.head.x == food.pos.x and self.head.y == food.pos.y): food.foodSpawn = False else: self.body.pop()
def test_rocket_launcher_longway(self): map = ["...............", "...............", "...............", "...............", "$R............."] ws = self.connect(map) self.recv_ws(ws) x = self.take_gun(ws) y = 4.5 self.fire(ws,84,-155) v = point(84,-155) v = v.scale(weapons['R'].speed/v.size()) while y+v.y>0: resp = self.recv_ws(ws) pr = resp['projectiles'][0] assert self.equal(pr[X], x) and self.equal(pr[Y], y) and self.equal(pr[VX], v.x) and self.equal(pr[VY], v.y), (pr, v.x,v.y) x+=v.x y+=v.y self.move(ws)
def get_sensor_position (self, sensor_id): # front sensors are numbered from left to right, with `sensors_pitch` distance between them # they are positioned in a line perpendicular to track direction and `sensors_dist` apart from robot's position #calculate sensor position without considering heading sensor_x = self.sensors_dist sensor_y = ((self.n_sensors - 1)/2 - sensor_id) * self.sensors_pitch #transform into polar coordinates z = (sensor_x + sensor_y * 1j) r,theta = z2polar(z) #sum heading to theta to calculate sensor position in reference to robot position new_theta = theta + self.heading new_z = polar2z(r,new_theta) #calculate final position in reference to track's origin final_sensor_x = round(np.real(new_z) + self.position.x) final_sensor_y = round(np.imag(new_z) + self.position.y) return point(int(final_sensor_x), int(final_sensor_y))
def generate_surface_points(self, n): point_list = [] d = (2.0 * math.pi) / float(n - 1) alpha = 0.0 for i in range(n): beta = 0.0 for j in range(n): x = self.radius * math.sin(alpha) * math.cos(beta) + \ self.center.get_x() y = self.radius * math.sin(alpha) * math.sin(beta) + \ self.center.get_y() z = self.radius * math.cos(alpha) + self.center.get_z() point_list.append(point(x, y, z)) beta += d alpha += d return point_list
def __init__(self, n, A=10, B=10, _start_point=point(), _end_point=point(-1, -1)): self.length = n self.points = [ point(randint(0, A - 1), randint(0, B - 1)) for _ in range(self.length) ] if 0 < _end_point.x < A or 0 < _end_point.y < B: self.end_point = point(_end_point.x, _end_point.y) else: self.end_point = point(A - 1, B - 1) if 0 < _start_point.x < A or 0 < _start_point.y < B: self.start_point(_start_point.x, _start_point.y) else: self.start_point = point(0, 0) self.cost = 0 self.calcCost()
import numpy as np from math import * import cv2 from point import * from light import light from player import player from surface import surface me = player() li = light() res = me.ppdist * 2 img = np.zeros((res, res, 3), np.uint8) mytri = surface('tri', point(0, 10, 0), point(10, 20, 0), point(0, 30, 10)) k = cv2.waitKey(10) & 0xFF norm = cross(sub(mytri.p2, mytri.p1), sub(mytri.p3, mytri.p1)) mnorm = norm.mod() while (k != 27): img = np.zeros((res, res, 3), np.uint8) n1 = add(mytri.p1, me.position) n2 = add(mytri.p2, me.position) n3 = add(mytri.p3, me.position) n1.project(me.ppdist) n2.project(me.ppdist) n3.project(me.ppdist) n1 = me.findfinal(n1)
def above_floor(self): if self.map.is_wall(self.pos + point(.5-EPS, .5+EPS)) or\ self.map.is_wall(self.pos + point(-.5+EPS, .5+EPS)): return True else: return False
filename = "final_config.txt" if (len(sys.argv)) == 2: filename = sys.argv[1] file = open(filename, "r") spheres = [] zmax = xmax = ymax = -10000.0 zmin = xmin = ymin = 10000.0 for sp in file: x, y, z, r = sp.split(" ") r = 1.0 center = point(float(x), float(y), float(z)) s = sphere(center, float(r)) spheres.append(s) if (zmax < (float(z) + float(r))): zmax = (float(z) + float(r)) if (xmax < (float(x) + float(r))): xmax = (float(x) + float(r)) if (ymax < (float(y) + float(r))): ymax = (float(y) + float(r)) if (zmin > (float(z) - float(r))): zmin = (float(z) - float(r)) if (xmin > (float(x) - float(r))): xmin = (float(x) - float(r)) if (ymin > (float(y) - float(r))):
def fire(self, params): if self.game.c_ticks - self.last_fire_tick >= weapons[self.weapon].recharge: self.last_fire_tick = self.game.c_ticks v = point(params['dx'],params['dy']) self.weapon_angle = v.angle() self.game.projectiles.append(projectile(self, self.weapon,v))
def resp(self): spawn = self.game.get_spawn() self.pos = spawn + point(0.5, 0.5) self.speed = point(0,0) self.health = MAX_HEALTH self.weapon = 'K'
def go(self): if self.game.c_ticks == 3: pass speed = self.speed if speed.size() < EPS: return if abs(self.speed.x) < EPS: self.speed.x = 0 if abs(self.speed.y) < EPS: self.speed.y = 0 dir = speed.direct() dir1 = point(1 if dir.x else -1, 1 if dir.y else -1) pos_cell = (self.pos + dir1.scale(-EPS)).index() forward = self.pos + dir1.scale(.5-EPS) forward_cell = forward.index() forward = self.pos + dir1.scale(.5) #forward_cell = forward.index() #if self.map.map[forward_cell.y][forward_cell.x] == '#': # pass from collections import defaultdict collisions = defaultdict(list) dists = (forward_cell + dir - forward, pos_cell + dir - self.pos) #### (a,b)-collision descriptor a(1-center, 0-forward), b(0-x, 1-y, 2-angle) #### for i in range(2): dist = dists[i] is_reach_x = speed.x and abs(speed.x) > abs(dist.x) + EPS; is_reach_y = speed.y and abs(speed.y) > abs(dist.y) + EPS; dist_size = dist.size(); speed_size = speed.size() if is_reach_x and is_reach_y and (dist_size < EPS or (speed.scale(dist_size/speed_size) - dist).size()<EPS): collisions[dist.x/speed.x].append((i,2)) else: if is_reach_x: collisions[dist.x/speed.x].append((i,0)) if is_reach_y: collisions[dist.y/speed.y].append((i,1)) ### was_coll = [X,Y] ### was_coll = [False,False] times = collisions.keys() times.sort() for time in times: for coll in collisions[time]: offset = dir1 * point(int(bool(coll[1] - 1)), int(bool(coll[1]))) * point(not was_coll[0], not was_coll[1]) if not offset.x and not offset.y: continue if coll[0]: pos_cell += offset el = self.map.map[pos_cell.y][pos_cell.x] if '0'<=el<='9': self.teleport(pos_cell); return elif 'A'<=el<='z': self.take_item(pos_cell) else: coll_cell = forward_cell + offset x_neib_wall = self.map.map[coll_cell.y][coll_cell.x - dir1.x] == '#' y_neib_wall = self.map.map[coll_cell.y - dir1.y][coll_cell.x] == '#' coll_cell_wall = self.map.map[coll_cell.y][coll_cell.x] == '#' if coll[1] == 2: if x_neib_wall: self.speed.y = 0 was_coll[1] = True if y_neib_wall: self.speed.x = 0 was_coll[0] = True if coll_cell_wall and not y_neib_wall and not x_neib_wall: if time < EPS: self.speed.y = 0 was_coll[1] = True else: self.speed = point(0,0) was_coll = [True,True] elif coll[1] == 1: if coll_cell_wall or (abs(self.pos.x - int(self.pos.x) - .5) > EPS or abs(self.speed.x) > EPS) and not was_coll[0] and x_neib_wall: self.speed.y = 0 was_coll[1] = True else: forward_cell = coll_cell elif coll[1] == 0: if coll_cell_wall or (abs(self.pos.y - int(self.pos.y) - .5) > EPS or abs(self.speed.y) > EPS) and not was_coll[1] and y_neib_wall: self.speed.x = 0 was_coll[0] = True else: forward_cell = coll_cell if was_coll[0] and was_coll[1]: break self.pos += speed if was_coll[0]: self.pos.x = forward_cell.x + .5 if was_coll[1]: self.pos.y = forward_cell.y + .5
def move(self, params): self.dv += point(params['dx'],params['dy'])
def main(): # Setup a renderer, render window, and interactor renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() #renderWindow.SetWindowName("Test") renderWindow.AddRenderer(renderer) renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # determino la box file = open("final_config.txt", "r") zmax = xmax = ymax = -10000.0 zmin = xmin = ymin = 10000.0 for sp in file: x, y, z, r = sp.split(" ") center = point(float(x), float(y), float(z)) s = sphere(center, float(r)) spheres.append(s) if (zmax < (float(z) + float(r))): zmax = (float(z) + float(r)) if (xmax < (float(x) + float(r))): xmax = (float(x) + float(r)) if (ymax < (float(y) + float(r))): ymax = (float(y) + float(r)) if (zmin > (float(z) - float(r))): zmin = (float(z) - float(r)) if (xmin > (float(x) - float(r))): xmin = (float(x) - float(r)) if (ymin > (float(y) - float(r))): ymin = (float(y) - float(r)) file.close() # add cube sources = [] addcube_to_source (sources, zmin, ymin, zmin, \ xmax, ymax, zmax) for s in sources: mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(s.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) renderer.AddActor(actor) file = open("final_config.txt", "r") for sp in file: x, y, z, r = sp.split(" ") center = point(float(x), float(y), float(z)) s = sphere(center, float(r)) spheres.append(s) file.close() #Render and interact renderWindow.Render() # Initialize must be called prior to creating timer events. renderWindowInteractor.Initialize() # Sign up to receive TimerEvent cb = vtkTimerCallback() cb.actor = actor renderWindowInteractor.AddObserver('TimerEvent', cb.execute) timerId = renderWindowInteractor.CreateRepeatingTimer(100) #start the interaction and timer renderWindowInteractor.Start()
def teleport(self, dot): self.pos = point(*self.map.tps[dot.to_turple()]) return
# -*- coding: utf-8 -*- """ Created on Wed Oct 14 20:29:42 2015 @author: Pie """ from point import * from edge import * from face import * from plotting import * p1 = point(0,0,0) p2 = point(2,0,0) p3 = point(2,2,0) p4 = point(0,2,0) #print p1 #print p2 #print p3 #print p4 e1 = edge(p1,p2) e2 = edge(p2,p3) e3 = edge(p3,p4) e4 = edge(p4,p1) #print e1 #print e2
from point import * a = point() print(a.deadline)
def is_point_inside(self, x, y, z): p = point(x, y, z) d = self.center.get_distance_from(p) return (d < self.radius)
def __init__(self, posX=100, posY=50): self.head = point(100, 50) self.body = [point(100, 50), point(90, 50), point(80, 50)] self.action = Action.MOVE_RIGHT
def test_point_creation(): p = point(22, 7) def test_access_x_and_y(): assert 22 == getx(p) assert 7 == gety(p)
from point import * #1 p1 = point(3, (1., 2., 3.)) p2 = point(3, (6., 7., 8.)) x = p1.dist(p2) print(x) #2 p2.mirror()
def set0(self): self.origin=point(self) return self.origin
# raggio delle sfere R_sphere = 5.0 pores = [] hm = 0 while len(pores) < how_many_pores: # il diametro e' genrato con una distribuzione # gaussiana con deviazione 3.33 e diametro 40.0 r = random.gauss(40.0, 3.33)/2.0 cx = random.uniform(botx+r, topx-r) cy = random.uniform(boty+r, topy-r) cz = random.uniform(botz+r, topz-r) c = point(cx, cy, cz) s = sphere(c, r) # controllo che non tocchi troppo gli altri pori if len(pores) == 0: pores.append(s) else: hmd = 0 for p in pores: cp = p.get_center() rp = p.get_radius() if cp.get_distance_from(c) > (rp+r+2.0*R_sphere): hmd += 1
import numpy as np from math import * import cv2 from point import * from light import light from player import player from surface import surface me = player() li = light() res = me.ppdist*2 img = np.zeros((res,res,3), np.uint8) mytri = surface('tri', point(0,10,0), point(10,20,0), point(0,30,10)) k = cv2.waitKey(10) & 0xFF norm = cross( sub(mytri.p2, mytri.p1), sub(mytri.p3, mytri.p1) ) mnorm = norm.mod() while(k != 27): img = np.zeros((res,res,3), np.uint8) n1 = add(mytri.p1,me.position) n2 = add(mytri.p2,me.position) n3 = add(mytri.p3,me.position) n1.project(me.ppdist) n2.project(me.ppdist) n3.project(me.ppdist) n1 = me.findfinal(n1)
def set0(self): self.origin = point(self) return self.origin
def __init__(self, center=point(0.0, 0.0, 0.0), radius=0.0): self.center = center self.radius = radius
from point import * p1 = point(3, [1., 2., 3.]) p2 = point(3, [6., 7., 8.]) print(p1) print(p2) print("p1 + p2", p1.add(p2)) print("magnitude of resultant p1", p1.sqmag())
from point import * p1 = point(3, [1, 2, 3]) p1 print(p1) p2 = point(3, [6, 7, 8]) p2 print(p2) p1.dist(p2) print(p1.dist(p2)) p1.mirror() print(p1)
def addRightPoint(self,x,y): if(len(self.leftpts)<len(self.rightpts)): print "The next point has to be selected from the left image" else: self.lastAdd = 'r' self.rightpts.append(point(x,y,0))
from point import * from projectile import * from config import * ZERO = point(0, 0) def sign(x): return 1 if x > 0 else -1 class player: def __init__(self, pid, login, game, server, kills, deaths): self.pid, self.login, self.game, self.server, self.map = pid, login, game, server, game.map self.kills = kills; self.deaths = deaths self.health = MAX_HEALTH self.respawn = 1 self.pos = point(0, 0) self.speed = point(0, 0) self.dv = point(0, 0) self.is_start, self.was_action = False, False self.weapon = 'K'; self.last_fire_tick = -INF; self.weapon_angle = -1 self.connects = [] #---------------------------function for using on client message ---------------------------------# def action(self, msg): self.was_action = True
from point import * p1=point(3, [1.2, 8.2, 3.4]) p1 p1.scale(3.3) print(p1) p2=point(3, [3.1, 4.5, 2.2]) print("p1 dot p2=", p1.dot(p2)) #p1= 3.95999999999995, 27.059999999999995, 11.219999999999999 p1 dot p2=158.73
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license()" for more information. >>> == RESTART: /Users/JessicaLopez/Documents/chem160homework4-master/point.py == >>> from point import * >>> p1 = point(3, [1,2,3]) >>> print(p1) 1.0 2.0 3.0 >>> p2 = point(3, [6,7,8]) >>> print(p2) 6.0 7.0 8.0 >>> print("p1 add p2=", p1.add(p2)) p1 add p2= 27.0 >>> print("p1 add p2=", p1.sqmag(p2)) p1 add p2= 163.0 >>>