Beispiel #1
0
def test_order_points():
    polygon = Polygon3D([(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)])
    starting_position = 'upperleftcorner'
    expected = Polygon3D([(1, 1, 1), (1, 0, 0), (0, 0, 0), (0, 1, 1)])
    result = polygon.order_points(starting_position)
    assert result == expected
    assert result[0] == expected[0]

    starting_position = 'lowerleftcorner'
    expected = Polygon3D([(1, 0, 0), (0, 0, 0), (0, 1, 1), (1, 1, 1)])
    result = polygon.order_points(starting_position)
    assert result == expected
    assert result[0] == expected[0]

    starting_position = 'lowerrightcorner'
    expected = Polygon3D([(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)])
    result = polygon.order_points(starting_position)
    assert result == expected
    assert result[0] == expected[0]

    starting_position = 'upperrightcorner'
    expected = Polygon3D([(0, 1, 1), (1, 1, 1), (1, 0, 0), (0, 0, 0)])
    result = polygon.order_points(starting_position)
    assert result == expected
    assert result[0] == expected[0]
Beispiel #2
0
def test_intersect_no_overlap():
    # surfaces don't overlap
    s1 = Polygon3D([(0, 2, 0), (2, 2, 0), (2, 0, 0), (0, 0, 0)])  # clockwise
    s2 = Polygon3D([(2, 3, 0), (3, 3, 0), (3, 1, 0), (2, 1, 0)])  # clockwise
    expected = []  #clockwise
    result = intersect_3D_polys(s1, s2)
    assert result == expected
Beispiel #3
0
def test_difference_3D_polys_single():
    """Simplest test for difference_3D_polys
    
    This has two squares in the horizontal plane which overlap in one place.
    Fails if the two original polygons do not have the intersection removed.
    
    """
    # surface is already a flat plane with z == 0
    s1 = Polygon3D([(0, 2, 0), (2, 2, 0), (2, 0, 0), (0, 0, 0)])  # clockwise
    s2 = Polygon3D([(1, 3, 0), (3, 3, 0), (3, 1, 0), (1, 1, 0)])  # clockwise

    # clockwise
    ex_s1 = [
        Polygon3D([(0, 2, 0), (1, 2, 0), (1, 1, 0), (2, 1, 0), (2, 0, 0),
                   (0, 0, 0)])
    ]
    ex_s2 = [
        Polygon3D([(1, 3, 0), (3, 3, 0), (3, 1, 0), (2, 1, 0), (2, 2, 0),
                   (1, 2, 0)])
    ]
    expected = [ex_s1, ex_s2]

    result = [difference_3D_polys(s1, s2), difference_3D_polys(s2, s1)]
    assert result[0] == expected[0]
    assert result[1] == expected[1]
Beispiel #4
0
def test_difference_3D_polys_multi():
    """Test for difference_3D_polys with two overlapping regions
    
    This has two shapes in the horizontal plane which overlap in two places.
    Fails if the overlapping shapes are not returned as a new polygons.

    """
    # surface is already a flat plane with z == 0
    s1 = Polygon3D([(0, 0, 0), (5, 0, 0), (5, 2, 0),
                    (0, 2, 0)])  # counterclockwise
    s2 = Polygon3D([(1, 1, 0), (2, 1, 0), (2, 2, 0), (3, 2, 0), (3, 1, 0),
                    (4, 1, 0), (4, 3, 0), (1, 3, 0)])  # counterclockwise

    ex_s1 = [
        Polygon3D([(0, 0, 0), (5, 0, 0), (5, 2, 0), (4, 2, 0), (4, 1, 0),
                   (3, 1, 0), (3, 2, 0), (2, 2, 0), (2, 1, 0), (1, 1, 0),
                   (1, 2, 0), (0, 2, 0)])
    ]
    ex_s2 = [Polygon3D([(1, 2, 0), (4, 2, 0), (4, 3, 0), (1, 3, 0)])]

    expected = [ex_s1, ex_s2]
    result = [difference_3D_polys(s1, s2), difference_3D_polys(s2, s1)]

    for res, exp in zip(result, expected):
        assert len(res) == len(exp)
        for r, e in zip(res, exp):
            assert r == e

    assert s1.difference(s2) == ex_s1
    assert s2.difference(s1) == ex_s2
