Lesson goal: Looking for Triangles

Previous: Reasoning about points and lines (2) | Home | Next: Looking for rectangles

Continuing to work with the set of $(x,y)$ points from this lesson, let's look for some triangles amongst the points.

On the one hand, it's kind of easy to find triangles, because any 3 points will form a triangle. But, we still want Prolog to do it, so we'll get a bit of practice with it. The goal goal: line([P1,P2]), line([P2,P3]), line([P3,P1]). will find triangles, noting that we ask Prolog to look for 3 lines that are formed solely of 3 unique points ($P_1$, $P_2$ and $P_3$). Notice we did not do line([P1,P2]), line([P3,P4]), line([P5,P6]).

To make Prolog work a little harder, suppose we restricted our triangle search to right triangles? Right triangles also need the three lines the goal above finds, with the additional qualification that two of the 3 lines are perpendicular.

Take a look at the goal below.

Now you try. Run the goal and test (with pencil, paper and a ruler by plotting the lines) if indeed the lines form right triangles.

Type your code here:

See your results here: