From 5c02c4a01cd98de2e2a4b4def7d4667d5f2ab3ef Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Thu, 24 May 2012 12:47:55 +0100 Subject: 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. --- tikzit/src/common/RegularPolyShape.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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); -- cgit v1.2.3