I’m trying to programmatically generate beveled edges for 2D polygons. For example, given an array of 4 vertices defining a square, I want to generate something like this:
_________
|\ _____ /|
| | | |
| | | |
| |_____| |
|/_______\|
But computing the vertices of the inner shape is baffling me.
Simply creating a copy of the original shape and scaling it down won’t work in the general case. (Imagine trying to bevel an N-shaped polygon this way.)
My algorithm so far involves analyzing adjacent edges (triples of vertices; e.g., the bottom-left, top-left, and top-right vertices of a square). From there, I need to find the angle between them, and then create a vertex somewhere along that angle, depending on how deep I want the bevel to be.
And because I don’t have much of a math background, that’s where I’m stuck. How do I find that center angle? Or is there a much simpler way of attacking this problem?
The general algorithm is pretty complex. The operation you’re looking for is known as offsetting the polygon; if you search around for that you might find some pointers/papers, etc.
If you’re working in or near C++, you could try CGAL.