Beispiel #5
0
    def test_align_face_transformations_trapezoid_floor(self):
        tol = 12  # places

        testVertices = Polygon3D([(27.69, 0, 0), (0, 0, 0), (5, 5, 0),
                                  (22.69, 5, 0)])
        t = Transformation().align_face(testVertices)
        tempVertices = t.inverse() * testVertices
        expectedVertices = Polygon3D([(0, 0, 0), (27.69, 0, 0), (22.69, 5, 0),
                                      (5, 5, 0)])
        assert almostequal(tempVertices, expectedVertices, tol)
Beispiel #6
0
def test_break_polygons():
    poly = Polygon3D([(0, 4, 0), (0, 0, 0), (4, 0, 0), (4, 4, 0)])
    hole = Polygon3D([(1, 3, 0), (1.5, 2, 0), (1, 1, 0), (3, 1, 0), (3, 3, 0)])
    expected = [
        Polygon3D([(0, 4, 0), (0, 0, 0), (1, 1, 0), (1.5, 2, 0), (1, 3, 0)]),
        Polygon3D([(4, 4, 0), (0, 4, 0), (1, 3, 0), (3, 3, 0), (3, 1, 0),
                   (1, 1, 0), (0, 0, 0), (4, 0, 0)])
    ]

    result = break_polygons(poly, hole)

    assert result[0] == expected[0]
    assert result[1] == expected[1]
Beispiel #7
0
def test_intersect_3D_polys_angled():
    s1 = Polygon3D([(2.5, 1.95, 0.5), (2.5, 1.95, 0), (1.5, 2.05, 0),
                    (1.5, 2.05, 0.5)])  # clockwise
    s2 = Polygon3D([(1, 2.1, 0.5), (1, 2.1, 0), (2, 2, 0),
                    (2, 2, 0.5)])  # clockwise
    expected = [
        Polygon3D([(2.0, 2.0, 0.0), (1.5, 2.05, 0.0), (1.5, 2.05, 0.5),
                   (2.0, 2.0, 0.5)])
    ]

    result = intersect_3D_polys(s1, s2)

    assert result == expected
Beispiel #8
0
    def test_translate_to_origin(self):
        idf = self.idf
        surfaces = getidfsurfaces(idf)
        translate(surfaces, (50000, 10000))  # move to x + 50, y + 100
        result = Polygon3D(surfaces[0].coords).xs
        expected = [50002.0, 50002.0, 50001.0, 50001.0]
        assert result == expected

        translate_to_origin(idf)
        surfaces = getidfsurfaces(idf)
        min_x = min(min(Polygon3D(s.coords).xs) for s in surfaces)
        min_y = min(min(Polygon3D(s.coords).ys) for s in surfaces)
        assert min_x == 0
        assert min_y == 0
Beispiel #9
0
def test_polygons_not_equal():
    """Test the check for equality between polygons.
    """
    # different normal vector
    poly3d = Polygon3D([(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)])
    poly3d_2 = Polygon3D([(0, 0, 2), (0, 1, 2), (1, 1, 2), (1, 0, 2)])
    assert poly3d.normal_vector != poly3d_2.normal_vector
    assert poly3d != poly3d_2
    # different distance
    poly3d = Polygon3D([(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)])
    poly3d_2 = Polygon3D([(0, 1, 2), (0, 2, 3), (1, 2, 3), (1, 1, 2)])
    assert poly3d.normal_vector == poly3d_2.normal_vector
    assert poly3d.distance != poly3d_2.distance
    assert poly3d != poly3d_2
