python中的罪和cos的功能不为我工作?
我是这种数学的新手,在学校喷气机中没有它。因此,我的问题是从球形坐标到GRRID的变化(半径和角度到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()
I am new to this kind of mathematics and didn't have it in school jet. So my problem is the change from spherical coordinates to a grrid (radius and angle to x and y). First I devide the circle in even angles. Until here everything works. When they get transformed they have all the same distance to the center but seam to be random in rotation. This can be well seen with low numbers like 4.
The final purpose of the project will be to draw a cardioid for that I need a circle with points. So here my code:
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Python 的三角函数以 弧度 计算角度,而不是度数。
您可以使用
math.radians
和
math. Degrees
。Python's trig functions take their angles in radians, not degrees.
You can easily convert between the two units using
math.radians
andmath.degrees
.