def to_vertices_and_faces(self, **kwargs): """Returns a list of vertices and faces""" u = kwargs.get('u') or 10 if u < 3: raise ValueError('The value for u should be u > 3.') vertices = [] a = 2 * pi / u for i in range(u): x = self.circle.radius * cos(i * a) y = self.circle.radius * sin(i * a) z = self.height / 2 vertices.append([x, y, z]) vertices.append([x, y, -z]) # transform vertices to cylinder's plane frame = Frame.from_plane(self.circle.plane) M = matrix_from_frame(frame) vertices = transform_points(vertices, M) faces = [] for i in range(0, u * 2, 2): faces.append([i, i + 1, (i + 3) % (u * 2), (i + 2) % (u * 2)]) faces.append([i for i in range(0, u * 2, 2)]) faces.append([i for i in range(1, u * 2, 2)]) faces[-1].reverse() return vertices, faces
def to_vertices_and_faces(self, **kwargs): if 'u' in kwargs: u = kwargs['u'] else: u = 10 vertices = [] a = 2 * pi / u for i in range(u): x = self.circle.radius * cos(i * a) y = self.circle.radius * sin(i * a) z = self.height / 2 vertices.append([x, y, z]) vertices.append([x, y, -z]) # transform vertices to cylinder's plane frame = Frame.from_plane(self.circle.plane) M = matrix_from_frame(frame) vertices = transform_points(vertices, M) faces = [] for i in range(0, u*2, 2): faces.append([i, i+1, (i+3)%(u*2), (i+2)%(u*2)]) faces.append([i for i in range(0, u*2, 2)]) faces.append([i for i in range(1, u*2, 2)]) faces[-1].reverse() return vertices, faces
def to_vertices_and_faces(self, **kwargs): """Returns a list of vertices and faces, called by `Mesh.from_shape()`.""" if 'u' in kwargs: u = kwargs['u'] else: u = 10 vertices = [] a = 2 * pi / u for i in range(u): x = self.circle.radius * cos(i * a) y = self.circle.radius * sin(i * a) vertices.append([x, y, 0]) vertices.append([0, 0, self.height]) # transform vertices to cylinder's plane frame = Frame.from_plane(self.circle.plane) M = matrix_from_frame(frame) vertices = transform_points(vertices, M) faces = [] last = len(vertices) - 1 for i in range(u): faces.append([i, (i + 1) % u, last]) faces.append([i for i in range(u)]) faces[-1].reverse() return vertices, faces
def to_vertices_and_faces(self, **kwargs): """Returns a list of vertices and faces""" u = kwargs.get('u') or 10 v = kwargs.get('v') or 10 if u < 3: raise ValueError('The value for u should be u > 3.') if v < 3: raise ValueError('The value for v should be v > 3.') theta = pi * 2 / u phi = pi * 2 / v vertices = [] for i in range(u): for j in range(v): x = cos(i * theta) * (self.radius_axis + self.radius_pipe * cos(j * phi)) y = sin(i * theta) * (self.radius_axis + self.radius_pipe * cos(j * phi)) z = self.radius_pipe * sin(j * phi) vertices.append([x, y, z]) # transform vertices to torus' plane frame = Frame.from_plane(self.plane) M = matrix_from_frame(frame) vertices = transform_points(vertices, M) faces = [] for i in range(u): ii = (i + 1) % u for j in range(v): jj = (j + 1) % v a = i * v + j b = ii * v + j c = ii * v + jj d = i * v + jj faces.append([a, b, c, d]) return vertices, faces
def to_vertices_and_faces(self, **kwargs): """Returns a list of vertices and faces, called by `Mesh.from_shape()`.""" if 'u' in kwargs: u = kwargs['u'] else: u = 10 if 'v' in kwargs: v = kwargs['v'] else: v = 10 theta = pi*2 / u phi = pi*2 / v vertices = [] for i in range(u): for j in range(v): x = cos(i * theta) * (self.radius_axis + self.radius_pipe * cos(j * phi)) y = sin(i * theta) * (self.radius_axis + self.radius_pipe * cos(j * phi)) z = self.radius_pipe * sin(j * phi) vertices.append([x, y, z]) # transform vertices to torus' plane frame = Frame.from_plane(self.plane) M = matrix_from_frame(frame) vertices = transform_points(vertices, M) faces = [] for i in range(u): ii = (i + 1) % u for j in range(v): jj = (j + 1) % v a = i * v + j b = ii * v + j c = ii * v + jj d = i * v + jj faces.append([a, b, c, d]) return vertices, faces
def to_vertices_and_faces(self, **kwargs): """Returns a list of vertices and faces""" u = kwargs.get('u') or 10 if u < 3: raise ValueError('The value for u should be u > 3.') vertices = [] a = 2 * pi / u z = self.height / 2 for i in range(u): x = self.circle.radius * cos(i * a) y = self.circle.radius * sin(i * a) vertices.append([x, y, z]) vertices.append([x, y, -z]) # add v in bottom and top's circle center vertices.append([0, 0, z]) vertices.append([0, 0, -z]) # transform vertices to cylinder's plane frame = Frame.from_plane(self.circle.plane) M = matrix_from_frame(frame) vertices = transform_points(vertices, M) faces = [] # side faces for i in range(0, u * 2, 2): faces.append([i, i + 1, (i + 3) % (u * 2), (i + 2) % (u * 2)]) # top and bottom circle faces for i in range(0, u * 2, 2): top = [i, (i + 2) % (u * 2), len(vertices) - 2] bottom = [i + 1, (i + 3) % (u * 2), len(vertices) - 1] faces.append(top) faces.append(bottom[::-1]) return vertices, faces