Beispiel #10
0
def test_intersect_3D_polys_single():
    """Simplest test for intersect_3D_polys
    
    This has two squares in the horizontal plane which overlap in one place.
    Fails if the expected overlapping shape is not returned.
    
    """
    # surface is already a flat plane with z == 0
    s1 = Polygon3D([(0, 2, 0), (2, 2, 0), (2, 0, 0), (0, 0, 0)])  # clockwise
    s2 = Polygon3D([(1, 3, 0), (3, 3, 0), (3, 1, 0), (1, 1, 0)])  # clockwise
    expected = [Polygon3D([(1, 2, 0), (2, 2, 0), (2, 1, 0),
                           (1, 1, 0)])]  #clockwise
    result = intersect_3D_polys(s1, s2)
    for res, exp in zip(result, expected):
        assert res == exp
Beispiel #11
0
def test_difference_no_difference():
    # surfaces don't overlap
    s1 = Polygon3D([(0, 2, 0), (2, 2, 0), (2, 0, 0), (0, 0, 0)])  # clockwise
    s2 = s1
    expected = []  #clockwise
    result = difference_3D_polys(s1, s2)
    assert result == expected
Beispiel #12
0
def set_unmatched_surface(s, vector):
    """Set boundary conditions for a surface which does not adjoin another one.
    
    Parameters
    ----------
    s : EpBunch
        The surface.
    vector : Vector3D
        The surface normal vector
        
    """
    s.View_Factor_to_Ground = 'autocalculate'
    poly = Polygon3D(s.coords)
    if min(poly.zs) < 0 or all(z == 0 for z in poly.zs):
        # below ground or ground-adjacent surfaces
        s.Outside_Boundary_Condition_Object = ''
        s.Outside_Boundary_Condition = 'ground'
        s.Sun_Exposure = 'NoSun'
        s.Wind_Exposure = 'NoWind'
    else:
        s.Outside_Boundary_Condition = 'outdoors'
        s.Outside_Boundary_Condition_Object = ''
        s.Wind_Exposure = 'WindExposed'
        if almostequal(vector, (0, 0, -1)):
            # downward facing surfaces
            s.Sun_Exposure = 'NoSun'
        else:
            s.Sun_Exposure = 'SunExposed'  # other external surfaces
Beispiel #13
0
def window_vertices_given_wall(wall, wwr):
    """Calculate window vertices given wall vertices and glazing ratio.
    
    For each axis:
    1) Translate the axis points so that they are centred around zero
    2) Either:
        a) Multiply the z dimension by the glazing ratio to shrink it vertically
        b) Multiply the x or y dimension by 0.995 to keep inside the surface
    3) Translate the axis points back to their original positions
    
    Parameters
    ----------
    wall : EpBunch
        The wall to add a window on. We expect each wall to have four vertices.
    wwr : float
        Window to wall ratio.
    
    Returns
    -------
    list 
        Window vertices bounding a vertical strip midway up the surface.
    
    """
    vertices = wall.coords
    average_x = sum([x for x, _y, _z in vertices]) / len(vertices)
    average_y = sum([y for _x, y, _z in vertices]) / len(vertices)
    average_z = sum([z for _x, _y, z in vertices]) / len(vertices)
    # move windows in 0.5% from the edges so they can be drawn in SketchUp
    window_points = [[((x - average_x) * 0.999) + average_x,
                      ((y - average_y) * 0.999) + average_y,
                      ((z - average_z) * wwr) + average_z]
                     for x, y, z in vertices]

    return Polygon3D(window_points)
Beispiel #14
0
def test_polygon3d_attributes():
    poly3d = Polygon3D([(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)])
    assert len(poly3d) == 4
    assert poly3d.xs == [0, 0, 1, 1]
    assert poly3d.ys == [0, 1, 1, 0]
    assert poly3d.zs == [0, 1, 1, 0]
    assert poly3d.vertices_list == [(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)]
    assert poly3d.vertices == [Vector3D(*v) for v in poly3d]
    assert poly3d.distance == 0
    assert poly3d.is_horizontal == False
    assert poly3d.normal_vector == [0.0, 0.5, -0.5]
    poly3d_2 = Polygon3D([(0, 1, 1), (0, 2, 2), (1, 2, 2), (1, 1, 1)])
    assert poly3d_2.normal_vector == [0.0, 0.5, -0.5]
    assert poly3d_2.projection_axis == 1
    result = poly3d.is_coplanar(poly3d_2)
    assert result
