data generator of a regular polygon

339 Views Asked by At

Don't know how to do it.

Write a function C = make_means(k, radius) that outputs a k x 2 data matrix C containing the 2D coordinates of k means (of the data to be generated later). The means of the data generator must lie on the vertices of a regular polygon (if k=3 the polygon is a equilateral triangle, if k=6 it is a regular hexagon, etc). Write your own code to determine the position of the vertices of a regular polygon given a radius value (input radius) of the circle centered in the origin and inscribing the regular polygon. The first point of the polygon on the x-axis.

For example make_means(3, radius=1) would yield:

[[ 1. , 0. ],

[-0.5 , 0.8660254],

[-0.5 , -0.8660254]]

here is my code:

for i in range(0, 360, 72):
    theta = np.radians(i)
    mean = np.array([1., 0.])
    c, s = np.cos(theta), np.sin(theta)
    cov = np.array(((c, -s), (s, c)))
    C = np.random.multivariate_normal(mean, cov, size= 1000)
    #C
    plt.scatter(C[:, 0], C[:, 1])

but it seems does not appear to rotate.

1

There are 1 best solutions below

0
Tejas Urs On
x_values = []
    y_values = []
    for i in range(k):
        angle = 2 * np.pi / k
        x = radius * np.cos(i * angle)
        y = radius * np.sin(i * angle)
        x_values.append(x)
        y_values.append(y)
    A = np.c_[x_values,y_values]

its something as simple as this.