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的示例