Beispiel #15
0
def getidfplanes(surfaces):
    """Fast access data structure for potentially matched surfaces.
    
    Get a data structure populated with all the surfaces in the IDF, keyed by
    their distance from the origin, and their normal vector.
    
    Parameters
    ----------
    surfaces : list
        List of all the surfaces.
    
    Returns
    -------
    dict
        
    """
    planes = {}
    for s in surfaces:
        poly = Polygon3D(s.coords)
        rounded_distance = round(poly.distance, 8)
        rounded_normal_vector = Vector3D(
            *[round(axis, 8) for axis in poly.normal_vector])
        planes.setdefault(rounded_distance,
                          {}).setdefault(rounded_normal_vector, []).append(s)
    return planes
Beispiel #16
0
def test_identify_inner_ring_polygons():
    geom = [(
        u'POLYGON((528318.562 186087.89,528307.65 186095.1,528303.1 186088.15,528305.59 186086.5,528299.67 186077.17,528300.85 186075.56,528295.35 186071.9,528294.401 186072.514,528292.8 186073.55,528285.8 186069.2,528286 186066.5,528286.45 186065.85,528285.854 186065.438,528277.752 186059.839,528275.54 186058.31,528273.93 186066.89,528273.76 186067.81,528273.45 186069.42,528269.73 186068.72,528267.91 186078.41,528242.51 186073.65,528242.78 186072.209,528243.49 186068.42,528252.68 186058.13,528255.36 186043.87,528261.22 186044.97,528266.75 186016.45,528269.25 186016.95,528271 186017.3,528271.2 186016.25,528277.85 186017.5,528277.25 186020.4,528300.75 186024.85,528301 186023.65,528307.8 186024.95,528307.7 186025.6,528311.5 186028.5,528310.85 186029.4,528316.7 186033.3,528320.15 186035.55,528320.7 186034.95,528324.15 186037.25,528325 186036.95,528328.75 186042.7,528327.85 186043.3,528340.6 186063.2,528342.65 186061.8,528347.25 186068.8,528347.3 186068.9,528318.562 186087.89),(528306.281 186071.421,528312.36 186075.46,528314.06 186078.02,528314.7 186077.6,528315.98 186076.78,528311.35 186069.56,528320.79 186063.52,528317.54 186058.45,528318.74 186057.68,528315.04 186051.9,528318.42 186049.74,528317.5 186048.31,528319.21 186047.21,528317.9 186045.2,528316.6 186043.15,528302.35 186063.6,528304.4 186065.05,528301.99 186068.57,528306.281 186071.421),(528294.9 186046.92,528296.47 186044.6,528299.04 186040.78,528298.55 186040.45,528290.62 186038.77,528289.3 186038.48,528288.33 186043.03,528289.65 186043.28,528287.66 186052.57,528285.16 186052.04,528284.85 186053.5,528284.1 186054.8,528286.79 186056.63,528287.12 186056.86,528286.6 186057.65,528287.3 186058.14,528289.45 186055,528291.3 186056.25,528296.85 186048.23,528294.9 186046.92),(528274.89 186044.69,528277.99 186045.28,528276.9 186051.08,528276.98 186051.1,528278.3 186052,528280.4 186053.44,528280.72 186052.98,528281.04 186051.33,528278.53 186050.86,528280.42 186041.51,528282.23 186041.86,528283.17 186037.18,528276.65 186035.8,528274.89 186044.69))',
        7.7)]

    for item in geom:
        poly = Polygon3D([]).from_wkt(item[0])
