Package jme3utilities.math
Class VectorXZ
java.lang.Object
jme3utilities.math.VectorXZ
- All Implemented Interfaces:
com.jme3.export.Savable,Comparable<ReadXZ>,ReadXZ
Single-precision vector with no 'y' coordinate, used to represent horizontal
locations, offsets, orientations, directions, rotations, and extents.
Immutable except for
read(com.jme3.export.JmeImporter). For viewport
coordinates, use Vector2f instead.
By convention, +X is north/forward and +Z is east/right.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final VectorXZbackward directionstatic final VectorXZeast direction on mapstatic final VectorXZforward directionstatic final VectorXZleft turn/rotationstatic final Loggermessage logger for this classstatic final VectorXZnorth direction on mapstatic final VectorXZright turn/rotationstatic final VectorXZsouth direction on mapstatic final VectorXZwest direction on mapstatic final VectorXZa zero vector -
Constructor Summary
ConstructorsConstructorDescriptionVectorXZ()Instantiate a zero vector.VectorXZ(float azimuth) Instantiate a unit vector from an azimuth value.VectorXZ(float x, float z) Instantiate a vector from a pair of coordinate values.VectorXZ(com.jme3.math.Vector3f vector3D) Instantiate a vector by projecting a 3-D vector onto the X-Z plane. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaboutEquals(ReadXZ otherVector, float absoluteTolerance) Test for approximate equality with another vector using a Chebyshev metric.Add to (translate) this vector.floatazimuth()Determine the azimuth of this vector.Convert this vector to one of the 4 cardinal directions.clampDirection(float maxAbsAngle) Clamp this vector to be within a specified angle of north (the +X axis).clampElliptical(float maxX, float maxZ) Clamp this vector to be within an origin-centered, axis-aligned ellipse.clampLength(float radius) Clamp this vector to be within an origin-centered circle.intcompareTo(float hX, float hZ) Compare lexicographically with a hypothetical vector having the specified components, distinguishing 0 and -0 and giving priority to the X components.intCompare lexicographically with another vector, with the X-component having priority.doublecosineAngleBetween(ReadXZ otherVector) Determine the cosine of the angle between this vector and another.floatDetermine the (left-handed) cross product of this vector with another.floatdirectionError(ReadXZ directionGoal) Determine a signed directional error of this vector with respect to a goal.divide(float scalar) Divide this vector by a scalar.doubleDetermine the dot (scalar) product of this vector with another.booleanequals(float hX, float hZ) Test for equality with a hypothetical vector having the specified components, distinguishing 0 and -0.booleanTest for exact equivalence with another Object, distinguishing 0 and -0.Mirror (or reflect) this vector to the first quadrant.floatgetX()Read the X-component of this vector.floatgetZ()Read the Z-component of this vector.inthashCode()Generate the hash code for this vector.interpolate(ReadXZ otherVector, float otherFraction) Interpolate (blend) this vector with another.booleanTest whether this vector is in the first quadrant.booleanisZero()Test whether this vector is a zero vector.floatlength()Determine the length (or magnitude or norm) of this vector.doubleDetermine the squared length of this vector.mirrorZ()Mirror (or reflect) this vector across the X-axis (complex conjugate or inverse rotation).mult(float multiplier) Scale this vector by a scalar.Multiply this vector by another (complex product or rotate-and-scale).negate()Negate this vector (or reverse its direction or reflect it in the origin).Normalize this vector to a unit vector.voidread(com.jme3.export.JmeImporter importer) De-serialize this instance, for example when loading from a J3O file.rotate(float radians) Rotate a vector CLOCKWISE about the +Y axis.Scale this vector by another (non-uniform scaling).Subtract from (inverse translate) this vector.com.jme3.math.QuaternionTreating this vector as a rotation (from north), generate an equivalent Quaternion.com.jme3.math.QuaterniontoQuaternion(com.jme3.math.Quaternion storeResult) Treating this vector as a rotation (from north), generate an equivalent Quaternion.toString()Represent this vector as a text string.com.jme3.math.Vector3fCreate an equivalent 3-D vector.com.jme3.math.Vector3ftoVector3f(float y) Create an equivalent 3-D vector with the specified y value.com.jme3.math.Vector3ftoVector3f(float y, com.jme3.math.Vector3f storeResult) Create an equivalent 3-D vector with the specified y value.static voidvalidateNonZero(ReadXZ vector, String description) Validate a non-zero VectorXZ as a method argument.voidwrite(com.jme3.export.JmeExporter exporter) Serialize this instance, for example when saving to a J3O file.
-
Field Details
-
logger
message logger for this class -
backward
backward direction -
east
east direction on map- See Also:
-
Vector3f.UNIT_Z
-
forward
forward direction- See Also:
-
Vector3f.UNIT_X
-
left
left turn/rotation -
north
north direction on map- See Also:
-
Vector3f.UNIT_X
-
right
right turn/rotation- See Also:
-
Vector3f.UNIT_Z
-
south
south direction on map -
west
west direction on map -
zero
a zero vector- See Also:
-
Vector3f.ZERO
-
-
Constructor Details
-
VectorXZ
public VectorXZ()Instantiate a zero vector.- See Also:
-
VectorXZ
public VectorXZ(float azimuth) Instantiate a unit vector from an azimuth value.- Parameters:
azimuth- radians east of north
-
VectorXZ
public VectorXZ(com.jme3.math.Vector3f vector3D) Instantiate a vector by projecting a 3-D vector onto the X-Z plane.- Parameters:
vector3D- the 3-D vector (not null, unaffected)
-
VectorXZ
public VectorXZ(float x, float z) Instantiate a vector from a pair of coordinate values.- Parameters:
x- northing component or X coordinate or cosinez- easting component or Z coordinate or sine
-
-
Method Details
-
validateNonZero
Validate a non-zero VectorXZ as a method argument.- Parameters:
vector- vector to validate (not null, non-zero)description- textual description of the vector- Throws:
IllegalArgumentException- if the vector is zero- See Also:
-
aboutEquals
Test for approximate equality with another vector using a Chebyshev metric.- Specified by:
aboutEqualsin interfaceReadXZ- Parameters:
otherVector- (not null)absoluteTolerance- (≥0)- Returns:
- true if each component differs by tolerance or less, otherwise false
-
add
Add to (translate) this vector. -
azimuth
public float azimuth()Determine the azimuth of this vector. Note: the directional convention is left-handed. If this vector is zero, return zero. -
cardinalize
Convert this vector to one of the 4 cardinal directions. If this vector is zero, return a zero vector.- Specified by:
cardinalizein interfaceReadXZ- Returns:
- a unit vector (4 possible values) or a zero vector
-
clampDirection
Clamp this vector to be within a specified angle of north (the +X axis).- Specified by:
clampDirectionin interfaceReadXZ- Parameters:
maxAbsAngle- tolerance angle in radians (≥0, ≤Pi)- Returns:
- clamped vector with same length
-
clampElliptical
Clamp this vector to be within an origin-centered, axis-aligned ellipse.- Specified by:
clampEllipticalin interfaceReadXZ- Parameters:
maxX- radius of the ellipse in the X-direction (≥0)maxZ- radius of the ellipse in the Z-direction (≥0)- Returns:
- clamped vector with the same direction
-
clampLength
Clamp this vector to be within an origin-centered circle.- Specified by:
clampLengthin interfaceReadXZ- Parameters:
radius- radius of the circle (≥0)- Returns:
- clamped vector with the same direction
- See Also:
-
compareTo
public int compareTo(float hX, float hZ) Compare lexicographically with a hypothetical vector having the specified components, distinguishing 0 and -0 and giving priority to the X components. -
cosineAngleBetween
Determine the cosine of the angle between this vector and another. This is used to compare the similarity of direction vectors. Returns a double-precision value for precise comparisons.- Specified by:
cosineAngleBetweenin interfaceReadXZ- Parameters:
otherVector- the other vector (not null)- Returns:
- the cosine of the angle (≥-1, ≤1) or 1 if either vector is zero
- See Also:
-
Vector3f.angleBetween(com.jme3.math.Vector3f)
-
cross
Determine the (left-handed) cross product of this vector with another. For example, north.cross(east) = +1 and east.cross(north) = -1. -
directionError
Determine a signed directional error of this vector with respect to a goal. The result is positive if the goal is to the right and negative if the goal is to the left.- Specified by:
directionErrorin interfaceReadXZ- Parameters:
directionGoal- goal direction (not null, not zero)- Returns:
- the sine of the angle from the goal, or +/-1 if that angle's magnitude exceeds 90 degrees
-
divide
Divide this vector by a scalar. -
dot
Determine the dot (scalar) product of this vector with another. -
equals
public boolean equals(float hX, float hZ) Test for equality with a hypothetical vector having the specified components, distinguishing 0 and -0. -
firstQuadrant
Mirror (or reflect) this vector to the first quadrant.- Specified by:
firstQuadrantin interfaceReadXZ- Returns:
- a mirrored vector with the same length, both components ≥0
-
getX
public float getX()Read the X-component of this vector. -
getZ
public float getZ()Read the Z-component of this vector. -
interpolate
Interpolate (blend) this vector with another.- Specified by:
interpolatein interfaceReadXZ- Parameters:
otherVector- other vector (not null)otherFraction- how much weight to give to the other vector (≥0, ≤1, 0 → purely this, 1 → purely the other)- Returns:
- a blended vector
-
isFirstQuadrant
public boolean isFirstQuadrant()Test whether this vector is in the first quadrant.- Specified by:
isFirstQuadrantin interfaceReadXZ- Returns:
- true if both components are ≥0, false otherwise
- See Also:
-
isZero
public boolean isZero()Test whether this vector is a zero vector. -
length
public float length()Determine the length (or magnitude or norm) of this vector. -
lengthSquared
public double lengthSquared()Determine the squared length of this vector. This is used to compare the lengths of vectors. Returns a double-precision value for precise comparisons.- Specified by:
lengthSquaredin interfaceReadXZ- Returns:
- the squared length (≥0)
- See Also:
-
mirrorZ
Mirror (or reflect) this vector across the X-axis (complex conjugate or inverse rotation). -
mult
Scale this vector by a scalar. -
mult
Multiply this vector by another (complex product or rotate-and-scale). This is NOT analogous toVector3f.mult(Vector3f), which performs non-uniform scaling. -
negate
Negate this vector (or reverse its direction or reflect it in the origin). This is equivalent to #mult(-1f) -
normalize
Normalize this vector to a unit vector. If this vector is zero, return a zero vector. -
rotate
Rotate a vector CLOCKWISE about the +Y axis. Note: This method is used to apply azimuths, which is why its angle convention is left-handed. -
scale
Scale this vector by another (non-uniform scaling). -
subtract
Subtract from (inverse translate) this vector. -
toQuaternion
public com.jme3.math.Quaternion toQuaternion()Treating this vector as a rotation (from north), generate an equivalent Quaternion.- Specified by:
toQuaternionin interfaceReadXZ- Returns:
- a new Quaternion
-
toQuaternion
public com.jme3.math.Quaternion toQuaternion(com.jme3.math.Quaternion storeResult) Treating this vector as a rotation (from north), generate an equivalent Quaternion.- Specified by:
toQuaternionin interfaceReadXZ- Parameters:
storeResult- storage for the result (modified if not null)- Returns:
- a Quaternion (either storeResult or a new instance, not null)
-
toVector3f
public com.jme3.math.Vector3f toVector3f()Create an equivalent 3-D vector.- Specified by:
toVector3fin interfaceReadXZ- Returns:
- a new 3-D vector with y=0
-
toVector3f
public com.jme3.math.Vector3f toVector3f(float y) Create an equivalent 3-D vector with the specified y value.- Specified by:
toVector3fin interfaceReadXZ- Parameters:
y- the y-coordinate- Returns:
- a new 3-D vector
-
toVector3f
public com.jme3.math.Vector3f toVector3f(float y, com.jme3.math.Vector3f storeResult) Create an equivalent 3-D vector with the specified y value.- Specified by:
toVector3fin interfaceReadXZ- Parameters:
y- the y-coordinatestoreResult- storage for the result (modified if not null)- Returns:
- a 3-D vector (either storeResult or a new instance, not null)
-
compareTo
Compare lexicographically with another vector, with the X-component having priority.- Specified by:
compareToin interfaceComparable<ReadXZ>- Parameters:
otherVector- (not null)- Returns:
- 0 if this vector equals otherVector; negative if this comes before otherVector; positive if this comes after otherVector
-
equals
Test for exact equivalence with another Object, distinguishing 0 and -0. -
hashCode
public int hashCode()Generate the hash code for this vector. -
toString
Represent this vector as a text string. The format is: (x=XX.XXX, z=ZZ.ZZZ) -
read
De-serialize this instance, for example when loading from a J3O file.- Specified by:
readin interfacecom.jme3.export.Savable- Parameters:
importer- (not null)- Throws:
IOException- from importer
-
write
Serialize this instance, for example when saving to a J3O file.- Specified by:
writein interfacecom.jme3.export.Savable- Parameters:
exporter- (not null)- Throws:
IOException- from exporter
-