public class Vec3d
extends java.lang.Object
implements java.lang.Cloneable
Methods with names ending in "Local" modify the current instance. They are used to avoid creating temporary vectors.
The conventional order of components is (X, Y, Z).
| Modifier and Type | Field and Description |
|---|---|
static Vec3d |
UNIT_X
Shared instance of the +X direction (1,0,0).
|
static Vec3d |
UNIT_Y
Shared instance of the +Y direction (0,1,0).
|
static Vec3d |
UNIT_Z
Shared instance of the +Z direction (0,0,1).
|
double |
x
The first (X) component.
|
double |
y
The 2nd (Y) component.
|
double |
z
The 3rd (Z) component.
|
static Vec3d |
ZERO
Shared instance of the all-zero vector (0,0,0).
|
| Constructor and Description |
|---|
Vec3d()
Instantiates an all-zero vector (0,0,0).
|
Vec3d(double x,
double y,
double z)
Instantiates a vector with the specified components.
|
Vec3d(Vec3d v)
Instantiates a copy of the argument.
|
Vec3d(Vector3f v)
Instantiates a double-precision copy of the argument.
|
| Modifier and Type | Method and Description |
|---|---|
Vec3d |
add(double vx,
double vy,
double vz)
Adds specified amounts to the vector's components and returns the sum as
a new instance.
|
Vec3d |
add(Vec3d v)
Adds the argument and returns the sum as a new instance.
|
Vec3d |
addLocal(double vx,
double vy,
double vz)
Adds specified amounts to the vector's components and returns the
(modified) current instance.
|
Vec3d |
addLocal(Vec3d v)
Adds the argument and returns the (modified) current instance.
|
Vec3d |
clone()
Creates a copy.
|
Vec3d |
cross(Vec3d v)
Calculates a cross product with the argument and returns the product as a
new instance.
|
Vec3d |
divideLocal(Vec3d v)
Divides component-wise by the argument and returns the (modified) current
instance.
|
double |
dot(Vec3d v)
Returns the dot (or inner) product with the argument.
|
boolean |
equals(java.lang.Object o)
Tests for exact equality with the argument, distinguishing -0 from 0.
|
double |
get(int i)
Returns the indexed component.
|
int |
hashCode()
Returns a hash code.
|
boolean |
isFinite()
Tests for finite components.
|
double |
length()
Returns the length (or magnitude).
|
double |
lengthSq()
Returns the square of the length.
|
Vec3d |
multLocal(double s)
Multiplies by the scalar argument and returns the (modified) current
instance.
|
Vec3d |
multLocal(Vec3d v)
Multiplies component-wise by the argument and returns the (modified)
current instance.
|
Vec3d |
normalizeLocal()
Normalize this vector in place.
|
Vec3d |
set(double x,
double y,
double z)
Sets all 3 components to specified values.
|
Vec3d |
set(int i,
double d)
Alters the indexed component.
|
Vec3d |
set(Vec3d v)
Copies all 3 components from the argument.
|
Vec3d |
set(Vector3f v)
Copies all 3 components from the argument, converting them to
double precision.
|
Vec3d |
subtract(Vec3d v)
Subtracts the argument and returns the difference as a new instance.
|
Vec3d |
subtractLocal(Vec3d v)
Subtracts the argument and returns the (modified) current instance.
|
java.lang.String |
toString()
Returns a string representation of the vector, which is unaffected.
|
Vector3f |
toVector3f()
Creates a single-precision copy of the current instance.
|
public static final Vec3d UNIT_X
public static final Vec3d UNIT_Y
public static final Vec3d UNIT_Z
public static final Vec3d ZERO
public double x
public double y
public double z
public Vec3d()
public Vec3d(double x,
double y,
double z)
x - the desired X componenty - the desired Y componentz - the desired Z componentpublic Vec3d(Vec3d v)
v - the Vec3d to copy (not null, unaffected)public Vec3d(Vector3f v)
v - the input Vector3f (not null, unaffected)public Vector3f toVector3f()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
o is null, false is returned. Either way, the current instance is
unaffected.equals in class java.lang.Objecto - the object to compare (may be null, unaffected)this and o have identical values,
otherwise falsepublic boolean isFinite()
public final Vec3d set(double x, double y, double z)
x - the desired X componenty - the desired Y componentz - the desired Z componentpublic final Vec3d set(Vec3d v)
v - the Vec3d to copy (not null, unaffected)public final Vec3d set(Vector3f v)
v - the Vector3f to copy (not null, unaffected)public final Vec3d clone()
clone in class java.lang.Objectpublic double get(int i)
i - 0, 1, or 2java.lang.IndexOutOfBoundsException - if i is not 0, 1, or 2public Vec3d set(int i, double d)
i - which component to set: 0 → the X component, 1 →
the Y component, 2 → the Z componentd - the desired component valuejava.lang.IllegalArgumentException - if i is not 0, 1, or 2public final Vec3d add(Vec3d v)
v - the vector to add (not null, unaffected)public final Vec3d add(double vx, double vy, double vz)
vx - the amount to add to the X componentvy - the amount to add to the Y componentvz - the amount to add to the Z componentpublic final Vec3d subtract(Vec3d v)
v - the vector to subtract (not null, unaffected)public final Vec3d addLocal(Vec3d v)
It IS safe for v and this to be the same object.
v - the vector to add (not null, unaffected unless it's
this)public final Vec3d addLocal(double vx, double vy, double vz)
vx - the amount to add to the X componentvy - the amount to add to the Y componentvz - the amount to add to the Z componentpublic final Vec3d subtractLocal(Vec3d v)
It IS safe for v and this to be the same object.
v - the vector to subtract (not null, unaffected unless it's
this)public final Vec3d multLocal(double s)
s - the scaling factorpublic final Vec3d multLocal(Vec3d v)
It IS safe for v and this to be the same object.
v - the scale vector (not null, unaffected unless it's this)public final Vec3d divideLocal(Vec3d v)
It IS safe for v and this to be the same object.
v - the divisor (not null, unaffected unless it's this)public final double lengthSq()
public final double length()
public final Vec3d normalizeLocal()
public final double dot(Vec3d v)
v - the vector to multiply (not null, unaffected)public final Vec3d cross(Vec3d v)
v - the right factor (not null, unaffected)this cross v (a new Vec3d)public java.lang.String toString()
Vec3d[1.0, 0.0, 0.0]
toString in class java.lang.Object