Beispiel #17
0
def test_surface_normal():
    poly = Polygon3D([
        Vector3D(0.0, 0.0, 0.0),
        Vector3D(1.0, 0.0, 0.0),
        Vector3D(1.0, 1.0, 0.0),
        Vector3D(0.0, 1.0, 0.0)
    ])
    assert list(poly.normal_vector) == [0.0, 0.0,
                                        1.0]  # for a horizontal surface

    poly = Polygon3D(
        reversed([
            Vector3D(0.0, 0.0, 0.0),
            Vector3D(1.0, 0.0, 0.0),
            Vector3D(1.0, 1.0, 0.0),
            Vector3D(0.0, 1.0, 0.0)
        ]))
    assert list(poly.normal_vector) == [0.0, 0.0,
                                        -1.0]  # for a horizontal surface

    poly = Polygon3D([
        Vector3D(0.0, 0.0, 0.0),
        Vector3D(2.0, 1.0, 0.0),
        Vector3D(4.0, 0.0, 0.0),
        Vector3D(4.0, 3.0, 0.0),
        Vector3D(2.0, 2.0, 0.0),
        Vector3D(0.0, 3.0, 0.0)
    ])
    assert list(poly.normal_vector) == [0.0, 0.0,
                                        1.0]  # for a horizontal surface

    poly = Polygon3D(
        reversed([
            Vector3D(0.0, 0.0, 0.0),
            Vector3D(2.0, 1.0, 0.0),
            Vector3D(4.0, 0.0, 0.0),
            Vector3D(4.0, 3.0, 0.0),
            Vector3D(2.0, 2.0, 0.0),
            Vector3D(0.0, 3.0, 0.0)
        ]))
    assert list(poly.normal_vector) == [0.0, 0.0,
                                        -1.0]  # for a horizontal surface

    poly = Polygon3D([[1., 1.1, 0.5], [1., 1.1, 0.], [1., 2.1, 0.],
                      [1., 2.1, 0.5]])
    assert list(poly.normal_vector) == [1.0, 0.0,
                                        0.0]  # for a horizontal surface
Beispiel #18
0
def translate_to_origin(idf):
    """
    Move an IDF close to the origin so that it can be viewed in SketchUp.
    
    Parameters
    ----------
    idf : IDF object
    
    """
    surfaces = getidfsurfaces(idf)
    windows = idf.idfobjects['FENESTRATIONSURFACE:DETAILED']

    min_x = min(min(Polygon3D(s.coords).xs) for s in surfaces)
    min_y = min(min(Polygon3D(s.coords).ys) for s in surfaces)

    translate(surfaces, (-min_x, -min_y))
    translate(windows, (-min_x, -min_y))
Beispiel #19
0
def test_bounding_box():
    poly = Polygon([(0, 0), (0, 1), (1, 1), (1, 0)])
    poly3d = Polygon3D([(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)])

    expected = Polygon([(1, 1, 1), (1, 0, 0), (0, 0, 0), (0, 1, 1)])

    result = poly3d.bounding_box
    assert almostequal(result, expected)
Beispiel #20
0
    def test_translate(self):
        idf = self.idf
        surfaces = getidfsurfaces(idf)
        translate(surfaces, (50, 100))  # move to x + 50, y + 100
        result = Polygon3D(surfaces[0].coords).xs
        expected = [52.0, 52.0, 51.0, 51.0]
        assert result == expected
        translate(surfaces, (-50, -100))  # move back

        translate(surfaces, Vector2D(50, 100))  # move to x + 50, y + 100
        result = Polygon3D(surfaces[0].coords).xs
        expected = [52.0, 52.0, 51.0, 51.0]
        assert result == expected
        translate(surfaces, (-50, -100))  # move back

        translate(surfaces, Vector3D(50, 100, 0))  # move to x + 50, y + 100
        result = Polygon3D(surfaces[0].coords).xs
        expected = [52.0, 52.0, 51.0, 51.0]
        assert result == expected
