Generating a beveled edge for a 2D polygon

Posted by Metaphile on Stack Overflow See other posts from Stack Overflow or by Metaphile
Published on 2010-05-11T20:33:40Z Indexed on 2010/05/11 21:04 UTC
Read the original article Hit count: 208

Filed under:
|

I'm trying to programmatically generate beveled edges for geometric 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 then scaling it down will not produce the desired result most of the time.

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?

© Stack Overflow or respective owner

Related posts about geometry

Related posts about graphics