Pygame 官方文档 - pygame.math

Pygame.math提供了Vector2和Vector3类来处理二维和三维向量,包括点积、叉积、归一化、缩放、反射、旋转、距离计算等操作。这些方法支持按元素执行,方便在游戏开发中进行向量运算。
摘要由CSDN通过智能技术生成

pygame.math

pygame模块关于向量类
pygame.math.Vector2 - 一个二维向量
pygame.math.Vector3 - 一个三维向量
pygame.math.enable_swizzling - 全局允许对向量进行调配
pygame.math.disable_swizzling - 全局禁用对向量进行调配

        pygame math模块目前分别提供Vector2(二维)和Vector3(三维)的Vector类。
        它们支持以下数值运算:vec + vec,vec-vec,vec * number,number * vec,vec / number,vec // number,vec + = vec,vec- = vec,vec * = number,vec / = number ,vec // =number。 所有这些操作都将按元素执行。 此外,vec * vec将执行标量积(又叫点积)。 如果你想将vector v中的每个元素与vector w中的每个元素相乘,你可以使用按元素方法:v.elementwise()\ * w
        pygame 1.9.2pre中的新功能。 1.9.4删除实验通知。 1.9.4将构造函数更改为需要2个或3个元素,而不是指定0默认值。 1.9.4允许标量构造如GLSL Vector2(2)== Vector2(2.0,2.0) 1.9.4 pygame.math需要导入。 更方便的pygame.Vector2和pygame.Vector3。
 

pygame.math.Vector2

一个二维向量
Vector2() -> Vector2
Vector2(int) -> Vector2
Vector2(float) -> Vector2
Vector2(Vector2) -> Vector2
Vector2(x, y) -> Vector2
Vector2((x, y)) -> Vector2

pygame.math.Vector2.dot - 使用另一个向量计算点或标量积
pygame.math.Vector2.cross - 计算叉或矢量积
pygame.math.Vector2.magnitude - 返回向量的欧几里德矢量大小。
pygame.math.Vector2.magnitude_squared - 返回向量的平方大小。
pygame.math.Vector2.length - 返回向量的欧几里德长度。
pygame.math.Vector2.length_squared - 返回向量的平方欧几里德长度。
pygame.math.Vector2.normalize - 返回方向相同但长度为1的向量。
pygame.math.Vector2.normalize_ip - 将矢量就原地位置正规化,使其长度为1。
pygame.math.Vector2.is_normalized - 测试向量是否正规化,即长度== 1。
pygame.math.Vector2.scale_to_length - 将矢量缩放到给定长度。
pygame.math.Vector2.reflect - 返回给定法线的反射向量。
pygame.math.Vector2.reflect_ip - 就原地位置给定法线的反射向量。
pygame.math.Vector2.distance_to - 计算给定矢量的欧几里德距离。
pygame.math.Vector2.distance_squared_to - 计算到给定向量的平方欧几里德距离。
pygame.math.Vector2.lerp - 返回给定向量的线性插值。
pygame.math.Vector2.slerp - 返回给定向量的球面插值。
pygame.math.Vector2.elementwise - 下一个操作将按元素执行。
pygame.math.Vector2.rotate - 以角度为单位旋转给定角度的矢量。
pygame.math.Vector2.rotate_ip - 将矢量旋转一个给定角度(以度为单位)。
pygame.math.Vector2.angle_to - 以角度为单位计算给定矢量的角度。
pygame.math.Vector2.as_polar - 返回一个具有径向距离和方位角的元组。
pygame.math.Vector2.from_polar - 从极坐标元组中设置x和y。
关于Vector2类的一些一般信息。

pygame.math.Vector2.dot()

使用另一个向量计算点或标量积
dot(Vector2) -> float
搜索pygame.math.Vector2.dot的示例

pygame.math.Vector2.cross()

计算叉或矢量积
cross(Vector2) -> Vector2
计算叉积的第三个分量。
搜索pygame.math.Vector2.cross的示例

pygame.math.Vector2.magnitude()

返回向量的欧几里德矢量大小。
magnitude() -> float
根据以下定理计算矢量的大小:vec.large() == math.sqrt(vec.x**2+vec.y**2)
搜索pygame.math.Vector2.magnitude的示例

pygame.math.Vector2.magnitude_squared()

返回向量的平方大小。
magnitude_squared() -> float
根据以下定理计算矢量的大小:vec.large_squared() == vec.x**2+vec.y**2这比vec.large()快,因为它避免了平方根。
搜索pygame.math.Vector2.magnitude_squared的示例

pygame.math.Vector2.length()

返回向量的欧几里德长度。
length() -> float
根据勾股定理计算向量的欧几里得长度:vec.length() == math.sqrt(vec.x**2+vec.y**2)
搜索pygame.math.Vector2.length的示例

pygame.math.Vector2.length_squared()
  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值