point(x,y).
facts as you can see at the top of the code below, which describes the points in the above graph.
line([(X1,Y1),(X2,Y2)])
clause below. This clause says "find a point $(x_1,y_1)$ and another point $(x_2,y_2)$, which defines a line. Also be sure either $x_1\ne x_2$ or $y_1\ne y_2$." (Our format for a line will look like this $[(x_1,y_2),(x_2,y_2)]$, a Prolog list of two $(x,y)$ points.) If we run line(L)
for example, one result will be L = [(-4,4),(-3,2)]
.
horiz
clause below, horiz([(_,Y),(_,Y)])
. See how the Y
is forced to be in common between the two points on the line (and we don't care about the $x$-coordinates).
vert([(X,_),(X,_)])
, where you can note how the X
coordinates are forced to be the same for both points of the line (and we don't care about the $y$-coordinates).
goal: line(L).
to see all lines in your point set.
goal: line([(3,Y1),(X2,Y2)]).
to look for all lines that have $x_1=3$.
goal: line(L), horiz(L).
to see all horizontal lines in your point set.
goal: line(L), vert(L).
to see all vertical lines in your point set.
Be sure to check the results displayed with your knowledge of math. Is Prolog doing this correctly?