【问题标题】:Pygame: Simple Cosine FunctionPygame:简单的余弦函数
【发布时间】:2013-12-16 23:19:35
【问题描述】:

我正在尝试调用一个简单的余弦计算。这是我的代码:

import pygame
from pygame.locals import *
import math

pygame.init()
screen = pygame.display.set_mode((480, 480))
myfont = pygame.font.SysFont("monospace", 15)
angle = 90*(math.pi/180)

while True:

    adj = math.cos(angle)
    display = myfont.render("opposite side: " + str(adj), 1, (255, 255, 0))
    screen.blit(display, (100,40))
    pygame.display.flip()

    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
            exit(0)

由于 cos(90)*5=0,我希望代码显示该值。相反,我收到以下内容:

6.12323399574e-17

【问题讨论】:

标签: pygame trigonometry


【解决方案1】:

floating point arithmetic 会发生这种情况。您应该先截断该值,然后再将其显示给用户。

【讨论】:

  • 该死的太快了。谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多