# Two line Segments Calculator

Example : for a line segment with endpoints (1,2) and (6,0), input : 1 2 6 0 (separator : blank).

Notations :

- S_{1} and S_{2} : two line segments of a cartesian plane

- Segment S_{1} passing through points of coordinates (a_{1} , b_{1}) and (c_{1} , d_{1}).

- Segment S_{2} passing through points of coordinates (a_{2} , b_{2}) and (c_{2} , d_{2}).

## Line segment Slope

Line segment slope formula is identical to the one that applies to the line passing through segment endpoints.

Slope calculator : Line Calculator

m_{1} : S_{1} slope

m_{2} : S_{2} slope

`m_1 = (d_1-b_1) / (c_1-a_1)`

`m_2 = (d_2-b_2) / (c_2-a_2)`

## Determine if two segments are parallel

Two segments are parallel if and only if one of the following conditions holds :

- segments are vertical (e.g. are both parrallel to y-axis)

- segments have the same slope, `m_1 = m_2`

## Determine if two segments are perpendicular

Two segments are perpendicular if and only if one of the following conditions holds :

- One of the segments is vertical (parallel to y-axis) and the other is horizontal (parallel to x-axis).

- The product of the segments slopes is equal to -1 : `m_1 * m_2 = -1`

## Intersection point of two segments

We're using parametric equations of the two segments S_{1} and S_{2}. For more informations about line segment equation forms, see : Line segment Equations.

A point M (x,y) of the plane is common to segments S_{1} and S_{2} if and only if its coordinates x and y fulfill parametric equations of the two segments :

\( \left\{ \begin{array}{c} x=a_1+t_1.(c_1-a_1) \\ y=b_1+t_1.(d_1-b_1) \\ 0<=t_1<=1 \end{array} \right. \)

\( \left\{ \begin{array}{c} x=a_2+t_2.(c_2-a_2) \\ y=b_2+t_2.(d_2-b_2) \\ 0<=t_2<=1 \end{array} \right. \)

S_{1} and S_{2} have non-empty intersection if the following equations system has at least one solution (t_{1} , t_{2} ) with 0 ≤ t_{1} ≤1 and 0 ≤ t_{2} ≤ 1 :

\( \left\{ \begin{array}{c} a_1+t_1.(c_1-a_1) = a_2+t_2.(c_2-a_2) \\ b_1+t_1.(d_1-b_1) = b_2+t_2.(d_2-b_2) \\ \end{array} \right. \)

This system can be rewritten as follows,

\( \left\{ \begin{array}{c} t_1.(c_1-a_1) - t_2.(c_2-a_2) = a_2-a_1 \\ t_1.(d_1-b_1) - t_2.(d_2-b_2) = b_2- b_1 \\ \end{array} \right. \)

This is a Cramer system which solutions can be found using our calculator : Cramer system Calculator.

The most important thing in a Cramer system is the determinant of its coefficients matrix :

`\text{det}([(c_1-a_1,-(c_2-a_2)),(d_1-b_1,-(d_2-b_2))]) = -(c_1-a_1)*(d_2-b_2)+(c_2-a_2)*(d_1-b_1)`

There are several possibilities :

- This determinant is non-zero so a unique solution (t_{1} and t_{2})exists. If t_{1} and t_{2} lie between 0 and 1 then, the two segments have a unique intersection point.

- If this determinant is non zero but the unique solution values (t_{1} and t_{2}) does not lie between 0 and 1 then the segments do not intersect.

In fact, the lines on which lie the two segments intersect at a point outside the segments.

- The determinant is zero. In this case, either the system has no solution (case of parallel segments or segments that lie on the same line without intersecting), either, there are an infinity of solutions : the two segments overlap.

## Angle between two segments

Angle between two segments is equivalent to angle beetween lines on which lie the segments. See formula and Calculator here : Angle between two lines.

## See also

Segment Calculator

Line Calculator

Linear System with two unknowns

Coordinate Geometry calculators

Geometry calculators

Mathematics calculators