Dec-09-2023, 11:49 PM
(This post was last modified: Dec-09-2023, 11:49 PM by deanhystad.)
You need to use atan2(y, x) instead of atan(). The sign of x and y are needed to derive the correct quadrant.
You can draw fewer lines if you draw the arrows at both ends of the lines.
You can draw fewer lines if you draw the arrows at both ends of the lines.
from math import sin, cos, degrees, pi, atan2 import turtle R = 100 r = 25 n = 4 Fi = 2*pi/n win = turtle win.setup(400, 400) win.title("Dependence of matrix elements") win.speed(10) p = [] for i in range(4): x = R * cos(Fi * i) y = R * sin(Fi * i) p.append((x, y)) win.teleport(x, y - r) win.circle(r) win.teleport(x, y) win.dot(5) win.teleport(x + 4, y + r) win.write(i + 1) win.speed(1) j = 3 for i in (0, 1, 2, 3, 1, 2, 0): win.teleport(p[j][0], p[j][1]) angle = atan2(p[j][1] - p[i][1], p[j][0] - p[i][0]) angle = degrees(angle) win.setheading(angle) win.stamp() win.setheading(angle + 180) win.goto(p[i][0], p[i][1]) win.stamp() j = i win.done()