lundi 24 octobre 2016

I need help in developing a circular pattern

I am trying to generate this pattern and instead of adding for loops and approximate angles (i think the angles towards the end might be off) i was wondering if someone could provide some insight.

The end goal would be to simply state the radius and how many layers of cicles i wish to generate

Thank you...

import numpy as np
import matplotlib.pyplot as plt

__author__ = 'George Pamfilis'

def rotate_around_origin(r,angle):
    # http://ift.tt/2f8xGM1
    x = r * np.cos(angle)
    y = r * np.sin(angle)
    return x, y

if __name__ == '__main__':
    r = 1
    r_cylinder = 1
    p1 = (0, 0)
    ps = [p1]

angle = 60

# first layer
for i in range(6):
    p_new = rotate_around_origin(2*r + (r/2) * 0, np.deg2rad(angle))
    ps.append(p_new)
    angle += 60

# second layer


angle = 30

for i in range(6):
    p_new = rotate_around_origin(3*r+(r/2) * 1, np.deg2rad(angle))
    ps.append(p_new)
    angle += 60


angle = 60
for i in range(6):
    p_new = rotate_around_origin(4*r+(r/2)*0, np.deg2rad(angle))
    ps.append(p_new)
    angle += 60


angle = 60 + 30/2 + 4

for i in range(6):
    p_new = rotate_around_origin(5*r+(r/3), np.deg2rad(angle))
    ps.append(p_new)
    angle += 60


angle = 60 +30/2 + 4 -8 + 30

for i in range(6):
    p_new = rotate_around_origin(5*r+(r/3), np.deg2rad(angle))
    ps.append(p_new)
    angle += 60


angle = 60
for i in range(6):
    p_new = rotate_around_origin(5*r+(r/1)*1, np.deg2rad(angle))
    ps.append(p_new)
    angle += 60

angle = 30
for i in range(6):
    p_new = rotate_around_origin(6 * r + (r / 1) * 1, np.deg2rad(angle))
    ps.append(p_new)
    angle += 60


angle = 60 +13.75
for i in range(6):
    p_new = rotate_around_origin(6*r+(r/1)*1+r/4, np.deg2rad(angle))
    ps.append(p_new)
    angle += 60


angle = 46.25
for i in range(6):
    p_new = rotate_around_origin(6*r+(r/1)*1+r/4, np.deg2rad(angle))
    ps.append(p_new)
    angle += 60


angle = 60
for i in range(6):
    p_new = rotate_around_origin(6*r+(r/1)*1+r/4 + (r/1.25), np.deg2rad(angle))
    ps.append(p_new)
    angle += 60


plt.figure(figsize=(20, 20 * (1/1)))

fig = plt.gcf()
# circle1 = plt.Circle((0, 0), 6*r+r+r+r/2+r, color="r")
# this is added just to enclose the pattern.
circle1 = plt.Circle((0, 0), 6*r+r+r+r, color="r")

fig.gca().add_artist(circle1)
for p in ps:
    circle1 = plt.Circle((p[0], p[1]), r)
    fig.gca().add_artist(circle1)


plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()

enter image description here

Aucun commentaire:

Enregistrer un commentaire