
#################
lineLineIntersect
#################

.. js:function:: common.lineLineIntersect

   .. rst-class:: sig-pretty-signature
   
      | lineLineIntersect(**p1**\ : :js:class:`Point3 <common.Point3>`\ , **p2**\ : :js:class:`Point3 <common.Point3>`\ , **p3**\ : :js:class:`Point3 <common.Point3>`\ , **p4**\ : :js:class:`Point3 <common.Point3>`\ ): (*None* | :js:class:`Point3 <common.Point3>`\ )
   
   Finds the closest point on the first line to the second line in 3D space.
   
   This function computes the point on line p1-p2 that is closest to line p3-p4. For intersecting lines, this returns the intersection point. For skew lines (non-intersecting, non-parallel lines in 3D), it returns the point on the first line that minimizes the distance to the second line.
   
   **Parameters**
   
   
      **p1**\ : :js:class:`Point3 <common.Point3>`
   
   
         First point defining the first line
   
   
      **p2**\ : :js:class:`Point3 <common.Point3>`
   
   
         Second point defining the first line
   
   
      **p3**\ : :js:class:`Point3 <common.Point3>`
   
   
         First point defining the second line
   
   
      **p4**\ : :js:class:`Point3 <common.Point3>`
   
   
         Second point defining the second line
   
   
   
   **Returns**\ : (*None* \| :js:class:`Point3 <common.Point3>`\ )
   
   
      The closest point on line p1-p2 to line p3-p4, or null if either line is degenerate or lines are parallel
   
   
   .. rubric:: Examples
   
   
   .. code-block:: typescript
   
      // Intersecting lines
      const p1 = new Point3(0, 0, 0);
      const p2 = new Point3(1, 0, 0);
      const p3 = new Point3(0.5, -1, 0);
      const p4 = new Point3(0.5, 1, 0);
      const intersection = lineLineIntersect(p1, p2, p3, p4);
      // Returns: Point3(0.5, 0, 0) - the intersection point
   
   .. code-block:: typescript
   
      // Skew lines (non-intersecting in 3D)
      const p1 = new Point3(0, 0, 0);
      const p2 = new Point3(1, 0, 0);
      const p3 = new Point3(0, 1, 1);
      const p4 = new Point3(1, 1, 1);
      const closest = lineLineIntersect(p1, p2, p3, p4);
      // Returns: Point3 representing the closest point on line p1-p2 to line p3-p4
   
   .. code-block:: typescript
   
      // Parallel lines
      const p1 = new Point3(0, 0, 0);
      const p2 = new Point3(1, 0, 0);
      const p3 = new Point3(0, 1, 0);
      const p4 = new Point3(1, 1, 0);
      const result = lineLineIntersect(p1, p2, p3, p4);
      // Returns: null (parallel lines have no unique closest point)
   
   .. rubric:: Remarks
   
   
   
   - Algorithm based on Paul Bourke's line-line intersection method
   - Uses a small epsilon (1e-12) for numerical stability
   - Returns null for degenerate cases:
   
   - Either line has zero length (p1 == p2 or p3 == p4)
   - Lines are parallel (cross product of direction vectors is zero)
   
   - For non-parallel lines, always returns a valid Point3
   - The returned point always lies on the infinite extension of line p1-p2
   - For truly intersecting lines, the distance between the returned point and line p3-p4 will be approximately zero
   - For skew lines, the returned point minimizes the 3D distance to line p3-p4
   
   .. rubric:: See Also
   
   
   
   - `http://paulbourke.net/geometry/pointlineplane/lineline.c <http://paulbourke.net/geometry/pointlineplane/lineline.c>`__ - Original algorithm reference
   - :js:func:`distanceLineLine <common.distanceLineLine>` - For computing distance between line segments with clamping
   