Beispiel #21
0
def match_idf_surfaces(idf):
    """Match all surfaces in an IDF.
    
    Parameters
    ----------
    idf : IDF object
        The IDF.
    
    """
    surfaces = getidfsurfaces(idf)
    planes = getidfplanes(surfaces)
    for distance in planes:
        for vector in planes[distance]:
            surfaces = planes[distance][vector]
            matches = planes.get(-distance, {}).get(-vector, [])
            if not matches:
                # default set all the surfaces boundary conditions
                for s in surfaces:
                    set_unmatched_surface(s, vector)
            else:
                # check which are matches
                for s in surfaces:
                    for m in matches:
                        matched = False
                        poly1 = Polygon3D(s.coords)
                        poly2 = Polygon3D(m.coords)
                        if almostequal(poly1, poly2.invert_orientation()):
                            matched = True
                            # matched surfaces
                            s.Outside_Boundary_Condition = 'surface'
                            s.Outside_Boundary_Condition_Object = m.Name
                            s.Sun_Exposure = 'NoSun'
                            s.Wind_Exposure = 'NoWind'
                            # matched surfaces
                            m.Outside_Boundary_Condition = 'surface'
                            m.Outside_Boundary_Condition_Object = s.Name
                            m.Sun_Exposure = 'NoSun'
                            m.Wind_Exposure = 'NoWind'
                            break
                    if not matched:
                        # unmatched surfaces
                        set_unmatched_surface(s, vector)
                        set_unmatched_surface(m, vector)
Beispiel #22
0
def test_reflect():
    """
    Test that a polygon with inverted orientation is seen as coplanar with the
    original polygon, but not seen as equal.
    
    """
    poly3d = Polygon3D([(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)])
    poly3d_inv = poly3d.invert_orientation()
    assert poly3d != poly3d_inv
    assert poly3d.is_coplanar(poly3d_inv)
Beispiel #23
0
 def footprint(self):
     """Ground level outline of the block.
     
     Returns
     -------
     Polygon3D
     
     """
     coordinates = [(v[0], v[1], 0) for v in self.coordinates]
     return Polygon3D(coordinates)
Beispiel #24
0
def test_surface_is_clockwise():
    """Test if a surface is clockwise as seen from a given point.
    """
    poly = Polygon3D(
        reversed([
            Vector3D(0.0, 0.0, 0.0),
            Vector3D(1.0, 0.0, 0.0),
            Vector3D(1.0, 1.0, 0.0),
            Vector3D(0.0, 1.0, 0.0)
        ]))
    poly_inv = Polygon3D([
        Vector3D(0.0, 0.0, 0.0),
        Vector3D(1.0, 0.0, 0.0),
        Vector3D(1.0, 1.0, 0.0),
        Vector3D(0.0, 1.0, 0.0)
    ])

    pt = Vector3D(0.5, 0.5, 1.0)  # point above the plane

    assert poly.is_clockwise(pt)
    assert not poly_inv.is_clockwise(pt)
Beispiel #25
0
def populate_adjacencies(adjacencies, s1, s2):
    """Update the adjacencies dict with any intersections between two surfaces.
    
    Parameters
    ----------
    adjacencies : dict
        Dict to contain lists of adjacent surfaces.
    s1 : EPBunch
        Object representing an EnergyPlus surface.
    s2 : EPBunch
        Object representing an EnergyPlus surface.
    
    Returns
    -------
    dict
    
    """
    poly1 = Polygon3D(s1.coords)
    poly2 = Polygon3D(s2.coords)
    if not almostequal(abs(poly1.distance), abs(poly2.distance), 4):
        return adjacencies
    if not almostequal(poly1.normal_vector, poly2.normal_vector, 4):
        if not almostequal(poly1.normal_vector, -poly2.normal_vector, 4):
            return adjacencies

    intersection = poly1.intersect(poly2)
    if intersection:
        new_surfaces = intersect(poly1, poly2)
        new_s1 = [
            s for s in new_surfaces
            if almostequal(s.normal_vector, poly1.normal_vector, 4)
        ]
        new_s2 = [
            s for s in new_surfaces
            if almostequal(s.normal_vector, poly2.normal_vector, 4)
        ]
        adjacencies[(s1.key, s1.Name)] += new_s1
        adjacencies[(s2.key, s2.Name)] += new_s2
    return adjacencies
