Repository: pyvista/pyvista

Issue:
Incorrect `PolyData.ray_trace` result if intersection is the origin
### Describe the bug, what's wrong, and what you expected.

Offending line [here](https://github.com/pyvista/pyvista/blob/6d1583bb51aecea964bde64107d8b2641c1f456b/pyvista/core/filters/poly_data.py#L2172C7-L2172C7). Followup PR in a sec

### Steps to reproduce the bug.

Passes:

```python
plane = pv.Plane(i_resolution=1, j_resolution=1)
pts, cells = plane.ray_trace([0.1, 0, 1], [0.1, 0, -1])
assert len(cells) == 1 and cells[0] == 0
```

Fails:

```python
plane = pv.Plane(i_resolution=1, j_resolution=1)
pts, cells = plane.ray_trace([0, 0, 1], [0, 0, -1])
assert len(cells) == 1 and cells[0] == 0
```

### System Information

```shell
--------------------------------------------------------------------------------
  Date: Wed Dec 20 12:02:08 2023 Eastern Standard Time

                OS : Windows
            CPU(s) : 48
           Machine : AMD64
      Architecture : 64bit
               RAM : 127.9 GiB
       Environment : Jupyter
        GPU Vendor : NVIDIA Corporation
      GPU Renderer : NVIDIA GeForce RTX 2080 Ti/PCIe/SSE2
       GPU Version : 4.5.0 NVIDIA 536.23
  MathText Support : False

  Python 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:26:13) [MSC
  v.1935 64 bit (AMD64)]

           pyvista : 0.43.dev0
               vtk : 9.2.6
             numpy : 1.26.2
        matplotlib : 3.8.1
            scooby : 0.9.2
             pooch : 1.8.0
            pillow : 10.0.1
           imageio : 2.31.6
           IPython : 8.18.1
          colorcet : 3.0.1
           cmocean : 3.0.3
        ipywidgets : 8.1.1
              tqdm : 4.66.1
            meshio : 5.3.4
        jupyterlab : 4.0.9
    pytest_pyvista : 0.1.8
             trame : 3.3.0
      trame_client : 2.12.7
      trame_server : 2.12.1
         trame_vtk : 2.5.10
     trame_vuetify : 2.3.1
      nest_asyncio : 1.5.8
--------------------------------------------------------------------------------
```


### Screenshots

_No response_

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pyvista/pyvista/pull/5373?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyvista) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`3c54651`)](https://app.codecov.io/gh/pyvista/pyvista/commit/3c546511a51d351a73540eb84ce4e565aeb72e4e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyvista) 96.00% compared to head [(`ae0fd8a`)](https://app.codecov.io/gh/pyvista/pyvista/pull/5373?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyvista) 89.27%.
> Report is 15 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #5373      +/-   ##
==========================================
- Coverage   96.00%   89.27%   -6.73%     
==========================================
  Files         134      134              
  Lines       22710    22722      +12     
==========================================
- Hits        21803    20286    -1517     
- Misses        907     2436    +1529     
```

</details>

Patch:
diff --git a/pyvista/core/filters/poly_data.py b/pyvista/core/filters/poly_data.py
index 392f1a70..773c9872 100644
--- a/pyvista/core/filters/poly_data.py
+++ b/pyvista/core/filters/poly_data.py
@@ -2165,11 +2165,12 @@ class PolyDataFilters(DataSetFilters):
         self.obbTree.IntersectWithLine(np.array(origin), np.array(end_point), points, cell_ids)
 
         intersection_points = _vtk.vtk_to_numpy(points.GetData())
-        if first_point and intersection_points.shape[0] >= 1:
+        has_intersection = intersection_points.shape[0] >= 1
+        if first_point and has_intersection:
             intersection_points = intersection_points[0]
 
         intersection_cells = []
-        if intersection_points.any():
+        if has_intersection:
             if first_point:
                 ncells = 1
             else:


Test patch:
diff --git a/tests/core/test_polydata.py b/tests/core/test_polydata.py
index e8536b8e..87ae5ac9 100644
--- a/tests/core/test_polydata.py
+++ b/tests/core/test_polydata.py
@@ -286,6 +286,13 @@ def test_ray_trace(sphere):
     assert np.any(ind)
 
 
+def test_ray_trace_origin():
+    # https://github.com/pyvista/pyvista/issues/5372
+    plane = pv.Plane(i_resolution=1, j_resolution=1)
+    pts, cells = plane.ray_trace([0, 0, 1], [0, 0, -1])
+    assert len(cells) == 1 and cells[0] == 0
+
+
 def test_multi_ray_trace(sphere):
     pytest.importorskip('rtree')
     pytest.importorskip('pyembree')