public class Vector extends java.lang.Object implements java.lang.Cloneable, ConfigurationSerializable
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.
构造器和说明 |
---|
Vector()
用坐标原点来构造一个向量.
|
Vector(double x,
double y,
double z)
用给定双精度浮点数坐标来构造一个向量.
|
Vector(float x,
float y,
float z)
用给定单精度浮点数坐标来构造一个向量.
|
Vector(int x,
int y,
int z)
用给定整数坐标来构造一个向量.
|
限定符和类型 | 方法和说明 |
---|---|
Vector |
add(Vector vec)
将本向量的坐标加上另一个向量的坐标.
|
float |
angle(Vector other)
获取本向量与另一个向量的夹角,用弧度表示.
|
void |
checkFinite()
检查向量的坐标数值是否均合法.
|
Vector |
clone()
克隆此向量.
|
Vector |
copy(Vector vec)
将本向量的坐标全部设为另一个向量的坐标.
|
Vector |
crossProduct(Vector o)
将本向量的坐标设为两个向量的叉积.
|
static Vector |
deserialize(java.util.Map<java.lang.String,java.lang.Object> args) |
double |
distance(Vector o)
获取本向量与与另一个向量之间的距离.
|
double |
distanceSquared(Vector o)
获取本向量与与另一个向量之间的距离的平方.
|
Vector |
divide(Vector vec)
将本向量的坐标除以另一个向量的坐标.
|
double |
dot(Vector other)
计算本向量与另一个向量的点积,定义为x1*x2+y1*y2+z1*z2.
|
boolean |
equals(java.lang.Object obj)
检查两个对象是否相同.
|
int |
getBlockX()
获取向下取整的X坐标,这等同于获取包含这个向量的方块的X坐标.
|
int |
getBlockY()
获取向下取整的Y坐标,这等同于获取包含这个向量的方块的Y坐标.
|
int |
getBlockZ()
获取向下取整的Z坐标,这等同于获取包含这个向量的方块的Z坐标.
|
Vector |
getCrossProduct(Vector o)
返回一个新的向量,其坐标为本向量与另一个向量的叉积.
|
static double |
getEpsilon()
获取近似相等的阈值,用于equals().
|
static Vector |
getMaximum(Vector v1,
Vector v2)
获取两个向量坐标中更大的那些坐标组成的新向量.
|
Vector |
getMidpoint(Vector other)
获取一个新的向量,它的值为本向量和另一个向量间的连线的中点.
|
static Vector |
getMinimum(Vector v1,
Vector v2)
获取两个向量坐标中更小的那些坐标组成的新向量.
|
static Vector |
getRandom()
获取一个随机向量,其坐标值均为0到1之间(不含1).
|
double |
getX()
获取X坐标.
|
double |
getY()
获取Y坐标.
|
double |
getZ()
获取Z坐标.
|
int |
hashCode()
返回这个向量的哈希码.
|
boolean |
isInAABB(Vector min,
Vector max)
判断本向量是否在一个AABB包围盒中.
|
boolean |
isInSphere(Vector origin,
double radius)
判断本向量是否在一个球形空间中.
|
double |
length()
获取向量的模值,定义为 sqrt(x^2+y^2+z^2).
|
double |
lengthSquared()
获取向量的模的平方.
|
Vector |
midpoint(Vector other)
设置本向量的坐标为两个向量连线的中点.
|
Vector |
multiply(double m)
向量的数乘,将向量在所有轴上扩展某个倍数.
|
Vector |
multiply(float m)
向量的数乘,将向量在所有轴上扩展某个倍数.
|
Vector |
multiply(int m)
向量的数乘,将向量在所有轴上扩展某个倍数.
|
Vector |
multiply(Vector vec)
将本向量的坐标乘上另一个向量的坐标.
|
Vector |
normalize()
将本向量转化为单位向量(模为1的向量).
|
java.util.Map<java.lang.String,java.lang.Object> |
serialize()
Creates a Map representation of this class.
|
Vector |
setX(double x)
设置X坐标.
|
Vector |
setX(float x)
设置X坐标.
|
Vector |
setX(int x)
设置X坐标.
|
Vector |
setY(double y)
设置Y坐标.
|
Vector |
setY(float y)
设置Y坐标.
|
Vector |
setY(int y)
设置Y坐标.
|
Vector |
setZ(double z)
设置Z坐标.
|
Vector |
setZ(float z)
设置Z坐标.
|
Vector |
setZ(int z)
设置Z坐标.
|
Vector |
subtract(Vector vec)
从本向量的坐标中减去另一个向量的坐标.
|
BlockVector |
toBlockVector()
获取这个向量所在的方块的向量.
|
Location |
toLocation(World world)
将向量转换为 Location,
其自转角(也叫偏航角,Yaw)、旋进角(也叫进动角、俯仰角,Pitch)为0.
|
Location |
toLocation(World world,
float yaw,
float pitch)
将向量转换为 Location.
|
java.lang.String |
toString()
返回这个向量的坐标表示 x,y,z.
|
Vector |
zero()
将本向量设为原点向量.
|
public Vector()
原文:Construct the vector with all components as 0.
public Vector(int x, int y, int z)
原文:Construct the vector with provided integer components.
x
- X坐标y
- Y坐标z
- Z坐标public Vector(double x, double y, double z)
原文:Construct the vector with provided double components.
x
- X坐标y
- Y坐标z
- Z坐标public Vector(float x, float y, float z)
原文:Construct the vector with provided float components.
x
- X坐标y
- Y坐标z
- Z坐标public Vector add(Vector vec)
原文:Adds a vector to this one
vec
- 另一个向量public Vector subtract(Vector vec)
原文:Subtracts a vector from this one.
vec
- 另一个向量public Vector multiply(Vector vec)
译注:这不是叉积也不是点积,只是单纯的乘法.
原文:Multiplies the vector by another.
vec
- 另一个向量public Vector divide(Vector vec)
原文:Divides the vector by another.
vec
- 另一个向量public Vector copy(Vector vec)
原文:Copies another vector
vec
- 另一个向量public double length()
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.
public double lengthSquared()
原文:Gets the magnitude of the vector squared.
public double distance(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
- 给定向量public double distanceSquared(Vector o)
原文:Get the squared distance between this vector and another.
o
- 给定向量public float angle(Vector other)
原文:Gets the angle between this vector and another in radians.
other
- 给定向量public Vector midpoint(Vector other)
原文:Sets this vector to the midpoint between this vector and another.
other
- 给定向量public Vector getMidpoint(Vector other)
原文:Gets a new midpoint vector between this vector and another.
other
- 给定向量public Vector multiply(int m)
原文:Performs scalar multiplication, multiplying all components with a scalar.
m
- 因数,即数乘的倍数,整数public Vector multiply(double m)
原文:Performs scalar multiplication, multiplying all components with a scalar.
m
- 因数,即数乘的倍数,双精度浮点数public Vector multiply(float m)
原文:Performs scalar multiplication, multiplying all components with a scalar.
m
- 因数,即数乘的倍数,单精度浮点数public double dot(Vector other)
原文: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
- 给定向量public Vector crossProduct(Vector o)
其计算过程如下:
译注:叉积是a向量和b向量的垂直向量的积的模,方向使用右手定则判断.
原文:Calculates the cross product of this vector with another. The cross product is defined as...
o
- 给定向量public Vector getCrossProduct(Vector o)
译注:叉积是a向量和b向量的垂直向量的积的模,方向使用右手定则判断.
原文:Calculates the cross product of this vector with another without mutating the original. The cross product is defined as:
o
- 给定向量public Vector normalize()
原文:Converts this vector to a unit vector (a vector with length of 1).
public Vector zero()
原文:Zero this vector's components.
public boolean isInAABB(Vector min, Vector max)
参数 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
- 最大向量public boolean isInSphere(Vector origin, double radius)
原文:Returns whether this vector is within a sphere.
origin
- 球心radius
- 半径public double getX()
原文:Gets the X component.
public int getBlockX()
原文:Gets the floored value of the X component, indicating the block that this vector is contained with.
public double getY()
原文:Gets the Y component.
public int getBlockY()
原文:Gets the floored value of the Y component, indicating the block that this vector is contained with.
public double getZ()
原文:Gets the Z component.
public int getBlockZ()
原文:Gets the floored value of the Z component, indicating the block that this vector is contained with.
public Vector setX(int x)
原文:Set the X component.
x
- 新的X坐标public Vector setX(double x)
原文:Set the X component.
x
- 新的X坐标public Vector setX(float x)
原文:Set the X component.
x
- 新的X坐标public Vector setY(int y)
原文:Set the Y component.
y
- 新的Y坐标public Vector setY(double y)
原文:Set the Y component.
y
- 新的Y坐标public Vector setY(float y)
原文:Set the Y component.
y
- 新的Y坐标public Vector setZ(int z)
原文:Set the Z component.
z
- 新的Z坐标public Vector setZ(double z)
原文:Set the Z component.
z
- 新的Z坐标public Vector setZ(float z)
原文:Set the Z component.
z
- 新的Z坐标public boolean equals(java.lang.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
在类中 java.lang.Object
public int hashCode()
原文:Returns a hash code for this vector
hashCode
在类中 java.lang.Object
public Vector clone()
原文:Get a new vector.
clone
在类中 java.lang.Object
public java.lang.String toString()
Returns this vector's components as x,y,z.
toString
在类中 java.lang.Object
public Location toLocation(World world)
原文:Gets a Location version of this vector with yaw and pitch being 0.
world
- 连接这个Location的World.public Location toLocation(World world, float yaw, float pitch)
原文:Gets a Location version of this vector.
world
- 连接这个Location的World.yaw
- 期望的自转角(也叫偏航角,Yaw).pitch
- 期望的旋进角(也叫进动角、俯仰角,Pitch).public BlockVector toBlockVector()
原文:Get the block vector of this vector.
public void checkFinite() throws java.lang.IllegalArgumentException
原文:Check if each component of this Vector is finite.
java.lang.IllegalArgumentException
- 如果任何一维的坐标不合法则抛出public static double getEpsilon()
原文:Get the threshold used for equals().
public static Vector getMinimum(Vector v1, Vector v2)
译注:即逐个比对两个向量的坐标,均取最小的那个组成一个新的向量.
原文:Gets the minimum components of two vectors.
v1
- 第一个向量v2
- 第二个向量public static Vector getMaximum(Vector v1, Vector v2)
译注:即逐个比对两个向量的坐标,均取更大的那个组成一个新的向量.
原文:Gets the maximum components of two vectors.
v1
- 第一个向量v2
- 第二个向量public static Vector getRandom()
public java.util.Map<java.lang.String,java.lang.Object> serialize()
ConfigurationSerializable
This class must provide a method to restore this class, as defined in
the ConfigurationSerializable
interface javadocs.
serialize
在接口中 ConfigurationSerializable
public static Vector deserialize(java.util.Map<java.lang.String,java.lang.Object> args)