Exemple #1
0
def extrude_polygon(polygon, vectors=None, height=None, height_pad=[0, 0]):

    shell = np.array(polygon.exterior.coords)
    holes = [np.array(i.coords) for i in polygon.interiors]

    if vectors is None:
        pad_signed = np.sign(height) * np.array(height_pad)
        vectors = np.array([[0.0, 0.0, -pad_signed[0]],
                            [0.0, 0.0, pad_signed[1] + height]])
    else:
        vectors = np.array(vectors)

    shell_3D = three_dimensionalize(shell, False)
    shell_3D[:, 2] = vectors[0][2]

    shell_face = Face().createPolygonal(shell_3D)
    shell_solid = Solid().extrude(shell_face, *vectors)

    if holes is None: return shell_solid

    pad_vector = np.diff(vectors, axis=0)[0]
    cut_vectors = vectors + [-pad_vector, pad_vector]

    for hole in holes:
        cut_face = Face().createPolygonal(three_dimensionalize(hole, False))
        cut_solid = Solid().extrude(cut_face, *cut_vectors)
        shell_solid.cut(cut_solid)
    return shell_solid
Exemple #2
0
    def test_createFace(self):
        eq = self.assertAlmostEqual

        self.assertRaises(OCCError, Face().createFace, Wire())

        # square face
        p1 = Vertex(0., 0., 0.)
        p2 = Vertex(1., 0., 0.)
        p3 = Vertex(1., 1., 0.)
        p4 = Vertex(0., 1., 0.)
        e1 = Edge().createLine(p1, p2)
        e2 = Edge().createLine(p2, p3)
        e3 = Edge().createLine(p3, p4)
        e4 = Edge().createLine(p4, p1)

        w1 = Wire().createWire((e1, e1, e1, e1))
        self.assertRaises(OCCError, Face().createFace, w1)

        w2 = Wire().createWire((e1, e2, e3, e4))

        face = Face().createFace(w2)

        self.assertEqual(face.numWires(), 1)
        self.assertEqual(face.numFaces(), 1)
        eq(face.area(), 1.)

        # circular face
        e1 = Edge()
        center = (0., 0., 0.)
        normal = (0., 0., 1.)
        radius = 1.

        e1.createCircle(center, normal, radius)
        face = Face().createFace(e1)
        eq(face.area(), pi, places=4)
Exemple #3
0
    def test_extrude(self):
        eq = self.assertAlmostEqual

        # square face
        p1 = Vertex(0., 0., 0.)
        p2 = Vertex(1., 0., 0.)
        e1 = Edge().createLine(p1, p2)

        face = Face().extrude(e1, (0., 0., 0.), (0., 1., 0.))
        eq(face.area(), 1.)
Exemple #4
0
    def test_createPolygonal(self):
        eq = self.assertAlmostEqual

        pnts = ((0., 0., 0.), (1., 0., 0.), (1., 1., 0.), (0., 1., 0.))
        face = Face().createPolygonal(pnts)
        eq(face.area(), 1.)