[Python] Get n number of coordinates from an octagon

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    I want to get the coordinates of a number of points that together form an octagon. For a circle this is done easily as follows:

    import numpy as np

    n = 100
    x = np.cos(np.linspace(0, 2 * np.pi, n))
    y = np.sin(np.linspace(0, 2 * np.pi, n))

    coordinates = list(zip(x, y))


    By changing n I can increase/decrease the "angularity". Now I want to do the same for an octagon. I know that an octagon has 8 sides and the angle between each side 45 degrees. Let's assume that the perimeter of the octagon is 30.72m. Each side has therefore a length of 3.79m.

    perimeter = 30.72
    n_sides = 8
    angle = 45


    How can I get n coordinates that represent this octagon?

    Continue reading...

Compartilhe esta Página