def make_vert(circ0, circ1, axes): v = vec.zero_vec(d) v[axes[0][0]] = circ0[0] v[axes[0][1]] = circ0[1] v[axes[1][0]] = circ1[0] v[axes[1][1]] = circ1[1] return v
def __init__(self, verts, edges, faces, pos=None, frame=None, scale=None): d = vec.dim(verts[0]) self.verts_ref = verts #relative vertex positions self.verts = verts.copy() #absolute vertex positions self.edges = edges #list of edges self.faces = faces #list of faces self.ref_frame = vec.eye(d) self.transparent = False if pos is None: self.pos = vec.zero_vec(d) else: self.pos = pos if frame is None: self.frame = vec.eye(d) else: self.frame = frame if scale is None: self.scale = 1. else: self.scale = scale self.subfaces = self.calc_subfaces() self.calc_face_fuzz() self.update(update_face_fuzz=True) if not self.check_normals(): print("Warning: not all normals perpendicular")
def draw_circle_2d(radius, color, n_points=60, line_width=2, draw_origin=vec.zero_vec(2)): glColor3f(*color) glLineWidth(line_width) glBegin(GL_LINE_LOOP) for i in range(n_points): x = math.cos(math.pi * 2 * i / n_points) * radius y = math.sin(math.pi * 2 * i / n_points) * radius p = vec.Vec([x, y]) + draw_origin glVertex2f(*shift_scale_point(p)) glEnd()
def __init__(self, pos, angles=None): d = len(pos) self.pos = pos if angles is None: self.angles = vec.zero_vec(d) else: self.angles = angles self.ref_frame = vec.eye(d) self.frame = self.ref_frame self.target_shape = build_cube(d) self.target_distance = 30 self.update_rot_matrix(0, 1, 0)
def init(d, size, focal=6, view_radius=5, view_height=5, stereo=False, n_fuzz_points=10): this.d = d #this.pygame = pygame this.focal = focal this.view_radius = view_radius this.view_height = view_height this.view_boundary = 'sphere' #scale faces very slightly to avoid drawing edges on top of each other #also, for some reason, setting this to one leads to a divide by 0 error #when there's transparency this.face_scales = [0.95] this.bounds_color = colors.GRAY this.show_fuzz = False this.random_fuzz = np.random.uniform(size=[n_fuzz_points, d - 1]) #for face fuzz this.width = size[0] this.height = size[1] this.center = (this.width // 2, this.height // 2) #needed for mouse input if d == 3: this.graphics = opengl_draw_2d this.draw_origin = vec.zero_vec(d) this.graphics.init(size, this.draw_origin) if d == 4: this.draw_origin = Vec([0.0, 0.0, -15.0]) this.graphics = opengl_draw_3d this.graphics.init(size, this.draw_origin) this.stereo = stereo this.stereo_sep = Vec([5, 0, 0]) this.view_angles = [30, 30] this.stereo_view_angles = [[30, 30], [120, 30]]
def draw_circle_3d(radius, axes, color, draw_origin, draw_angles, n_points=30, line_width=2): gl.glLoadIdentity() # reset position gl.glTranslatef(*draw_origin) #origin of plotting gl.glRotatef(draw_angles[1], 1, 0, 0) gl.glRotatef(draw_angles[0], 0, 1, 0) glColor3f(*color) glLineWidth(line_width) glBegin(GL_LINE_LOOP) for i in range(n_points): x = math.cos(math.pi * 2 * i / n_points) * radius y = math.sin(math.pi * 2 * i / n_points) * radius p = vec.zero_vec(3) p[axes[0]] = x p[axes[1]] = y glVertex3f(*p) glEnd()
def check_normal(self, shape): vertis = self.get_verts(shape) verts = [shape.verts_ref[vi] for vi in vertis] dots = [vec.dot(v - self.center, self.normal_ref) for v in verts] return np.all(vec.isclose(dots, vec.zero_vec(len(dots))))