This activity will help you practice writing functions while solving for the area of a simple polygon.
The shoelace formula (https://en.wikipedia.org/wiki/Shoelace formula) is an algorithm to calculate the
area of a simple polygon given the vertices. Its name comes from repeatedly cross-multiplying the
coordinates, like threading shoelaces. The math behind the method works by taking each edge of the
polygon, forming a triangle with the origin, taking the cross-product (which gives the area of a
parallelogram), then dividing by 2. The component areas will overlap, however the areas outside of the
polygon will cancel out leaving only the area inside remaining. You can view a nice video explanation
here: https://www.youtube.com/watch?v=0KjG8Pg6LGk
Create a program named shoelace_formula.py that utilizes the shoelace formula via the following steps:
1. Create a function named getpoints that takes in as an argument a string and returns a list of
points of arbitrary length. The string passed to the function contains pairs of numbers separated
by commas, with each pair separated by a space, as shown in the format below. Have the
function convert it to a list of points (the polygon's vertices). Each element in the list of points
should itself be a list of one point. For the example shown below, your function should return:
[[3, 4], [5, 6], [9, 51, [12, 8], [5, 11]]
2. Create a function named cross that takes in two arguments, both of which are a list of one
point, and returns the cross-product. This is one step of the shoelace method. For example, if
the points [1, 2] and [3, 4] are passed to the function, in that order, it will return -2.
Cross product: (14) - (23) = -2
3. Create a function named shoelace that takes in as an argument a list of points and returns the
area of the polygon calculated via the shoelace formula. The list of points passed to the function
is the same list returned by your getpoints function. Your shoelace function should call your
cross function.
4. Create a function named main that does not take in any arguments nor return any values. This
function should take as input from the user a string of pairs of numbers separated by commas
and spaces, as shown in the format below, and print the area of the polygon. Your main function
should call your getpoints and shoelace functions. Format your output as shown below.
5. Finally, in your main code type the following:
if__name__==main_ ==!
main ()
You should NOT include any other executable lines in your main code.