Package net.minecraft.util.math
Class Vec3d
java.lang.Object
net.minecraft.util.math.Vec3d
- All Implemented Interfaces:
Position
public class Vec3d extends Object implements Position
An immutable vector composed of 3 doubles.
This vector class is used for representing position, velocity, rotation, color, etc.
This vector has proper hashCode() and equals(Object)
implementations and can be used as a map key.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Vec3dadd(double x, double y, double z)Returns the sum of this vector and the given vector.Vec3dadd(Vec3d vec)Returns the sum of this vector and the given vector.Vec3dcrossProduct(Vec3d vec)Returns the cross product of this vector and the given vector.doubledistanceTo(Vec3d vec)Returns the distance between this vector and the given vector.doubledotProduct(Vec3d vec)Returns the dot product of this vector and the given vector.booleanequals(Object o)Vec3dfloorAlongAxes(EnumSet<Direction.Axis> axes)Applies the floor function to the coordinates chosen by the given axes.static Vec3dfromPolar(float pitch, float yaw)Converts pitch and yaw into a direction vector.static Vec3dfromPolar(Vec2f polar)Converts pitch and yaw into a direction vector.doublegetComponentAlongAxis(Direction.Axis axis)Returns the coordinate chosen by the given axis.doublegetX()Returns the X coordinate.doublegetY()Returns the Y coordinate.doublegetZ()Returns the Z coordinate.inthashCode()booleanisInRange(Position pos, double radius)Checks if the distance between this vector and the given position is less thanradius.doublelength()Returns the length of this vector.doublelengthSquared()Returns the squared length of this vector.Vec3dmultiply(double value)Return a vector whose coordinates are the coordinates of this vector each multiplied by the given scalar value.Vec3dmultiply(double x, double y, double z)Returns a vector whose coordinates are the product of each pair of coordinates in this vector and the given vector.Vec3dmultiply(Vec3d vec)Returns a vector whose coordinates are the product of each pair of coordinates in this vector and the given vector.Vec3dnegate()Creates a vector with the same length but with the opposite direction.Vec3dnormalize()Normalizes this vector.static Vec3dof(Vec3i vec)Copies the given vector.static Vec3dofBottomCenter(Vec3i vec)Creates a vector representing the bottom center of the given block position.static Vec3dofCenter(Vec3i vec)Creates a vector representing the center of the given block position.static Vec3dofCenter(Vec3i vec, double deltaY)Creates a vector representing the center of the given block position but with the given offset for the Y coordinate.Vec3drelativize(Vec3d vec)Subtracts this vector from the given vector.Vec3drotateX(float angle)Rotates this vector by the given angle counterclockwise around the X axis.Vec3drotateY(float angle)Rotates this vector by the given angle counterclockwise around the Y axis.Vec3drotateZ(float angle)Rotates this vector by the given angle counterclockwise around the Z axis.doublesquaredDistanceTo(double x, double y, double z)Returns the squared distance between this vector and the given vector.doublesquaredDistanceTo(Vec3d vec)Returns the squared distance between this vector and the given vector.Vec3dsubtract(double x, double y, double z)Subtracts the given vector from this vector.Vec3dsubtract(Vec3d vec)Subtracts the given vector from this vector.StringtoString()static Vec3dunpackRgb(int rgb)Converts a packed RGB color into a vector of (red, green, blue).
-
Field Details
-
ZERO
The zero vector (0, 0, 0). -
x
public final double xThe X coordinate of this vector. -
y
public final double yThe Y coordinate of this vector. -
z
public final double zThe Z coordinate of this vector.
-
-
Constructor Details
-
Vec3d
public Vec3d(double x, double y, double z)Creates a vector of the given coordinates. -
Vec3d
Copies the given vector.
-
-
Method Details
-
unpackRgb
Converts a packed RGB color into a vector of (red, green, blue).- Parameters:
rgb- the color in the 0xRRGGBB format- Returns:
- the vector representing the given color; each coordinate has value between 0 and 1
-
ofCenter
Creates a vector representing the center of the given block position. -
of
Copies the given vector. -
ofBottomCenter
Creates a vector representing the bottom center of the given block position.The bottom center of a block position
posis(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5).- See Also:
ofCenter(Vec3i)
-
ofCenter
Creates a vector representing the center of the given block position but with the given offset for the Y coordinate.- Returns:
- a vector of
(vec.getX() + 0.5, vec.getY() + deltaY, vec.getZ() + 0.5)
-
relativize
Subtracts this vector from the given vector.- Returns:
- the difference between the given vector and this vector
- See Also:
subtract(Vec3d)
-
normalize
Normalizes this vector.Normalized vector is a vector with the same direction but with length 1. Each coordinate of normalized vector has value between 0 and 1.
- Returns:
- the normalized vector of this vector
-
dotProduct
Returns the dot product of this vector and the given vector. -
crossProduct
Returns the cross product of this vector and the given vector. -
subtract
Subtracts the given vector from this vector.- Returns:
- the difference between this vector and the given vector
- See Also:
subtract(double, double, double),relativize(Vec3d)
-
subtract
Subtracts the given vector from this vector.- Returns:
- the difference between this vector and the given vector
- See Also:
relativize(Vec3d)
-
add
Returns the sum of this vector and the given vector.- See Also:
add(double, double, double)
-
add
Returns the sum of this vector and the given vector.- See Also:
add(Vec3d)
-
isInRange
Checks if the distance between this vector and the given position is less thanradius. -
distanceTo
Returns the distance between this vector and the given vector.- See Also:
squaredDistanceTo(Vec3d)
-
squaredDistanceTo
Returns the squared distance between this vector and the given vector.Can be used for fast comparison between distances.
-
squaredDistanceTo
public double squaredDistanceTo(double x, double y, double z)Returns the squared distance between this vector and the given vector.Can be used for fast comparison between distances.
- See Also:
squaredDistanceTo(Vec3d),distanceTo(Vec3d)
-
multiply
Return a vector whose coordinates are the coordinates of this vector each multiplied by the given scalar value.- See Also:
multiply(Vec3d),multiply(double, double, double)
-
negate
Creates a vector with the same length but with the opposite direction. -
multiply
Returns a vector whose coordinates are the product of each pair of coordinates in this vector and the given vector.- See Also:
multiply(double, double, double),multiply(double)
-
multiply
Returns a vector whose coordinates are the product of each pair of coordinates in this vector and the given vector.- See Also:
multiply(Vec3d),multiply(double)
-
length
public double length()Returns the length of this vector.The length of a vector is equivalent to the distance between that vector and the ZERO vector.
- See Also:
lengthSquared()
-
lengthSquared
public double lengthSquared()Returns the squared length of this vector.Can be used for fast comparison between lengths.
- See Also:
length()
-
equals
-
hashCode
public int hashCode() -
toString
-
rotateX
Rotates this vector by the given angle counterclockwise around the X axis.- Parameters:
angle- the angle in radians
-
rotateY
Rotates this vector by the given angle counterclockwise around the Y axis.- Parameters:
angle- the angle in radians
-
rotateZ
Rotates this vector by the given angle counterclockwise around the Z axis.- Parameters:
angle- the angle in radians
-
fromPolar
Converts pitch and yaw into a direction vector.- Parameters:
polar- the vector composed of pitch and yaw- See Also:
fromPolar(float, float)
-
fromPolar
Converts pitch and yaw into a direction vector.- See Also:
fromPolar(Vec2f)
-
floorAlongAxes
Applies the floor function to the coordinates chosen by the given axes. -
getComponentAlongAxis
Returns the coordinate chosen by the given axis. -
getX
public final double getX()Returns the X coordinate. -
getY
public final double getY()Returns the Y coordinate. -
getZ
public final double getZ()Returns the Z coordinate.
-