Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
angle of rotation
#3
I entered into the program correction bot coefficients from the current bot direction. Now shows the exact value of the angle.

import tkinter as tk
from tkinter import*
import math


root = tk.Tk()
root.geometry('500x500+2+10')



def target(event):
    
    bot_center_x = canvas1.coords(bot)[0] + 15
    bot_center_y = canvas1.coords(bot)[1] + 15
    
    clik_x = event.x
    clik_y = event.y
    
    angle(bot_center_x, bot_center_y, clik_x, clik_y)


def angle(bot_center_x, bot_center_y, clik_x, clik_y):
    
    if  angle_mov == 'nord':  #current bot direction
        k1 = 90
        k2 = 270
    elif angle_mov == 'east': #current bot direction
        pass
    elif angle_mov == 'south':#current bot direction
        pass
    elif angle_mov == 'west': #current bot direction
        pass
    
    if clic_x >= bot_x:
        angle_grad = int(math.degrees(math.atan((clic_y - bot_center_y) / (clic_x - bot_center_x))) + k1)
    else:
        angle_grad = int(math.degrees(math.atan((clic_y - bot_center_y) / (clic_x - bot_center_x))) + k2)
        
        print('angle: '+str(angle_grad))



canvas1 = Canvas(root, width = 500, height = 500)
canvas1.place(x = 0, y = 0)

bot = canvas1.create_oval(200, 200, 230, 230)

angle_mov = 'nord' #current bot direction

root.bind('<Button-1>', target)

root.mainloop()
Reply


Messages In This Thread
angle of rotation - by berckut72 - Apr-15-2020, 10:22 AM
RE: angle of rotation - by TomToad - Apr-15-2020, 06:56 PM
RE: angle of rotation - by berckut72 - Apr-16-2020, 04:56 AM
RE: angle of rotation - by michael1789 - Apr-17-2020, 06:00 PM
RE: angle of rotation - by berckut72 - Apr-27-2020, 04:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Sprite image rotation problem XavierPlatinum 4 2,559 Jul-25-2022, 01:31 PM
Last Post: Ruslan8819
  [PyGame] Rotation Problem in PyGame thunderbird028 1 2,791 Nov-14-2019, 06:49 AM
Last Post: Windspar
  [PyGame] Converting PyGame 2 axis joystick float to 360 angle archieab 1 3,444 Sep-26-2018, 05:40 PM
Last Post: archieab
  What's the angle? microphone_head 0 1,948 Aug-13-2018, 08:38 PM
Last Post: microphone_head

Forum Jump:

User Panel Messages

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