Python Forum
Python Turtle. Pointers of the "arrow" direction of the vector.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Turtle. Pointers of the "arrow" direction of the vector.
#2
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.
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()
roomONmoon likes this post
Reply


Messages In This Thread
RE: Python Turtle. Pointers of the "arrow" direction of the vector. - by deanhystad - Dec-09-2023, 11:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to move in entries using the arrow keys by applying the bind and focus? pymn 4 4,892 Apr-06-2022, 04:29 AM
Last Post: pymn
  [Tkinter] arrow key selection for menu knoxvilles_joker 6 5,977 Apr-19-2021, 12:04 AM
Last Post: knoxvilles_joker
  Turtle / turtle question DPaul 2 2,218 Oct-04-2020, 09:23 AM
Last Post: DPaul
  How to work with pointers in PyQt? AlekseyPython 4 4,090 Feb-07-2019, 04:14 AM
Last Post: AlekseyPython
  Can someone point me in the right direction? Aesgarth 1 2,764 Nov-03-2017, 11:13 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020