I have been working on a 2-dimensional object creator program that handles manipulations of arbitrary shapes and calculates collision detection between them. The program allows you to input a shape's coordinates, and from there it will do whatever else you want it to do (draw the shape to the screen, expand the border, manipulate individual coordinates, make it symmetrical, etc.).

But I've run into a problem when trying to calculate the interior angles of an arbitrary polygon. While the algorithm's I've used to calculate the angles technically output the correct angle, I have no way of telling whether or not the program spits out an interior angle or an exterior angle (since the arbitrary shape the user inputs could have concave vertices).

On paper this would seem like a piece of cake, since you can visualize the shape and you can interpret which angle is interior and exterior automatically. But since the program only stores the values of the coordinates and doesn't actually visually create the object to extrapolate data, this problem becomes a little bit trickier to solve.

So my question is:

What method should I use to calculate the angle between two lines and how should I go about using it to determine the difference between an interior and an exterior angle?

For example, if I have a shape that has coordinates $((30,50),(35,47),(40,50),(37,43),(35,35),(33,43))$ (which ends up looking sort of like an upside-down spire with a concave base), I can easily calculate the angles between the lines, but which angle I am calculating is a mystery.


Your problem starts with clearly defining what you mean by an "interior" angle. I assume you always "close" the shape by connecting the last coordinate to the first one.

Maybe you should start with convex shapes. You can find some good definitions in topology material. Pick a definition where you can see what programming is needed to determine that the shape is convex. In this case the angle less than $\pi$ is the right one.

Then decide what other shapes you will allow. Will you accept a star? How will you define "star"? If you are clear about that, then you know which interior angles must be < $\pi$ and which interior angles greater.

There are some awful things out there, which double back upon themselves, etc. I can't imagine that you want to deal with them. But how do you rule them out?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.