diff options
author | Alex Merry <alex.merry@cs.ox.ac.uk> | 2012-05-24 12:47:55 +0100 |
---|---|---|
committer | Alex Merry <alex.merry@cs.ox.ac.uk> | 2012-05-24 12:47:55 +0100 |
commit | 5c02c4a01cd98de2e2a4b4def7d4667d5f2ab3ef (patch) | |
tree | 8760e584fef8f7a80a1dcab7c68408373da87a93 | |
parent | e363a25246d76f8e1b1c6f14c0700dedb96c82e9 (diff) |
Draw regular polygons with an inner circle radius
TikZ determines the size of a regular polygon by the radius of a circle
inscribed inside the shape, touching the middle of each edge, not a
circle outside the sahep, touching each vertex.
-rw-r--r-- | tikzit/src/common/RegularPolyShape.m | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tikzit/src/common/RegularPolyShape.m b/tikzit/src/common/RegularPolyShape.m index b9acdf3..3555115 100644 --- a/tikzit/src/common/RegularPolyShape.m +++ b/tikzit/src/common/RegularPolyShape.m @@ -34,7 +34,10 @@ if (self == nil) return nil; - float radius = 0.25f; + // TikZ draws regular polygons using a radius inscribed + // _inside_ the shape (touching middles of edges), not + // outside (touching points) + const float innerRadius = 0.2f; NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:sides]; NSMutableArray *edges = [NSMutableArray arrayWithCapacity:sides]; @@ -42,6 +45,9 @@ float dtheta = (M_PI * 2.0f) / ((float)sides); float theta = (dtheta/2.0f) - (M_PI / 2.0f); theta += degreesToRadians(rotation); + // radius of the outer circle + float radius = ABS(innerRadius / cos(dtheta)); + for (int i = 0; i < sides; ++i) { NSPoint p; p.x = radius * cos(theta); |