10. Line-line intersection

There are several ways you can approach this problem. One approach that doesn't work well is to use slope-intercept equations of the form y = m × x + b for the lines. The problem with that approach is that it doesn't work for vertical lines. If a line is vertical, then the equation's slope, m, is effectively infinite.

The approach that I use defines a line by giving a point p0 on the line and a vector v that points in the direction of the line. Then the following equation defines the points on the line:

Here, t is any real number. For example, if t = 0, then the point is p0.

This is a parametric equation. In a  ...

Get Improving your C# Skills now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.