示例#1
0
def constructTetrahedron(cx,cy,cz,side):
    """
    Constructs a tetrahedron mesh.

    Arguments:
    ----------
    cx, cy, cz : float
        The center point of the tetrahedron
    side : float
        The edge length of the tetrahedron
    """
    mesh = Mesh()
    coord = 1 / math.sqrt(2)
    mesh.vertices = [Vertex(+1, 0, -coord),
                     Vertex(-1, 0, -coord),
                     Vertex(0, +1, +coord),
                     Vertex(0, -1, +coord)]

    for i in range(len(mesh.vertices)):
        mesh.vertices[i] = vec.scale(mesh.vertices[i], side / 2)
        mesh.vertices[i] = vec.add(mesh.vertices[i], Vertex(cx, cy, cz))

    f1 = Face([mesh.vertices[0], mesh.vertices[1], mesh.vertices[2]])
    f2 = Face([mesh.vertices[1], mesh.vertices[0], mesh.vertices[3]])
    f3 = Face([mesh.vertices[2], mesh.vertices[3], mesh.vertices[0]])
    f4 = Face([mesh.vertices[3], mesh.vertices[2], mesh.vertices[1]])

    mesh.faces = [f1, f2, f3, f4]
    return mesh
示例#2
0
def constructBox(x1,y1,z1,x2,y2,z2):
    """
    Creates and returns a mesh box with six quad faces.

    Arguments:
    ----------
    x1,y1,z1 : float
        The coordinates of the bottom left front corner
    x2,y2,z2 : float
        The coordinates of the top right back corner
    """
    mesh = Mesh()
    v1 = Vertex(x1, y1, z1)
    v2 = Vertex(x1, y2, z1)
    v3 = Vertex(x2, y2, z1)
    v4 = Vertex(x2, y1, z1)
    v5 = Vertex(x1, y1, z2)
    v6 = Vertex(x1, y2, z2)
    v7 = Vertex(x2, y2, z2)
    v8 = Vertex(x2, y1, z2)
    mesh.vertices = [v1, v2, v3, v4, v5, v6, v7, v8]
    f1 = Face([v1, v2, v3, v4])
    f2 = Face([v8, v7, v6, v5])
    f3 = Face([v4, v3, v7, v8])
    f4 = Face([v3, v2, v6, v7])
    f5 = Face([v2, v1, v5, v6])
    f6 = Face([v1, v4, v8, v5])
    mesh.faces = [f1, f2, f3, f4, f5, f6]
    return mesh
示例#3
0
def constructSingleFace(vertices):
    """
    Creates and returns a single face mesh from the vertices.

    Arguments:
    ----------
    vertices : list of mola.core.Vertex
        The vertices describing the face
    """
    mesh = Mesh()
    mesh.vertices = vertices
    mesh.faces = [Face(vertices)]
    return mesh
示例#4
0
 def getQuadMesh(self, functionIn, functionOut):
     faces = []
     for x in range(self.nX):
         for y in range(self.nY):
             for z in range(self.nZ):
                 index = self.getIndex(x, y, z)
                 if functionIn(self.values[index]):
                     # (x,y) (x1,y) (x1,y1) (x,y1)
                     if x == self.nX - 1 or functionOut(
                             self.get_xyz(x + 1, y, z)):
                         v1 = Vertex(x + 1, y, z)
                         v2 = Vertex(x + 1, y + 1, z)
                         v3 = Vertex(x + 1, y + 1, z + 1)
                         v4 = Vertex(x + 1, y, z + 1)
                         faces.append(Face([v1, v2, v3, v4]))
                     if x == 0 or functionOut(self.get_xyz(x - 1, y, z)):
                         v1 = Vertex(x, y + 1, z)
                         v2 = Vertex(x, y, z)
                         v3 = Vertex(x, y, z + 1)
                         v4 = Vertex(x, y + 1, z + 1)
                         faces.append(Face([v1, v2, v3, v4]))
                     if y == self.nY - 1 or functionOut(
                             self.get_xyz(x, y + 1, z)):
                         v1 = Vertex(x + 1, y + 1, z)
                         v2 = Vertex(x, y + 1, z)
                         v3 = Vertex(x, y + 1, z + 1)
                         v4 = Vertex(x + 1, y + 1, z + 1)
                         faces.append(Face([v1, v2, v3, v4]))
                     if y == 0 or functionOut(self.get_xyz(x, y - 1, z)):
                         v1 = Vertex(x, y, z)
                         v2 = Vertex(x + 1, y, z)
                         v3 = Vertex(x + 1, y, z + 1)
                         v4 = Vertex(x, y, z + 1)
                         faces.append(Face([v1, v2, v3, v4]))
                     if z == self.nZ - 1 or functionOut(
                             self.get_xyz(x, y, z + 1)):
                         v1 = Vertex(x, y, z + 1)
                         v2 = Vertex(x + 1, y, z + 1)
                         v3 = Vertex(x + 1, y + 1, z + 1)
                         v4 = Vertex(x, y + 1, z + 1)
                         faces.append(Face([v1, v2, v3, v4]))
                     if z == 0 or functionOut(self.get_xyz(x, y, z - 1)):
                         v1 = Vertex(x, y + 1, z)
                         v2 = Vertex(x + 1, y + 1, z)
                         v3 = Vertex(x + 1, y, z)
                         v4 = Vertex(x, y, z)
                         faces.append(Face([v1, v2, v3, v4]))
     mesh = Mesh()
     mesh.faces = faces
     return mesh
示例#5
0
def constructIcosahedron(cx,cy,cz,radius):
    """
    Creates and returns a mesh in the form of an icosahedron.

    Arguments:
    ----------
    cx,cy,cz : float
        The coordinates of the center point
    radius : float
        The radius of the containing sphere
    """
    mesh = Mesh()
    phi = (1 + 5 ** 0.5) / 2
    coordA = 1 / (2 * math.sin(2 * math.pi / 5))
    coordB = phi / (2 * math.sin(2 * math.pi / 5))
    mesh.vertices = [Vertex(0, -coordA, coordB),
                Vertex(coordB, 0, coordA),
                Vertex(coordB, 0, -coordA),
                Vertex(-coordB, 0, -coordA),
                Vertex(-coordB, 0, coordA),
                Vertex(-coordA, coordB, 0),
                Vertex(coordA, coordB, 0),
                Vertex(coordA, -coordB, 0),
                Vertex(-coordA, -coordB, 0),
                Vertex(0, -coordA, -coordB),
                Vertex(0, coordA, -coordB),
                Vertex(0, coordA, coordB)]

    for i in range(len(mesh.vertices)):
        mesh.vertices[i] = vec.scale(mesh.vertices[i], radius)
        mesh.vertices[i] = vec.add(mesh.vertices[i], Vertex(cx,cy,cz))

    indices = [1, 2, 6, 1, 7, 2, 3, 4, 5, 4, 3, 8, 6, 5, 11, 5, 6, 10, 9, 10, 2, 10, 9, 3, 7, 8, 9, 8, 7, 0, 11, 0, 1, 0, 11, 4, 6, 2, 10, 1, 6, 11, 3, 5, 10, 5, 4, 11, 2, 7, 9, 7, 1, 0, 3, 9, 8, 4, 8, 0]
    faces = []

    for i in range(0,len(indices),3):
        f = Face([mesh.vertices[indices[i]], mesh.vertices[indices[i + 1]], mesh.vertices[indices[i + 2]]])
        faces.append(f)
    mesh.faces = faces
    return mesh