为什么 Python 中的 sin 和 cos 函数对我不起作用?

Why are sin and cos functions in Python not working for me?

我对这种数学很陌生,学校的飞机上没有。所以我的问题是从球坐标到网格的变化(半径和角度到 x 和 y)。首先,我将圆分成均匀的角度。直到这里一切正常。当它们变形时,它们到中心的距离都相同,但在旋转时接缝是随机的。这可以从 4 这样的低数字中看出。 该项目的最终目的是绘制一个心形,因为我需要一个带点的圆。所以这是我的代码:

from tkinter import *
from math import *
import round_canvas as round

#settings
speed = 1 # in ms
window_size = 700
cellamount = 20
cell = window_size / cellamount
r = 300
pointSize = 20
animationSize = window_size - cell*4

#colors:
#48979b
#7cbeba
#a7c7b3
#d9beac
#f5e6d9

#window
win = Tk()
win.title("heart")
win.resizable(False, False)
win.geometry(str(window_size) + "x" + str(window_size))
win.configure(background="#f5e6d9")

# variables
point_amount = 4
point_cords = [] # saves point rotations in list (place in list coresponds to number of point)

# canvas
canvas = Canvas(win, width=window_size, height=window_size, bg="#f5e6d9", 
highlightthickness=0)
canvas.place(x=0,y=0)
canvas_overlay = round.round_rectangle(canvas, cell, cell, cell*cellamount-cell, 
cell*cellamount-cell, radius=40, fill="#d9beac")

# functions:
def drawPoints():
    for point in range(0, point_amount):
        #print(point)
        localPoint = 360/(point_amount)*point
        point_cords.append(localPoint)

def showPoints():
    for angle in point_cords:
        print(angle)
        localX = cos(angle)*r+window_size/2 # https://www.youtube.com/watch?v=O5wjXoFrau4&t=635s
        localY = sin(angle)*r+window_size/2
        print(localX, localY)
        visiblePoint = canvas.create_oval(localX-pointSize/2, localY-pointSize/2, localX+pointSize/2, localY+pointSize/2, width=0, fill="#7cbeba")

# main
def main():
    drawPoints()
    showPoints()

win.after(speed,main)
win.mainloop()

Python 的三角函数采用 radians 的角度,而不是度数。

您可以使用 math.radians and math.degrees 在两个单位之间轻松转换。

>>> math.sin(math.radians(45))
0.7071067811865476