math - Draw diagonals of an n-gon, effectively -
so got problem while practicing python, guess applies languages. draw diagonals in regular n-gon , fine, managed that. but, there criteria aswell, same line isn't drawn more once. way interpret turtle (i use turtle graphics btw) cannot travel between same 2 corners twice, , not lift pen. have been trying find solution while can't seem figure out , have started wonder if possible.
do on here know if possible n-gons? , if is, give me hint?
here 2 regular n-gons don't know is. (i sure hell didn't)
/q
edit
thanks john kahn able solvable part, pointed out can done on regular n-gons of uneven degree. here code solution. think?
def nhorning(r, n, ): if n % 2 == 0: print("it can't done") return none angl = (2 * pi) / n # angle calculating coordinates of n-gon = {} # contains destinations each corners diagonals cord = {} # contains coordinates of each corner x in range(n): cord[x] = [float("%.2f" % (r * cos(x * angl))), float("%.2f" % (r * sin(x * angl)))] # corners coordinates in range(n): # diagonals drawn corner "i" a[i] = [x x in range(n)] a[i].remove(i) # can't draw diagonal cunt = 0 pu() goto(cord[0]) # have start on corner pd() cordstring = str(cord) # list isn't hashable, making lists string while cunt < (((n-1) * n) / 2): # loops until diagonals drawn if str(list(pos())) in cordstring: # should on circles radius except in beginning in range(len(cord)): if cord[i] == list(pos()): # finds corner turtle on = diags = a[where] # diagonals not drawn corner dest = diags.pop() # corner diagonal drawn, # removes since diagonal corner drawn nwhere = a[dest] # diagonals not drawn corner # diagonal drawn next nwhere.remove(where) # diagonal destination corner current corner drawn next, # can't drawn again goto(cord[dest]) # draw diagonal cunt += 1 done()
tldr
you looking eulerian path.
it possible odd number of vertices, impossible number.
explanation
"to see why true, note every time path passes through vertex, uses 2 of edges connected vertex. because of this, vertices except first , last 1 on path need have degree. in case of cycle, first , last vertex same, vertices need have degree." - for square, concept applies n-gons