{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Ray Tracing {#ray_trace_example}\n\nSingle line segment ray tracing for PolyData objects.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pyvista as pv\n\n# Create source to ray trace\nsphere = pv.Sphere(radius=0.85)\n\n# Define line segment\nstart = [0, 0, 0]\nstop = [0.25, 1, 0.5]\n\n# Perform ray trace\npoints, ind = sphere.ray_trace(start, stop)\n\n# Create geometry to represent ray trace\nray = pv.Line(start, stop)\nintersection = pv.PolyData(points)\n\n# Render the result\np = pv.Plotter()\np.add_mesh(sphere, show_edges=True, opacity=0.5, color=\"w\", lighting=False, label=\"Test Mesh\")\np.add_mesh(ray, color=\"blue\", line_width=5, label=\"Ray Segment\")\np.add_mesh(intersection, color=\"maroon\", point_size=25, label=\"Intersection Points\")\np.add_legend()\np.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}