Two non-vertical lines are perpendicular if and only if the product of their slopes is −1.
Let two lines have inclinations θ1 and θ2. If they are perpendicular:
θ2=θ1+90°
Then:
m2=tanθ2=tan(θ1+90°)=−cotθ1=−tanθ11=−m11
Therefore:
m1m2=−1
Geometric interpretation
If line L1 has slope m, a vector along it is (1,m). A vector along a line perpendicular to L1 is (−m,1) (rotate 90°). The slope of the perpendicular is −m1=−m1, giving m⋅(−m1)=−1.
Edge cases
If one line is horizontal (m1=0), the perpendicular is vertical (undefined slope) — handle separately.
If one line is vertical (undefined slope), the perpendicular is horizontal (m=0) — handle separately.
Key Idea
Vector form. Let $\vec{d_1} = (1, m_1)$ and $\vec{d_2} = (1, m_2)$ be direction vectors of the two lines. Perpendicularity means:
>
> $$
> \vec{d_1} \cdot \vec{d_2} = 0
> $$
>
> Computing: $(1)(1) + (m_1)(m_2) = 1 + m_1 m_2 = 0$, which gives $m_1 m_2 = -1$.
>
> The dot product condition $\vec{d_1} \cdot \vec{d_2} = 0$ is the universal test — it works in 2D, 3D, and any dimension, and handles vertical/horizontal lines without special cases (use direction vectors $(0,1)$ and $(1,0)$ respectively).