# Examples from pyvista.DataSet.intersect_with_line
# =================================================

# Intersect a line with a surface mesh.
import pyvista as pv
mesh = pv.Sphere()
points, cell_ids = mesh.intersect_with_line([0.0, 0, 0], [1.0, 0, 0])
points

cell_ids

# Observe that two identical points are returned since two adjacent cells were intersected.
# Use `deduplicate_points` to return unique intersection points only.
points, cell_ids = mesh.intersect_with_line(
    [0.0, 0, 0], [1.0, 0, 0], deduplicate_points=True
)
points

cell_ids

# Intersect a line with a 3D cell. Here we create a single
# `HEXAHEDRON` from `ImageData`.
mesh = pv.ImageData(dimensions=(2, 2, 2)).to_hexahedra()

# Intersecting the cell returns a single intersection point where the line first "hits" the
# cell.
pointa, pointb = (-1.0, 0.5, 0.5), (1.0, 0.5, 0.5)
mesh.intersect_with_line(pointa, pointb)

# Reversing the point order returns a different intersection point on the opposide side
# of the cell.
mesh.intersect_with_line(pointb, pointa)

# Converting the cell to a surface mesh will yield both intersections since each face
# is now a separate cell.
mesh.extract_surface(algorithm=None).intersect_with_line(pointa, pointb)

# An intersection is still found if the line coincides with one of the cell's edges.
mesh.intersect_with_line((0, 0, 0), (1, 0, 0))

# Similarly, intersections are found when the line is coincident with planar cells.
mesh = pv.Plane(i_resolution=2, j_resolution=2)
mesh.intersect_with_line((0, 0, 0), (1, 0, 0))

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code

