pygame.math
pygame module for vector classes
 pygame.math.Vector2 — a 2-Dimensional Vector pygame.math.Vector3 — a 3-Dimensional Vector

PYGAME数学模块目前提供二维和三维的向量类， Vector2Vector3 分别为。

v = pygame.Vector3()

v.x = 5
v[1] = 2 * v.x
print(v[1]) # 10

v.x == v[0]
v.y == v[1]
v.z == v[2]

v = pygame.Vector2()
v.xy = 1, 2
v[:] = 1, 2

New in pygame 1.9.2pre.

Changed in pygame 1.9.4: 删除了实验通知。

Changed in pygame 1.9.4: 允许像GLSL Vector2(2)==Vector2(2.0，2.0)这样的标量构造

Changed in pygame 1.9.4: 所需的导入。更方便 pygame.Vector2pygame.Vector3

pygame.math.Vector2
a 2-Dimensional Vector
Vector2() -> Vector2
Vector2(int) -> Vector2
Vector2(float) -> Vector2
Vector2(Vector2) -> Vector2
Vector2(x, y) -> Vector2
Vector2((x, y)) -> Vector2
 pygame.math.Vector2.dot — calculates the dot- or scalar-product with the other vector pygame.math.Vector2.cross — calculates the cross- or vector-product pygame.math.Vector2.magnitude — returns the Euclidean magnitude of the vector. pygame.math.Vector2.magnitude_squared — returns the squared magnitude of the vector. pygame.math.Vector2.length — returns the Euclidean length of the vector. pygame.math.Vector2.length_squared — returns the squared Euclidean length of the vector. pygame.math.Vector2.normalize — returns a vector with the same direction but length 1. pygame.math.Vector2.normalize_ip — normalizes the vector in place so that its length is 1. pygame.math.Vector2.is_normalized — tests if the vector is normalized i.e. has length == 1. pygame.math.Vector2.scale_to_length — scales the vector to a given length. pygame.math.Vector2.reflect — returns a vector reflected of a given normal. pygame.math.Vector2.reflect_ip — reflect the vector of a given normal in place. pygame.math.Vector2.distance_to — calculates the Euclidean distance to a given vector. pygame.math.Vector2.distance_squared_to — calculates the squared Euclidean distance to a given vector. pygame.math.Vector2.move_towards — returns a vector moved toward the target by a given distance. pygame.math.Vector2.move_towards_ip — moves the vector toward its target at a given distance. pygame.math.Vector2.lerp — returns a linear interpolation to the given vector. pygame.math.Vector2.slerp — returns a spherical interpolation to the given vector. pygame.math.Vector2.elementwise — The next operation will be performed elementwise. pygame.math.Vector2.rotate — rotates a vector by a given angle in degrees. pygame.math.Vector2.rotate_rad — rotates a vector by a given angle in radians. pygame.math.Vector2.rotate_ip — rotates the vector by a given angle in degrees in place. pygame.math.Vector2.rotate_ip_rad — rotates the vector by a given angle in radians in place. pygame.math.Vector2.rotate_rad_ip — rotates the vector by a given angle in radians in place. pygame.math.Vector2.angle_to — calculates the angle to a given vector in degrees. pygame.math.Vector2.as_polar — returns a tuple with radial distance and azimuthal angle. pygame.math.Vector2.from_polar — Sets x and y from a polar coordinates tuple. pygame.math.Vector2.project — projects a vector onto another. pygame.math.Vector2.copy — Returns a copy of itself. pygame.math.Vector2.clamp_magnitude — Returns a copy of a vector with the magnitude clamped between max_length and min_length. pygame.math.Vector2.clamp_magnitude_ip — Clamps the vector's magnitude between max_length and min_length pygame.math.Vector2.update — Sets the coordinates of the vector.

Changed in pygame 2.1.3: 矢量子类的继承方法现在正确返回子类的实例，而不是超类

dot()
calculates the dot- or scalar-product with the other vector
dot(Vector2) -> float
cross()
calculates the cross- or vector-product
cross(Vector2) -> Vector2

magnitude()
returns the Euclidean magnitude of the vector.
magnitude() -> float

magnitude_squared()
returns the squared magnitude of the vector.
magnitude_squared() -> float

length()
returns the Euclidean length of the vector.
length() -> float

