LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

プログラミング問題集解答例(問35)

Posted at
import numpy as np
def rotation(x, t, deg = False):
    if deg == True:
        t = np.deg2rad(t)
    a = np.array([[np.cos(t), -np.sin(t)],
                  [np.sin(t),  np.cos(t)]])
    ax = np.dot(a, x)        
    return ax
n = 5
angle = 360 / n
P = []
x0 = [0, 1]
P.append(x0)
for i in range(n):
    x = rotation(P[i], angle * 2, deg=True)
    P.append(x)
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(6,6))
plt.plot(np.array(P)[:, 0], np.array(P)[:, 1])
plt.show()

output_3_0.png

plt.figure(figsize=(6,6))
for n in [19]:
    angle = 360 / n
    P = []
    x0 = [0, 1]
    P.append(x0)
    for i in range(n):
        x = rotation(P[i], angle * int(n/2), deg=True)
        P.append(x)
    plt.plot(np.array(P)[:, 0], np.array(P)[:, 1])
plt.show()

output_4_0.png

plt.figure(figsize=(6,6))
n = 19
for m in [2, 3, 4, 5, 6, 7, 8, 9, 10]:
    angle = 360 / n
    P = []
    x0 = [0, 1]
    P.append(x0)
    for i in range(n):
        x = rotation(P[i], angle * m, deg=True)
        P.append(x)
    plt.plot(np.array(P)[:, 0], np.array(P)[:, 1])
plt.show()

output_5_0.png

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up