Beispiel #26
0
def test_rotate():
    """Test for rotating 3D polygons into 2D and back again
    """
    # At the origin
    s1 = Polygon3D([(0, 0, 2), (2, 0, 2), (0, 0, 0)])  # vertical
    expected = Polygon([(0, 2), (2, 2), (0, 0)])
    # convert to 2D
    result = s1.project_to_2D()
    assert result == expected

    # revert to 3D
    result = result.project_to_3D(s1)
    assert result == s1

    # Away from the origin
    s1 = Polygon3D([(1, 0, 2), (3, 0, 2), (1, 0, 0)])  # vertical
    expected = Polygon([(1, 2), (3, 2), (1, 0)])
    # convert to 2D
    result = s1.project_to_2D()

    assert result == expected

    # revert to 3D
    result = result.project_to_3D(s1)
    assert result == s1

    # Away from the origin
    s1 = Polygon3D([(0, 1, 1), (2, 2, 0), (2, 2, 2), (0, 1, 2)])  # vertical
    expected = Polygon([(0.0, 1.0), (2.0, 0.0), (2.0, 2.0), (0.0, 2.0)])

    # convert to 2D
    result = s1.project_to_2D()
    assert result == expected

    # revert to 3D
    result = result.project_to_3D(s1)
    assert result == s1
Beispiel #27
0
def set_coords(surface, coords, ggr):
    """Update the coordinates of a surface.
      
    Parameters
    ----------
    surface : EPBunch
        The surface to modify.
    coords : list
        The new coordinates as lists of [x,y,z] lists.
    ggr : EpBunch
        Global geometry rules.

    """
    poly = Polygon3D(coords)
    poly = poly.normalize_coords(ggr)
    coords = [i for vertex in poly for i in vertex]
    # find the vertex fields
    n_vertices_index = surface.objls.index('Number_of_Vertices')
    first_x = n_vertices_index + 1  # X of first coordinate
    surface.obj = surface.obj[:first_x]
    # set the vertex field values
    surface.fieldvalues.extend(coords)
Beispiel #28
0
def test_intersect_3D_polys_multi():
    """Test for intersect_3D_polys with two overlapping regions
    
    This has two shapes in the horizontal plane which overlap in two places.
    Fails if the overlapping shapes are not returned as a new polygons.

    """
    # surface is already a flat plane with z == 0
    s1 = Polygon3D([(0, 0, 0), (5, 0, 0), (5, 2, 0),
                    (0, 2, 0)])  # counterclockwise
    s2 = Polygon3D([(1, 1, 0), (2, 1, 0), (2, 2, 0), (3, 2, 0), (3, 1, 0),
                    (4, 1, 0), (4, 3, 0), (1, 3, 0)])  # counterclockwise
    overlap = [
        Polygon3D([(1, 1, 0), (2, 1, 0), (2, 2, 0), (1, 2, 0)]),
        Polygon3D([(3, 1, 0), (4, 1, 0), (4, 2, 0), (3, 2, 0)])
    ]

    ex_s1 = Polygon3D([(0, 0, 0), (5, 0, 0), (5, 2, 0), (4, 2, 0), (4, 1, 0),
                       (3, 1, 0), (3, 2, 0), (2, 2, 0), (2, 1, 0), (1, 1, 0),
                       (1, 2, 0), (0, 2, 0)])
    ex_s2 = Polygon3D([(1, 2, 0), (4, 2, 0), (4, 3, 0), (1, 3, 0)])

    expected = [ex_s1, ex_s2]
    expected.extend(overlap)
    result = intersect_3D_polys(s1, s2)

    for res, exp in zip(result, overlap):
        assert res == exp

    result = s1.intersect(s2)
    for res, exp in zip(result, overlap):
        assert res == exp

    result = s2.intersect(s1)
    for res, exp in zip(result, overlap):
        assert res == exp