length_squared()
returns the squared Euclidean length of the vector.
length_squared() -> float

normalize()
returns a vector with the same direction but length 1.
normalize() -> Vector2

normalize_ip()
normalizes the vector in place so that its length is 1.
normalize_ip() -> None

is_normalized()
tests if the vector is normalized i.e. has length == 1.
is_normalized() -> Bool

scale_to_length()
scales the vector to a given length.
scale_to_length(float) -> None

reflect()
returns a vector reflected of a given normal.
reflect(Vector2) -> Vector2

reflect_ip()
reflect the vector of a given normal in place.
reflect_ip(Vector2) -> None

distance_to()
calculates the Euclidean distance to a given vector.
distance_to(Vector2) -> float
distance_squared_to()
calculates the squared Euclidean distance to a given vector.
distance_squared_to(Vector2) -> float
move_towards()
returns a vector moved toward the target by a given distance.
move_towards(Vector2, float) -> Vector2

New in pygame 2.1.3.

move_towards_ip()
moves the vector toward its target at a given distance.
move_towards_ip(Vector2, float) -> None

New in pygame 2.1.3.

lerp()
returns a linear interpolation to the given vector.
lerp(Vector2, float) -> Vector2

slerp()
returns a spherical interpolation to the given vector.
slerp(Vector2, float) -> Vector2

elementwise()
The next operation will be performed elementwise.
elementwise() -> VectorElementwiseProxy

rotate()
rotates a vector by a given angle in degrees.
rotate(angle) -> Vector2

rotates a vector by a given angle in radians.

New in pygame 2.0.0.

rotate_ip()
rotates the vector by a given angle in degrees in place.
rotate_ip(angle) -> None

rotates the vector by a given angle in radians in place.

New in pygame 2.0.0.

Deprecated since pygame 2.1.1.

rotates the vector by a given angle in radians in place.

New in pygame 2.1.1.

angle_to()
calculates the angle to a given vector in degrees.
angle_to(Vector2) -> float

as_polar()
returns a tuple with radial distance and azimuthal angle.
as_polar() -> (r, phi)

from_polar()
Sets x and y from a polar coordinates tuple.
from_polar((r, phi)) -> None

project()
projects a vector onto another.
project(Vector2) -> Vector2

New in pygame 2.0.2.

copy()
Returns a copy of itself.
copy() -> Vector2

New in pygame 2.1.1.

clamp_magnitude()
Returns a copy of a vector with the magnitude clamped between max_length and min_length.
clamp_magnitude(max_length) -> Vector2
clamp_magnitude(min_length, max_length) -> Vector2

New in pygame 2.1.3.

clamp_magnitude_ip()
Clamps the vector's magnitude between max_length and min_length
clamp_magnitude_ip(max_length) -> None
clamp_magnitude_ip(min_length, max_length) -> None

New in pygame 2.1.3.

update()
Sets the coordinates of the vector.
update() -> None
update(int) -> None
update(float) -> None
update(Vector2) -> None
update(x, y) -> None
update((x, y)) -> None

New in pygame 1.9.5.

pygame.math.Vector3
a 3-Dimensional Vector
Vector3() -> Vector3
Vector3(int) -> Vector3
Vector3(float) -> Vector3
Vector3(Vector3) -> Vector3
Vector3(x, y, z) -> Vector3
Vector3((x, y, z)) -> Vector3

Changed in pygame 2.1.3: 矢量子类的继承方法现在正确返回子类的实例，而不是超类

dot()
calculates the dot- or scalar-product with the other vector
dot(Vector3) -> float
cross()
calculates the cross- or vector-product
cross(Vector3) -> Vector3

magnitude()
returns the Euclidean magnitude of the vector.
magnitude() -> float

magnitude_squared()
returns the squared Euclidean magnitude of the vector.
magnitude_squared() -> float

length()
returns the Euclidean length of the vector.
length() -> float

length_squared()
returns the squared Euclidean length of the vector.
length_squared() -> float

normalize()
returns a vector with the same direction but length 1.
normalize() -> Vector3

normalize_ip()
normalizes the vector in place so that its length is 1.
normalize_ip() -> None

is_normalized()
tests if the vector is normalized i.e. has length == 1.
is_normalized() -> Bool

scale_to_length()
scales the vector to a given length.
scale_to_length(float) -> None

