Question: prolog programming !!! 8 & Problem 4 (simple Cartesian geometry using structures) Implement perimeter (Shape, N), where shape is defined as a 4-sided polygon as

8 & Problem 4 (simple Cartesian geometry using structures) Implement perimeter (Shape, N), where shape is defined as a 4-sided polygon as follows: poly4(P1, P2, P3, P4), and P1-P4 are each points of the form point (X,Y), and X and Y $ are coordinates on the X and Y axis, respectively, and the edges are listed counterclockwise starting at the lower 8 left: pl to P2, P2 to P3, P3 to P4, and P4 to Pl; and N is the 8 perimeter (sum of the lengths of the edges). To implement 8 this for any 4-sided polygon, you will need to use the Pythagorian theorem. If a line segment 2 starts at (x1,71) and ends at (x2, Y2), the length of 2 is the square root of (X1- X2)**2 + (Y1-Y2)**2. 8 Use the built-in square root operator in Prolog; for example: 8?- A is sqrt(4). A = 2.0. Test cases: $ Example 1: a square 2- perimeter (poly4 (point(1,1), point(1,2), point (2,2), point(2,1)), A). A = 4.0. 8 Example 2: a rectangle ?- perimeter (poly4 (point(1,1), point(1,5), point(3, 5), point(3,1)), A). 8 A - 12.0. * Example 3: irregular polygon $ ?- perimeter (poly4 (point (2,1), point (2,3), point (6,3), point(4,1)), A). $ A = 10.8284. Hint: simplify your program by implementing a predicate to compute the length of a line segment. 8 Write your solution here: % 8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
