Help! My math exam is coming up soon and I didn't study! 1 Part of the exam is to classify a quadrilateral given its vertex coordinates, which I, unfortunately, do not know how to do. 2
So, your challenge is to write a program to do this for me so I don't fail!
Given four vertices such that no three of them are colinear, determine the most specific classification of the quadrilateral formed by those four vertices.
What I mean by "most specific classification" is that even though all squares are rectangles, if the shape is a square, you should indicate that it is a square and not indicate that it is a rectangle.
Input will be given as four (x, y) coordinates. You may take these as a list of length 4 of lists/tuples of length 2. Alternatively, you can take input as a list of the x-coordinates and a list of the respective y-coordinates.
For example, if my shape has vertices at points
(6, 1), and
(1, 1), you may choose to take input in either of the following formats or something similar:
[(0, 0), (5, 0), (6, 1), (1, 1)] ([0, 5, 6, 1], [0, 0, 1, 1])
You may assume that the quadrilateral is not self-intersecting and that the points are given in the correct order (that is, two consecutive points in the input will be connected by a line segment in the quadrilateral).
You will need a unique output for each of the following classes of quadrilaterals:
This could be the exact name itself, a character, an integer, etc.
- Standard Loopholes Apply
- If your programming language has a built-in that will perform this exact task, that built-in is not allowed.
- Built-ins for finding the distance between two points are allowed.
- Built-ins for finding the angle between two lines are allowed.
At this point, if you know all of the terms, you are ready to start programming! (Test Cases are at the end)
This section is for anyone who needs clarification on the definitions of the different shapes.
A quadrilateral is a square if and only if all 4 of its sides are equal in length and every pair of adjacent sides is perpendicular (that is, it is both a rectangle and a rhombus).
A quadrilateral is a rectangle if and only if every pair of adjacent sides is perpendicular.
A quadrilateral is a rhombus if and only if all 4 of its sides are equal.
A quadrilateral is a parallelogram if and only if each pair of opposite sides is parallel and each pair of opposite angles is equal. Both of these conditions imply each other so you only need to check for one of them.
A quadrilateral is a trapezoid/trapezium if and only if it has at least one pair of parallel sides.
A quadrilateral is a kite if two opposite pairs of adjacent sides are equal in length; that is, two of its adjacent sides are equal and the other two are also equal.
input as (x, y) * 4 -> full name [(0, 0), (1, 0), (1, 1), (0, 1)] -> square [(0, 0), (1, 1), (-1, 3), (-2, 2)] -> rectangle [(0, 0), (5, 0), (8, 4), (3, 4)] -> rhombus [(0, 0), (5, 0), (6, 1), (1, 1)] -> parallelogram [(0, 0), (4, 0), (3, 1), (1, 1)] -> trapezoid/trapezium [(0, 0), (1, 1), (0, 3), (-1, 1)] -> kite [(0, 0), (2, 0), (4, 4), (0, 1)] -> quadrilateral
Links (Desmos Graphing Calculator)
Here are links to visualizations of each of the test cases.
I can't bring a computer into the exam obviously, so I need you to write the shortest code possible so I can memorize it. I need to write it into the margins and run it using TryItOfflineTM so to fit it into the margins your program needs to be as small as possible!
1 Of course I actually did :P
2 Of course I actually do :P