类 Vector
- 所有已实现的接口:
Cloneable
,ConfigurationSerializable
- 直接已知子类:
BlockVector
clone()
获得一个拷贝.
原文:Represents a mutable vector. Because the components of Vectors are mutable,
storing Vectors long term may be dangerous if passing code modifies the
Vector later. If you want to keep around a Vector, it may be wise to call
clone()
in order to get a copy.
-
字段概要
-
构造器概要
-
方法概要
修饰符和类型方法说明将本向量的坐标加上另一个向量的坐标.float
获取本向量与另一个向量的夹角,用弧度表示.void
检查向量的坐标数值是否均合法.clone()
克隆此向量.将本向量的坐标全部设为另一个向量的坐标.将本向量的坐标设为两个向量的叉积.deserialize
(@NotNull Map<String, Object> args) double
获取本向量与与另一个向量之间的距离.double
获取本向量与与另一个向量之间的距离的平方.将本向量的坐标除以另一个向量的坐标.double
计算本向量与另一个向量的点积,定义为x1*x2+y1*y2+z1*z2.boolean
检查两个对象是否相同.Gets a vector with components that match the provided JOMLVector3d
.Gets a vector with components that match the provided JOMLVector3dc
.Gets a vector with components that match the provided JOMLVector3f
.Gets a vector with components that match the provided JOMLVector3fc
.Gets a vector with components that match the provided JOMLVector3i
.Gets a vector with components that match the provided JOMLVector3ic
.int
获取向下取整的X坐标,这等同于获取包含这个向量的方块的X坐标.int
获取向下取整的Y坐标,这等同于获取包含这个向量的方块的Y坐标.int
获取向下取整的Z坐标,这等同于获取包含这个向量的方块的Z坐标.返回一个新的向量,其坐标为本向量与另一个向量的叉积.static double
获取近似相等的阈值,用于equals().getMaximum
(@NotNull Vector v1, @NotNull Vector v2) 获取两个向量坐标中更大的那些坐标组成的新向量.getMidpoint
(@NotNull Vector other) 获取一个新的向量,它的值为本向量和另一个向量间的连线的中点.getMinimum
(@NotNull Vector v1, @NotNull Vector v2) 获取两个向量坐标中更小的那些坐标组成的新向量.获取一个随机向量,其坐标值均为0到1之间(不含1).double
getX()
获取X坐标.double
getY()
获取Y坐标.double
getZ()
获取Z坐标.int
hashCode()
返回这个向量的哈希码.boolean
判断本向量是否在一个AABB包围盒中.boolean
isInSphere
(@NotNull Vector origin, double radius) 判断本向量是否在一个球形空间中.boolean
Returns if a vector is normalizedboolean
isZero()
Check whether or not each component of this vector is equal to 0.double
length()
获取向量的模值,定义为 sqrt(x^2+y^2+z^2).double
获取向量的模的平方.设置本向量的坐标为两个向量连线的中点.multiply
(double m) 向量的数乘,将向量在所有轴上扩展某个倍数.multiply
(float m) 向量的数乘,将向量在所有轴上扩展某个倍数.multiply
(int m) 向量的数乘,将向量在所有轴上扩展某个倍数.将本向量的坐标乘上另一个向量的坐标.将本向量转化为单位向量(模为1的向量).rotateAroundAxis
(@NotNull Vector axis, double angle) Rotates the vector around a given arbitrary axis in 3 dimensional space.rotateAroundNonUnitAxis
(@NotNull Vector axis, double angle) Rotates the vector around a given arbitrary axis in 3 dimensional space.rotateAroundX
(double angle) Rotates the vector around the x axis.rotateAroundY
(double angle) Rotates the vector around the y axis.rotateAroundZ
(double angle) Rotates the vector around the z axisCreates a Map representation of this class.setX
(double x) 设置X坐标.setX
(float x) 设置X坐标.setX
(int x) 设置X坐标.setY
(double y) 设置Y坐标.setY
(float y) 设置Y坐标.setY
(int y) 设置Y坐标.setZ
(double z) 设置Z坐标.setZ
(float z) 设置Z坐标.setZ
(int z) 设置Z坐标.从本向量的坐标中减去另一个向量的坐标.获取这个向量所在的方块的向量.toLocation
(@NotNull World world) 将向量转换为 Location, 其自转角(也叫偏航角,Yaw)、旋进角(也叫进动角、俯仰角,Pitch)为0.toLocation
(@NotNull World world, float yaw, float pitch) 将向量转换为 Location.toString()
返回这个向量的坐标表示 x,y,z.@NotNull org.joml.Vector3d
Get this vector as a JOMLVector3d
.@NotNull org.joml.Vector3f
Get this vector as a JOMLVector3f
.@NotNull org.joml.Vector3i
Get this vector as a JOMLVector3i
with its components floored.@NotNull org.joml.Vector3i
toVector3i
(int roundingMode) Get this vector as a JOMLVector3i
.zero()
将本向量设为原点向量.
-
字段详细资料
-
x
protected double x -
y
protected double y -
z
protected double z
-
-
构造器详细资料
-
Vector
public Vector()用坐标原点来构造一个向量.原文:Construct the vector with all components as 0.
-
Vector
public Vector(int x, int y, int z) 用给定整数坐标来构造一个向量.原文:Construct the vector with provided integer components.
- 参数:
x
- X坐标y
- Y坐标z
- Z坐标
-
Vector
public Vector(double x, double y, double z) 用给定双精度浮点数坐标来构造一个向量.原文:Construct the vector with provided double components.
- 参数:
x
- X坐标y
- Y坐标z
- Z坐标
-
Vector
public Vector(float x, float y, float z) 用给定单精度浮点数坐标来构造一个向量.原文:Construct the vector with provided float components.
- 参数:
x
- X坐标y
- Y坐标z
- Z坐标
-
-
方法详细资料
-
add
将本向量的坐标加上另一个向量的坐标.原文:Adds a vector to this one
- 参数:
vec
- 另一个向量- 返回:
- 返回自身作为结果向量
-
subtract
从本向量的坐标中减去另一个向量的坐标.原文:Subtracts a vector from this one.
- 参数:
vec
- 另一个向量- 返回:
- 返回自身作为结果向量
-
multiply
将本向量的坐标乘上另一个向量的坐标.译注:这不是叉积也不是点积,只是单纯的乘法.
原文:Multiplies the vector by another.
- 参数:
vec
- 另一个向量- 返回:
- 返回自身作为结果向量
-
divide
将本向量的坐标除以另一个向量的坐标.原文:Divides the vector by another.
- 参数:
vec
- 另一个向量- 返回:
- 返回自身作为结果向量
-
copy
将本向量的坐标全部设为另一个向量的坐标.原文:Copies another vector
- 参数:
vec
- 另一个向量- 返回:
- 返回自身作为结果向量
-
length
public double length()获取向量的模值,定义为 sqrt(x^2+y^2+z^2). 这个方法的返回值没有被缓存,且使用了开销较大的平方以及开根函数, 所以不要反复调用这个方法来获取向量的模值. 当向量的模过大时,开根函数有可能发生溢出,并会返回Double.NaN
.原文:Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2). The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the vector's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the length is too long.
- 返回:
- 模
-
lengthSquared
public double lengthSquared()获取向量的模的平方.原文:Gets the magnitude of the vector squared.
- 返回:
- 模的平方
-
distance
获取本向量与与另一个向量之间的距离. 这个方法的返回值没有被缓存,且使用了开销较大的平方以及开根函数, 所以不要反复调用这个方法来获取向量的模值. 当向量的模过大时,开根函数有可能发生溢出,并会返回Double.NaN
.原文:Get the distance between this vector and another. The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the vector's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the distance is too long.
- 参数:
o
- 给定向量- 返回:
- 距离
-
distanceSquared
获取本向量与与另一个向量之间的距离的平方.原文:Get the squared distance between this vector and another.
- 参数:
o
- 给定向量- 返回:
- 距离的平方
-
angle
获取本向量与另一个向量的夹角,用弧度表示.原文:Gets the angle between this vector and another in radians.
- 参数:
other
- 给定向量- 返回:
- 弧度表示的夹角
-
midpoint
设置本向量的坐标为两个向量连线的中点.原文:Sets this vector to the midpoint between this vector and another.
- 参数:
other
- 给定向量- 返回:
- 返回自身作为结果向量(此时已经是中点向量)
-
getMidpoint
获取一个新的向量,它的值为本向量和另一个向量间的连线的中点.原文:Gets a new midpoint vector between this vector and another.
- 参数:
other
- 给定向量- 返回:
- 一个新的中点向量
-
multiply
向量的数乘,将向量在所有轴上扩展某个倍数.原文:Performs scalar multiplication, multiplying all components with a scalar.
- 参数:
m
- 因数,即数乘的倍数,整数- 返回:
- 返回自身作为结果向量
-
multiply
向量的数乘,将向量在所有轴上扩展某个倍数.原文:Performs scalar multiplication, multiplying all components with a scalar.
- 参数:
m
- 因数,即数乘的倍数,双精度浮点数- 返回:
- 返回自身作为结果向量
-
multiply
向量的数乘,将向量在所有轴上扩展某个倍数.原文:Performs scalar multiplication, multiplying all components with a scalar.
- 参数:
m
- 因数,即数乘的倍数,单精度浮点数- 返回:
- 返回自身作为结果向量
-
dot
计算本向量与另一个向量的点积,定义为x1*x2+y1*y2+z1*z2. 此函数的返回值是个标量.原文:Calculates the dot product of this vector with another. The dot product is defined as x1*x2+y1*y2+z1*z2. The returned value is a scalar.
- 参数:
other
- 给定向量- 返回:
- 点积
-
crossProduct
将本向量的坐标设为两个向量的叉积.其计算过程如下:
- x = y1 * z2 - y2 * z1
- y = z1 * x2 - z2 * x1
- z = x1 * y2 - x2 * y1
译注:叉积是a向量和b向量的垂直向量的积的模,方向使用右手定则判断.
原文:Calculates the cross product of this vector with another. The cross product is defined as...
- 参数:
o
- 给定向量- 返回:
- 返回自身作为结果向量
-
getCrossProduct
返回一个新的向量,其坐标为本向量与另一个向量的叉积. 其计算过程如下:- x = y1 * z2 - y2 * z1
- y = z1 * x2 - z2 * x1
- z = x1 * y2 - x2 * y1
译注:叉积是a向量和b向量的垂直向量的积的模,方向使用右手定则判断.
原文:Calculates the cross product of this vector with another without mutating the original. The cross product is defined as:
- x = y1 * z2 - y2 * z1
- y = z1 * x2 - z2 * x1
- z = x1 * y2 - x2 * y1
- 参数:
o
- 给定向量- 返回:
- 新向量表示叉积的结果
-
normalize
将本向量转化为单位向量(模为1的向量).原文:Converts this vector to a unit vector (a vector with length of 1).
- 返回:
- 返回自身作为结果向量
-
zero
将本向量设为原点向量.原文:Zero this vector's components.
- 返回:
- 返回自身作为结果向量
-
isZero
public boolean isZero()Check whether or not each component of this vector is equal to 0.- 返回:
- true if equal to zero, false if at least one component is non-zero
-
isInAABB
判断本向量是否在一个AABB包围盒中.参数 min 和 max 必须真的是最小坐标和最大坐标,也就是说必须是能构成长方体的对角点.
原文:Returns whether this vector is in an axis-aligned bounding box.
The minimum and maximum vectors given must be truly the minimum and maximum X, Y and Z components.
- 参数:
min
- 最小向量max
- 最大向量- 返回:
- 这个向量是否在这个AABB包围盒中
-
isInSphere
判断本向量是否在一个球形空间中.原文:Returns whether this vector is within a sphere.
- 参数:
origin
- 球心radius
- 半径- 返回:
- 此向量是否在球形空间中
-
isNormalized
public boolean isNormalized()Returns if a vector is normalized- 返回:
- whether the vector is normalised
-
rotateAroundX
Rotates the vector around the x axis.This piece of math is based on the standard rotation matrix for vectors in three dimensional space. This matrix can be found here: Rotation Matrix.
- 参数:
angle
- the angle to rotate the vector about. This angle is passed in radians- 返回:
- the same vector
-
rotateAroundY
Rotates the vector around the y axis.This piece of math is based on the standard rotation matrix for vectors in three dimensional space. This matrix can be found here: Rotation Matrix.
- 参数:
angle
- the angle to rotate the vector about. This angle is passed in radians- 返回:
- the same vector
-
rotateAroundZ
Rotates the vector around the z axisThis piece of math is based on the standard rotation matrix for vectors in three dimensional space. This matrix can be found here: Rotation Matrix.
- 参数:
angle
- the angle to rotate the vector about. This angle is passed in radians- 返回:
- the same vector
-
rotateAroundAxis
@NotNull public @NotNull Vector rotateAroundAxis(@NotNull @NotNull Vector axis, double angle) throws IllegalArgumentException Rotates the vector around a given arbitrary axis in 3 dimensional space.Rotation will follow the general Right-Hand-Rule, which means rotation will be counterclockwise when the axis is pointing towards the observer.
This method will always make sure the provided axis is a unit vector, to not modify the length of the vector when rotating. If you are experienced with the scaling of a non-unit axis vector, you can use
rotateAroundNonUnitAxis(Vector, double)
.- 参数:
axis
- the axis to rotate the vector around. If the passed vector is not of length 1, it gets copied and normalized before using it for the rotation. Please usenormalize()
on the instance before passing it to this methodangle
- the angle to rotate the vector around the axis- 返回:
- the same vector
- 抛出:
IllegalArgumentException
- if the provided axis vector instance is null
-
rotateAroundNonUnitAxis
@NotNull public @NotNull Vector rotateAroundNonUnitAxis(@NotNull @NotNull Vector axis, double angle) throws IllegalArgumentException Rotates the vector around a given arbitrary axis in 3 dimensional space.Rotation will follow the general Right-Hand-Rule, which means rotation will be counterclockwise when the axis is pointing towards the observer.
Note that the vector length will change accordingly to the axis vector length. If the provided axis is not a unit vector, the rotated vector will not have its previous length. The scaled length of the resulting vector will be related to the axis vector. If you are not perfectly sure about the scaling of the vector, use
rotateAroundAxis(Vector, double)
- 参数:
axis
- the axis to rotate the vector around.angle
- the angle to rotate the vector around the axis- 返回:
- the same vector
- 抛出:
IllegalArgumentException
- if the provided axis vector instance is null
-
getX
public double getX()获取X坐标.原文:Gets the X component.
- 返回:
- X坐标
-
getBlockX
public int getBlockX()获取向下取整的X坐标,这等同于获取包含这个向量的方块的X坐标.原文:Gets the floored value of the X component, indicating the block that this vector is contained with.
- 返回:
- 方块的X坐标
-
getY
public double getY()获取Y坐标.原文:Gets the Y component.
- 返回:
- Y坐标
-
getBlockY
public int getBlockY()获取向下取整的Y坐标,这等同于获取包含这个向量的方块的Y坐标.原文:Gets the floored value of the Y component, indicating the block that this vector is contained with.
- 返回:
- 方块的Y坐标
-
getZ
public double getZ()获取Z坐标.原文:Gets the Z component.
- 返回:
- Z坐标
-
getBlockZ
public int getBlockZ()获取向下取整的Z坐标,这等同于获取包含这个向量的方块的Z坐标.原文:Gets the floored value of the Z component, indicating the block that this vector is contained with.
- 返回:
- 方块的Z坐标
-
setX
设置X坐标.原文:Set the X component.
- 参数:
x
- 新的X坐标- 返回:
- 自身向量
-
setX
设置X坐标.原文:Set the X component.
- 参数:
x
- 新的X坐标- 返回:
- 自身向量
-
setX
设置X坐标.原文:Set the X component.
- 参数:
x
- 新的X坐标- 返回:
- 自身向量
-
setY
设置Y坐标.原文:Set the Y component.
- 参数:
y
- 新的Y坐标- 返回:
- 自身向量
-
setY
设置Y坐标.原文:Set the Y component.
- 参数:
y
- 新的Y坐标- 返回:
- 自身向量
-
setY
设置Y坐标.原文:Set the Y component.
- 参数:
y
- 新的Y坐标- 返回:
- 自身向量
-
setZ
设置Z坐标.原文:Set the Z component.
- 参数:
z
- 新的Z坐标- 返回:
- 自身向量
-
setZ
设置Z坐标.原文:Set the Z component.
- 参数:
z
- 新的Z坐标- 返回:
- 自身向量
-
setZ
设置Z坐标.原文:Set the Z component.
- 参数:
z
- 新的Z坐标- 返回:
- 自身向量
-
equals
检查两个对象是否相同.只要两个向量的所有坐标均相同则返回true.这个方法使用模糊匹配来回避浮点错误. 这个误差量(epsilon)可以通过自身恢复,即不会影响向量本身.
原文:Checks to see if two objects are equal.
Only two Vectors can ever return true. This method uses a fuzzy match to account for floating point errors. The epsilon can be retrieved with epsilon.
-
hashCode
public int hashCode()返回这个向量的哈希码.原文:Returns a hash code for this vector
-
clone
克隆此向量.原文:Get a new vector.
-
toString
返回这个向量的坐标表示 x,y,z.Returns this vector's components as x,y,z.
-
toLocation
将向量转换为 Location, 其自转角(也叫偏航角,Yaw)、旋进角(也叫进动角、俯仰角,Pitch)为0.原文:Gets a Location version of this vector with yaw and pitch being 0.
- 参数:
world
- 连接这个Location的World.- 返回:
- 这个Location实例
-
toLocation
将向量转换为 Location.原文:Gets a Location version of this vector.
- 参数:
world
- 连接这个Location的World.yaw
- 期望的自转角(也叫偏航角,Yaw).pitch
- 期望的旋进角(也叫进动角、俯仰角,Pitch).- 返回:
- 这个Location实例
-
toBlockVector
获取这个向量所在的方块的向量.原文:Get the block vector of this vector.
- 返回:
- 一个方块向量.
-
toVector3f
Get this vector as a JOMLVector3f
.- 返回:
- the JOML vector
-
toVector3d
Get this vector as a JOMLVector3d
.- 返回:
- the JOML vector
-
toVector3i
Get this vector as a JOMLVector3i
.- 参数:
roundingMode
- theRoundingMode
to use for this vector's components- 返回:
- the JOML vector
-
toVector3i
Get this vector as a JOMLVector3i
with its components floored.- 返回:
- the JOML vector
- 另请参阅:
-
checkFinite
检查向量的坐标数值是否均合法.原文:Check if each component of this Vector is finite.
- 抛出:
IllegalArgumentException
- 如果任何一维的坐标不合法则抛出
-
getEpsilon
public static double getEpsilon()获取近似相等的阈值,用于equals().原文:Get the threshold used for equals().
- 返回:
- 误差量
-
getMinimum
@NotNull public static @NotNull Vector getMinimum(@NotNull @NotNull Vector v1, @NotNull @NotNull Vector v2) 获取两个向量坐标中更小的那些坐标组成的新向量.译注:即逐个比对两个向量的坐标,均取最小的那个组成一个新的向量.
原文:Gets the minimum components of two vectors.
- 参数:
v1
- 第一个向量v2
- 第二个向量- 返回:
- 最小向量
-
getMaximum
@NotNull public static @NotNull Vector getMaximum(@NotNull @NotNull Vector v1, @NotNull @NotNull Vector v2) 获取两个向量坐标中更大的那些坐标组成的新向量.译注:即逐个比对两个向量的坐标,均取更大的那个组成一个新的向量.
原文:Gets the maximum components of two vectors.
- 参数:
v1
- 第一个向量v2
- 第二个向量- 返回:
- 最大向量
-
getRandom
获取一个随机向量,其坐标值均为0到1之间(不含1).- 返回:
- A random vector.
-
fromJOML
Gets a vector with components that match the provided JOMLVector3f
.- 参数:
vector
- the vector to match- 返回:
- the new vector
-
fromJOML
Gets a vector with components that match the provided JOMLVector3d
.- 参数:
vector
- the vector to match- 返回:
- the new vector
-
fromJOML
Gets a vector with components that match the provided JOMLVector3i
.- 参数:
vector
- the vector to match- 返回:
- the new vector
-
fromJOML
Gets a vector with components that match the provided JOMLVector3fc
.- 参数:
vector
- the vector to match- 返回:
- the new vector
-
fromJOML
Gets a vector with components that match the provided JOMLVector3dc
.- 参数:
vector
- the vector to match- 返回:
- the new vector
-
fromJOML
Gets a vector with components that match the provided JOMLVector3ic
.- 参数:
vector
- the vector to match- 返回:
- the new vector
-
serialize
从接口复制的说明:ConfigurationSerializable
Creates a Map representation of this class.This class must provide a method to restore this class, as defined in the
ConfigurationSerializable
interface javadocs.- 指定者:
serialize
在接口中ConfigurationSerializable
- 返回:
- Map containing the current state of this class
-
deserialize
-