reflect()
returns a vector reflected of a given normal.
reflect(Vector3) -> Vector3

reflect_ip()
reflect the vector of a given normal in place.
reflect_ip(Vector3) -> None

distance_to()
calculates the Euclidean distance to a given vector.
distance_to(Vector3) -> float
distance_squared_to()
calculates the squared Euclidean distance to a given vector.
distance_squared_to(Vector3) -> float
move_towards()
returns a vector moved toward the target by a given distance.
move_towards(Vector3, float) -> Vector3

New in pygame 2.1.3.

move_towards_ip()
moves the vector toward its target at a given distance.
move_towards_ip(Vector3, float) -> None

New in pygame 2.1.3.

lerp()
returns a linear interpolation to the given vector.
lerp(Vector3, float) -> Vector3

slerp()
returns a spherical interpolation to the given vector.
slerp(Vector3, float) -> Vector3

elementwise()
The next operation will be performed elementwise.
elementwise() -> VectorElementwiseProxy

rotate()
rotates a vector by a given angle in degrees.
rotate(angle, Vector3) -> Vector3

rotates a vector by a given angle in radians.

New in pygame 2.0.0.

rotate_ip()
rotates the vector by a given angle in degrees in place.
rotate_ip(angle, Vector3) -> None

rotates the vector by a given angle in radians in place.

New in pygame 2.0.0.

Deprecated since pygame 2.1.1.

rotates the vector by a given angle in radians in place.

New in pygame 2.1.1.

rotate_x()
rotates a vector around the x-axis by the angle in degrees.
rotate_x(angle) -> Vector3

rotates a vector around the x-axis by the angle in radians.

New in pygame 2.0.0.

rotate_x_ip()
rotates the vector around the x-axis by the angle in degrees in place.
rotate_x_ip(angle) -> None

rotates the vector around the x-axis by the angle in radians in place.

New in pygame 2.0.0.

Deprecated since pygame 2.1.1.

rotates the vector around the x-axis by the angle in radians in place.

New in pygame 2.1.1.

rotate_y()
rotates a vector around the y-axis by the angle in degrees.
rotate_y(angle) -> Vector3

rotates a vector around the y-axis by the angle in radians.

New in pygame 2.0.0.

rotate_y_ip()
rotates the vector around the y-axis by the angle in degrees in place.
rotate_y_ip(angle) -> None

rotates the vector around the y-axis by the angle in radians in place.

New in pygame 2.0.0.

Deprecated since pygame 2.1.1.

rotates the vector around the y-axis by the angle in radians in place.

New in pygame 2.1.1.

rotate_z()
rotates a vector around the z-axis by the angle in degrees.
rotate_z(angle) -> Vector3

rotates a vector around the z-axis by the angle in radians.

New in pygame 2.0.0.

rotate_z_ip()
rotates the vector around the z-axis by the angle in degrees in place.
rotate_z_ip(angle) -> None

rotates the vector around the z-axis by the angle in radians in place.

Deprecated since pygame 2.1.1.

rotates the vector around the z-axis by the angle in radians in place.

New in pygame 2.1.1.

angle_to()
calculates the angle to a given vector in degrees.
angle_to(Vector3) -> float

as_spherical()
returns a tuple with radial distance, inclination and azimuthal angle.
as_spherical() -> (r, theta, phi)

from_spherical()
Sets x, y and z from a spherical coordinates 3-tuple.
from_spherical((r, theta, phi)) -> None

project()
projects a vector onto another.
project(Vector3) -> Vector3

New in pygame 2.0.2.

copy()
Returns a copy of itself.
copy() -> Vector3

New in pygame 2.1.1.

clamp_magnitude()
Returns a copy of a vector with the magnitude clamped between max_length and min_length.
clamp_magnitude(max_length) -> Vector3
clamp_magnitude(min_length, max_length) -> Vector3

New in pygame 2.1.3.

clamp_magnitude_ip()
Clamps the vector's magnitude between max_length and min_length
clamp_magnitude_ip(max_length) -> None
clamp_magnitude_ip(min_length, max_length) -> None

New in pygame 2.1.3.

update()
Sets the coordinates of the vector.
update() -> None
update(int) -> None
update(float) -> None
update(Vector3) -> None
update(x, y, z) -> None
update((x, y, z)) -> None

New in pygame 1.9.5.

Edit on GitHub