def intersection(axis, coord, triangle):
    """
    Returns the intersection (if one exists) between a *triangle*
    and the plane based on the *axis* and *coord*. 
    Also returns a boolean indicating whether or not an
    intersection was found.
    """
    #create an array for the coordinates
    triangle_verts=np.array([], ndmin=3)
    triangle_verts.shape =(0, 3, 3)

    verts = mesh.getEntAdj(triangle, iBase.Type.vertex)
    vert1 = mesh.getVtxCoords(verts[0])
    vert2 = mesh.getVtxCoords(verts[1])
    vert3 = mesh.getVtxCoords(verts[2])

    temp = np.vstack( (vert1, vert2, vert3) )
    #insert the coordinates into the array
    triangle_verts = np.append(triangle_verts, [temp], axis = 0)

    #check for an intersection                                                                                                                                                   
    line = triangle_plane_intersect(axis, coord, triangle_verts)

    #if a line is returned, indicate that we have an intersection
    intersect = True if line.size is not 0 else False

    return intersect, line
Esempio n. 2
0
def test_perfect_element_intersection():
    # This test tests mesh line annotation where a z=0 slice
    # perfectly intersects the top of a hexahedral element with node
    # z-coordinates containing both -0 and +0. Before
    # https://github.com/yt-project/yt/pull/1437 this test falsely
    # yielded three annotation lines, whereas the correct result is four
    # corresponding to the four edges of the top hex face.

    ds = small_fake_hexahedral_ds()
    indices = ds.index.meshes[0].connectivity_indices
    coords = ds.index.meshes[0].connectivity_coords
    tri_indices = triangulate_indices(indices)
    tri_coords = coords[tri_indices]
    lines = triangle_plane_intersect(2, 0, tri_coords)
    non_zero_lines = 0
    for i in range(lines.shape[0]):
        norm = np.linalg.norm(lines[i][0] - lines[i][1])
        if norm > 1e-8:
            non_zero_lines += 1
    np.testing.assert_equal(non_zero_lines, 4)
Esempio n. 3
0
    def __call__(self, plot):
        plot._axes.hold(True)
        ax = plot.data.axis
        xax = plot.data.ds.coordinates.x_axis[ax]
        yax = plot.data.ds.coordinates.y_axis[ax]

        if not hasattr(self.vertices, "in_units"):
            vertices = plot.data.pf.arr(self.vertices, "code_length")
        else:
            vertices = self.vertices
        l_cy = triangle_plane_intersect(plot.data.axis, plot.data.coord,
                                        vertices)[:, :, (xax, yax)]
        # reformat for conversion to plot coordinates
        l_cy = np.rollaxis(l_cy, 0, 3)
        # convert all line starting points
        l_cy[0] = self.convert_to_plot(plot, l_cy[0])
        l_cy[1] = self.convert_to_plot(plot, l_cy[1])
        # convert all line ending points
        l_cy = np.rollaxis(l_cy, 2, 0)
        # create line collection and add it to the plot
        lc = matplotlib.collections.LineCollection(l_cy, **self.plot_args)
        plot._axes.add_collection(lc)
        plot._axes.hold(False)