【发布时间】:2020-07-04 20:54:55
【问题描述】:
我写了一些代码来尝试实现一个函数,它使用屏幕中心的坐标创建一个三角形,在这种情况下它也对应于三角形的中心,这个坐标被标识为“cx”和“ cy”,因为窗口是 800 x 600 cx = 400 和 cy = 300。 有了这个,我创建了一个“第一个点”,它具有相同的中心 x 坐标,但它在中心上方 100 个像素,现在使用中心和第一个点,我试图计算另一个点应该在哪里。 这是代码:
def triangle(cx,cy):
angle = 2*math.pi/3
first_point_x = cx
first_point_y = cy + 100
vertex = [first_point_x,first_point_y]
for i in range(2):
newx = (vertex[i*2]-cx) * math.cos(angle) - (vertex[i*2+1]-cy) * math.sin(angle)
newy = (vertex[i*2+1]-cy) * math.cos(angle) + (vertex[i*2]-cx) * math.sin(angle)
vertex.append(newx)
vertex.append(newy)
return vertex
但由于某种原因,该数组给出的负值和数字总体上不符合我想要的。 任何帮助都将不胜感激。
【问题讨论】: