## Lesson goal: More on points and lines

Previous: Reasoning about points and lines (1) | Home | Next: Looking for right triangles

In the last lesson, we looked at what lines would be possible, given a bunch of points that we set. Let's now look for lines that are perpendicular to each other.

We can think of two tests for lines being perpendicular. 1) One line is horizontal and the other vertical, and 2) the slopes of the two lines, $m_1$ and $m_2$ are so that $m_1m_2=-1$. (We have horizontal and vertical tests from the last lesson.)

One definition for perpendicular lines is if one is horizontal and one is vertical. You can see this defined in the first perp(L1,L2) clause. It says "find a line $L_1$ and see if it's horizontal. Then find a line $L_2$ and see if its vertical."

Another definition for perpendicular lines is if neither is vertical and the product of their slopes is -1. (We have to avoid vertical lines in this clause because their slopes are $\infty$.) You can see this in the second clause of perp(L1,L2). It says "find a line $L_1$ and be sure it's not vertical. Then find a line $L_2$ and be sure it is also not vertical. Find the slope of each into $m_1$ and $m_2$, then see if $m_1\times m_2$ is $-1$."

Note we have a slope calculator clause slope(...), and a clause called is_neg1(X) that checks if X is "close to -1" (this handles cases where round-off in the computer's math might gives $-0.99$ for $m_1\times m_2$, etc. which is close enough to $-1$.