程序包 org.bukkit.util

类 Vector

java.lang.Object
org.bukkit.util.Vector
所有已实现的接口:
Cloneable, ConfigurationSerializable
直接已知子类:
BlockVector

public class Vector extends Object implements Cloneable, ConfigurationSerializable
Vector代表一个可变向量. 这个组件是可变的,长期存储这些向量可能导致问题,因为之后的代码可能对其进行修改. 如果你想要长期存储一个向量,最好使用 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.

  • 字段详细资料

    • 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

      public double distance(@NotNull @NotNull Vector o)
      获取本向量与与另一个向量之间的距离. 这个方法的返回值没有被缓存,且使用了开销较大的平方以及开根函数, 所以不要反复调用这个方法来获取向量的模值. 当向量的模过大时,开根函数有可能发生溢出,并会返回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

      public double distanceSquared(@NotNull @NotNull Vector o)
      获取本向量与与另一个向量之间的距离的平方.

      原文:Get the squared distance between this vector and another.

      参数:
      o - 给定向量
      返回:
      距离的平方
    • angle

      public float angle(@NotNull @NotNull Vector other)
      获取本向量与另一个向量的夹角,用弧度表示.

      原文:Gets the angle between this vector and another in radians.

      参数:
      other - 给定向量
      返回:
      弧度表示的夹角
    • midpoint

      @NotNull public @NotNull Vector midpoint(@NotNull @NotNull Vector other)
      设置本向量的坐标为两个向量连线的中点.

      原文:Sets this vector to the midpoint between this vector and another.

      参数:
      other - 给定向量
      返回:
      返回自身作为结果向量(此时已经是中点向量)
    • getMidpoint

      @NotNull public @NotNull Vector getMidpoint(@NotNull @NotNull Vector other)
      获取一个新的向量,它的值为本向量和另一个向量间的连线的中点.

      原文:Gets a new midpoint vector between this vector and another.

      参数:
      other - 给定向量
      返回:
      一个新的中点向量
    • multiply

      @NotNull public @NotNull Vector multiply(int m)
      向量的数乘,将向量在所有轴上扩展某个倍数.

      原文:Performs scalar multiplication, multiplying all components with a scalar.

      参数:
      m - 因数,即数乘的倍数,整数
      返回:
      返回自身作为结果向量
    • multiply

      @NotNull public @NotNull Vector multiply(double m)
      向量的数乘,将向量在所有轴上扩展某个倍数.

      原文:Performs scalar multiplication, multiplying all components with a scalar.

      参数:
      m - 因数,即数乘的倍数,双精度浮点数
      返回:
      返回自身作为结果向量
    • multiply

      @NotNull public @NotNull Vector multiply(float m)
      向量的数乘,将向量在所有轴上扩展某个倍数.

      原文:Performs scalar multiplication, multiplying all components with a scalar.

      参数:
      m - 因数,即数乘的倍数,单精度浮点数
      返回:
      返回自身作为结果向量
    • dot

      public double dot(@NotNull @NotNull Vector other)
      计算本向量与另一个向量的点积,定义为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

      @NotNull public @NotNull Vector crossProduct(@NotNull @NotNull Vector o)
      将本向量的坐标设为两个向量的叉积.

      其计算过程如下:

      • 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

      @NotNull public @NotNull Vector getCrossProduct(@NotNull @NotNull Vector o)
      返回一个新的向量,其坐标为本向量与另一个向量的叉积. 其计算过程如下:
      • 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

      @NotNull public @NotNull Vector normalize()
      将本向量转化为单位向量(模为1的向量).

      原文:Converts this vector to a unit vector (a vector with length of 1).

      返回:
      返回自身作为结果向量
    • zero

      @NotNull public @NotNull Vector 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

      public boolean isInAABB(@NotNull @NotNull Vector min, @NotNull @NotNull Vector max)
      判断本向量是否在一个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

      public boolean isInSphere(@NotNull @NotNull Vector origin, double radius)
      判断本向量是否在一个球形空间中.

      原文: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

      @NotNull public @NotNull Vector rotateAroundX(double angle)
      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

      @NotNull public @NotNull Vector rotateAroundY(double angle)
      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

      @NotNull public @NotNull Vector rotateAroundZ(double angle)
      Rotates the vector around the z 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
    • 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 use normalize() on the instance before passing it to this method
      angle - 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

      @NotNull public @NotNull Vector setX(int x)
      设置X坐标.

      原文:Set the X component.

      参数:
      x - 新的X坐标
      返回:
      自身向量
    • setX

      @NotNull public @NotNull Vector setX(double x)
      设置X坐标.

      原文:Set the X component.

      参数:
      x - 新的X坐标
      返回:
      自身向量
    • setX

      @NotNull public @NotNull Vector setX(float x)
      设置X坐标.

      原文:Set the X component.

      参数:
      x - 新的X坐标
      返回:
      自身向量
    • setY

      @NotNull public @NotNull Vector setY(int y)
      设置Y坐标.

      原文:Set the Y component.

      参数:
      y - 新的Y坐标
      返回:
      自身向量
    • setY

      @NotNull public @NotNull Vector setY(double y)
      设置Y坐标.

      原文:Set the Y component.

      参数:
      y - 新的Y坐标
      返回:
      自身向量
    • setY

      @NotNull public @NotNull Vector setY(float y)
      设置Y坐标.

      原文:Set the Y component.

      参数:
      y - 新的Y坐标
      返回:
      自身向量
    • setZ

      @NotNull public @NotNull Vector setZ(int z)
      设置Z坐标.

      原文:Set the Z component.

      参数:
      z - 新的Z坐标
      返回:
      自身向量
    • setZ

      @NotNull public @NotNull Vector setZ(double z)
      设置Z坐标.

      原文:Set the Z component.

      参数:
      z - 新的Z坐标
      返回:
      自身向量
    • setZ

      @NotNull public @NotNull Vector setZ(float z)
      设置Z坐标.

      原文:Set the Z component.

      参数:
      z - 新的Z坐标
      返回:
      自身向量
    • equals

      public boolean equals(Object obj)
      检查两个对象是否相同.

      只要两个向量的所有坐标均相同则返回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.

      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      返回这个向量的哈希码.

      原文:Returns a hash code for this vector

      覆盖:
      hashCode 在类中 Object
      返回:
      哈希码
    • clone

      @NotNull public @NotNull Vector clone()
      克隆此向量.

      原文:Get a new vector.

      覆盖:
      clone 在类中 Object
      返回:
      新向量
    • toString

      public String toString()
      返回这个向量的坐标表示 x,y,z.

      Returns this vector's components as x,y,z.

      覆盖:
      toString 在类中 Object
    • toLocation

      @NotNull public @NotNull Location toLocation(@NotNull @NotNull World world)
      将向量转换为 Location, 其自转角(也叫偏航角,Yaw)、旋进角(也叫进动角、俯仰角,Pitch)为0.

      原文:Gets a Location version of this vector with yaw and pitch being 0.

      参数:
      world - 连接这个Location的World.
      返回:
      这个Location实例
    • toLocation

      @NotNull public @NotNull Location toLocation(@NotNull @NotNull World world, float yaw, float pitch)
      将向量转换为 Location.

      原文:Gets a Location version of this vector.

      参数:
      world - 连接这个Location的World.
      yaw - 期望的自转角(也叫偏航角,Yaw).
      pitch - 期望的旋进角(也叫进动角、俯仰角,Pitch).
      返回:
      这个Location实例
    • toBlockVector

      @NotNull public @NotNull BlockVector toBlockVector()
      获取这个向量所在的方块的向量.

      原文:Get the block vector of this vector.

      返回:
      一个方块向量.
    • toVector3f

      @NotNull public @NotNull org.joml.Vector3f toVector3f()
      Get this vector as a JOML Vector3f.
      返回:
      the JOML vector
    • toVector3d

      @NotNull public @NotNull org.joml.Vector3d toVector3d()
      Get this vector as a JOML Vector3d.
      返回:
      the JOML vector
    • toVector3i

      @NotNull public @NotNull org.joml.Vector3i toVector3i(int roundingMode)
      Get this vector as a JOML Vector3i.
      参数:
      roundingMode - the RoundingMode to use for this vector's components
      返回:
      the JOML vector
    • toVector3i

      @NotNull public @NotNull org.joml.Vector3i toVector3i()
      Get this vector as a JOML Vector3i with its components floored.
      返回:
      the JOML vector
      另请参阅:
    • checkFinite

      public void checkFinite() throws IllegalArgumentException
      检查向量的坐标数值是否均合法.

      原文: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

      @NotNull public static @NotNull Vector getRandom()
      获取一个随机向量,其坐标值均为0到1之间(不含1).
      返回:
      A random vector.
    • fromJOML

      @NotNull public static @NotNull Vector fromJOML(@NotNull @NotNull org.joml.Vector3f vector)
      Gets a vector with components that match the provided JOML Vector3f.
      参数:
      vector - the vector to match
      返回:
      the new vector
    • fromJOML

      @NotNull public static @NotNull Vector fromJOML(@NotNull @NotNull org.joml.Vector3d vector)
      Gets a vector with components that match the provided JOML Vector3d.
      参数:
      vector - the vector to match
      返回:
      the new vector
    • fromJOML

      @NotNull public static @NotNull Vector fromJOML(@NotNull @NotNull org.joml.Vector3i vector)
      Gets a vector with components that match the provided JOML Vector3i.
      参数:
      vector - the vector to match
      返回:
      the new vector
    • fromJOML

      @NotNull public static @NotNull Vector fromJOML(@NotNull @NotNull org.joml.Vector3fc vector)
      Gets a vector with components that match the provided JOML Vector3fc.
      参数:
      vector - the vector to match
      返回:
      the new vector
    • fromJOML

      @NotNull public static @NotNull Vector fromJOML(@NotNull @NotNull org.joml.Vector3dc vector)
      Gets a vector with components that match the provided JOML Vector3dc.
      参数:
      vector - the vector to match
      返回:
      the new vector
    • fromJOML

      @NotNull public static @NotNull Vector fromJOML(@NotNull @NotNull org.joml.Vector3ic vector)
      Gets a vector with components that match the provided JOML Vector3ic.
      参数:
      vector - the vector to match
      返回:
      the new vector
    • serialize

      @NotNull public @NotNull Map<String,Object> 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

      @NotNull public static @NotNull Vector deserialize(@NotNull @NotNull Map<String,Object> args)