Beispiel #29
0
    def test_align_face_transformations(self):
        tol = 12  # places

        vertices = Polygon3D([(1, 0, 1), (1, 0, 0), (2, 0, 0), (2, 0, 1)])
        t = Transformation()

        # rotate 0 degrees about z
        testVertices = t.rotation(Vector3D(0, 0, 1), 0) * vertices
        t = Transformation().align_face(testVertices)
        tempVertices = t.inverse() * testVertices
        expectedVertices = Polygon3D([(0, 1, 0), (0, 0, 0), (1, 0, 0),
                                      (1, 1, 0)])
        assert almostequal(tempVertices, expectedVertices, tol)

        # rotate 30 degrees about z
        testVertices = t.rotation(Vector3D(0, 0, 1), np.deg2rad(30)) * vertices
        t = Transformation().align_face(testVertices)
        tempVertices = t.inverse() * testVertices
        expectedVertices = Polygon3D([(0, 1, 0), (0, 0, 0), (1, 0, 0),
                                      (1, 1, 0)])
        assert almostequal(tempVertices, expectedVertices, tol)

        # rotate -30 degrees about z
        testVertices = t.rotation(Vector3D(0, 0, 1),
                                  -np.deg2rad(30)) * vertices
        t = Transformation().align_face(testVertices)
        tempVertices = t.inverse() * testVertices
        expectedVertices = Polygon3D([(0, 1, 0), (0, 0, 0), (1, 0, 0),
                                      (1, 1, 0)])
        assert almostequal(tempVertices, expectedVertices, tol)

        # rotate -30 degrees about x
        testVertices = t.rotation(Vector3D(1, 0, 0),
                                  -np.deg2rad(30)) * vertices
        t = Transformation().align_face(testVertices)
        tempVertices = t.inverse() * testVertices
        expectedVertices = Polygon3D([(0, 1, 0), (0, 0, 0), (1, 0, 0),
                                      (1, 1, 0)])
        assert almostequal(tempVertices, expectedVertices, tol)

        # rotate -90 degrees about x
        testVertices = t.rotation(Vector3D(1, 0, 0),
                                  -np.deg2rad(90)) * vertices
        t = Transformation().align_face(testVertices)
        tempVertices = t.inverse() * testVertices
        expectedVertices = Polygon3D([(1, 0, 0), (1, 1, 0), (0, 1, 0),
                                      (0, 0, 0)])
        assert almostequal(tempVertices, expectedVertices, tol)

        # rotate 30 degrees about x
        testVertices = t.rotation(Vector3D(1, 0, 0), np.deg2rad(30)) * vertices
        t = Transformation().align_face(testVertices)
        tempVertices = t.inverse() * testVertices
        expectedVertices = Polygon3D([(0, 1, 0), (0, 0, 0), (1, 0, 0),
                                      (1, 1, 0)])
        assert almostequal(tempVertices, expectedVertices, tol)

        # rotate 90 degrees about x
        testVertices = t.rotation(Vector3D(1, 0, 0), np.deg2rad(90)) * vertices
        t = Transformation().align_face(testVertices)
        tempVertices = t.inverse() * testVertices
        expectedVertices = Polygon3D([(1, 0, 0), (1, 1, 0), (0, 1, 0),
                                      (0, 0, 0)])
        assert almostequal(tempVertices, expectedVertices, tol)
Beispiel #30
0
def make_wall(edge, fh, ch):
    return Polygon3D([edge.p1 + (0,0,ch),  # upper left
                      edge.p1 + (0,0,fh),  # lower left
                      edge.p2 + (0,0,fh),  # lower right
                      edge.p2 + (0,0,ch),  # upper right
                      ])