So I took a challenge from my Geometry teacher to create code that when the user gives the computer how many angles / sides a polygon has and the angle of each of the interior angles it could find each of the exterior angles whether it is regular or irregular. For example the user tells the computer they have a four-sided shape (quadrilateral), the interior angles are $70, 75, 110, 145$. The computer would then be able to output each corresponding angle in the proper order. My problem is that with coding you can't just type in the human logic so I need a formula to work from: what on earth would be a formula that could apply to any polygon with any number of sides (irregular or regular)?
2 Answers
At each vertex of the polygon, the interior angle and exterior angle must sum to $180$. You can use this to find the value of each exterior angle.
The other answer is not complete, because you can have a non convex polygon (i.e one interior angle can be 240) and to say that $180-$input_angle
is not all correct.
Thr proper way to to this is:
- read angles and save them as a list
angles_list
- initialize and empty array with size equal to
angles_list
with nameexteriors
. - loop over elements in
angles_list
, ifelement
is greater than 180, then append toexteriors
$360-$element
, else append $180-$element
- return
exteriors
Also you can add validations to check if the input angles indeed correspond to a polygon (i.e, the sum of angles must be a multiple of 180)