# Help: scripting circle within circle

Hi everyone, I am new to the forum and a 2-week new Rhino learner without much programming experience, but trying to create a recursive loop with python(!). Brain racked for days so am seeking help here…

I attempt to write a script that draws a circle within a circle and continues for a few generations. As I am confused about the syntax, I am mostly only able to write down the steps I think the script should do.

Does what I outline make sense in Python? I am most unsure about how I may locate a point on the circle to draw the next circle.

Any help from major direction to actual solutions appreciated! Many thanks in advance!

``````import rhinoscriptsyntax as rs

def concentric_circles():
circle = rs.GetObject("select starting circle",4)
if not circle:
print ("Without giving me a circle what do you expect?")
return
if not rs.IsCircle(circle):
print ("Did you try to fool me?")
return
return
center = rs.CircleCenterPoint(circle)

concentric_circles()
``````
1 Like

and here is one for touching circles:

``````import rhinoscriptsyntax as rs
import random
import math

def touching_circles():
circle = rs.GetObject("select starting circle",4)
if not circle:
print ("without giving me a circle what do you expect?")
return
if not rs.IsCircle(circle):
print ("did you try to fool me?")
return
return
center = rs.CircleCenterPoint(circle)
angle = random.random()*2*math.pi
x = math.sin(angle)
y = math.cos(angle)
trans=(x,y,0)
rs.MoveObject(circle, trans)

touching_circles()
``````

and one for spiraling circles:

``````import rhinoscriptsyntax as rs
import random
import math

def spiraling_circles():
circle = rs.GetObject("select starting circle",4)
if not circle:
print ("without giving me a circle what do you expect?")
return
if not rs.IsCircle(circle):
print ("did you try to fool me?")
return
return
angle = 0
center = rs.CircleCenterPoint(circle)
angle+= math.pi/7
x = math.sin(angle)
y = math.cos(angle)
trans=(x,y,0)
rs.MoveObject(circle, trans)

spiraling_circles()
``````

Thank you so much for the quick response! I am working based on your solution although I haven’t grasped the angle/sin/cos bits. Let me finish it off and come back later. Cheers!

Just look for polar coordinates in your favorite search engine. The relation between a point on a circle with radius 1 and the derived x and y coordinates is that for any angle a, x=cos(a) and y=sin(a)
Although I swapped x and y in my example but it’s in fact the same logic.
So I take a random angle and then move the circle in that direction 1 unit.