gpt4 book ai didi

python - 如何将 pybox2d 中的物体角度保持在 -pi 和 pi 之间?

转载 作者:行者123 更新时间:2023-12-01 03:25:31 24 4
gpt4 key购买 nike

pybox2d manual它指出以下内容:

pybox2d uses radians for angles. The body rotation is stored in radians and may grow unbounded. Consider normalizing the angle of your bodies if the magnitude of the angle becomes too large (use b2Body.SetAngle).

但是,当我尝试实现一些东西来“标准化”角度时,我收到以下错误:

AttributeError: 'b2Body' object has no attribute 'SetAngle'

代码片段:

def update_outputs(self):

# This is necessary to prevent the angle
# from getting too large or small
self.body.SetAngle(self.body.angle % 2*pi)

最佳答案

看起来自从这些文档编写以来,该库已经被 Python 化了。角度是 Body 的一个属性:

@angle.setter
def angle(self, angle):
self._xf.angle=angle
self._transform_updated()

您应该能够简单地设置它,例如:

def update_outputs(self):

# This is necessary to prevent the angle
# from getting too large or small
self.body.angle %= 2*pi

关于python - 如何将 pybox2d 中的物体角度保持在 -pi 和 pi 之间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41419503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com