author Antonio Ospite Wed, 23 May 2018 14:37:19 +0000 (16:37 +0200) committer Antonio Ospite Wed, 23 May 2018 15:05:28 +0000 (17:05 +0200)
 .gitignore [new file with mode: 0644] patch | blob draw_circle_surrounded_by_circles.py [new file with mode: 0755] patch | blob

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..210b681
--- /dev/null
@@ -0,0 +1 @@
+circle-surrounded-by-circles.svg
diff --git a/draw_circle_surrounded_by_circles.py b/draw_circle_surrounded_by_circles.py
new file mode 100755 (executable)
index 0000000..0a1ed24
--- /dev/null
@@ -0,0 +1,90 @@
+#!/usr/bin/env python3
+#
+# Draw a circle surrounded by other circles
+#
+# Copyright (C) 2018  Antonio Ospite <ao2@ao2.it>
+#
+# Using a formula from:
+# https://math.stackexchange.com/questions/12166/numbers-of-circles-around-a-circle
+
+from math import pi, sin, cos, degrees
+import svgwrite
+
+
+        raise ValueError("Radius of outer circles cannot be zero")
+
+    if number_of_circles < 3:
+        raise ValueError("Number of outer circles cannot be smaller than 3")
+
+    # Ratio between the inner circle and the outer circles
+    ratio = sin(pi / number_of_circles) / (1 - sin(pi / number_of_circles))
+
+
+
+
+              number_of_circles, unit=""):
+    border = 10
+
+    width = height = (inner_circle_radius + outer_circles_radius + border) * 2
+
+    svg = svgwrite.Drawing(filename, profile='full',
+                           size=(str(width) + unit, str(height) + unit),
+                           viewBox=('0 0 %g %g') % (width, height))
+
+    cx_inner = cy_inner = width / 2
+
+    inner_circle = svgwrite.shapes.Circle(center=(cx_inner, cy_inner),
+                                          fill='none',
+                                          stroke='black',
+                                          stroke_width=0.5)
+
+    # Add a group for the first outer circle for extra flexibility.
+    outer_circle_group = svgwrite.container.Group()
+
+    cx_outer = cx_inner + sin(0) * (inner_circle_radius +
+    cy_outer = cy_inner + cos(0) * (inner_circle_radius +
+    outer_circle = svgwrite.shapes.Circle(center=(cx_outer, cy_outer),
+                                          fill='none',
+                                          stroke='black',
+                                          stroke_width=0.5)
+
+    # Clone the group for the other outer circles to make it easier to keep
+    # visual symmetry by editing just the first group added above.
+    for i in range(1, number_of_circles):
+        theta = i * 2 * pi / number_of_circles
+        outer_circle_clone = svgwrite.container.Use(outer_circle_group,
+                                                    insert=(0, 0),
+                                                    transform="rotate(%f, %f, %f)" %
+                                                    (degrees(theta),
+                                                     cx_inner,
+                                                     cy_inner))
+
+    svg.save()
+
+
+def main():