vmm3d.core3D
Class Vector3D
- java.lang.Object
-
- vmm3d.core3D.Vector3D
-
public class Vector3D extends java.lang.ObjectA 3D vector with components of type double named x, y, and z.
-
-
Field Summary
Fields Modifier and Type Field and Description static Vector3DORIGINThe origin, (0,0,0).static Vector3DUNIT_XThe unit vector in the x direction, (1,0,0).static Vector3DUNIT_YThe unit vector in the y direction, (0,1,0).static Vector3DUNIT_ZThe uint vector in the z direction, (0,0,1).doublexThe first component of the vector.doubleyThe second component of the vector.doublezThe third component of the vector.
-
Constructor Summary
Constructors Constructor and Description Vector3D()Construct a vector with all three components initially equal to zero.Vector3D(double x, double y, double z)Construct a vector that initially has coordinates (x,y,z).Vector3D(Vector3D v)Construct a vector that is initially a copy of a specified vector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidassign(Vector3D v)this.assign(v) assigns to this the value v.voidassignLinComb(double c, double d, Vector3D v)this.assignLinComb(c,d,v) assigns to this the value c*this + d*v.voidassignLinComb(double c, Vector3D v, double d, Vector3D w)this.assignLinComb(c,v,d,w) assigns to this the value c*v + d*w.voidassignMinus(Vector3D v)this.assignMinus(v) assigns to this the value this (- v).voidassignMinus(Vector3D v, Vector3D w)this.assignMinus(v, w) assigns to this the value this (v - w).voidassignPlus_SumTimes(Vector3D u, Vector3D v, Vector3D w, Vector3D ww, double d)this.assignPlus_SumTimes(u, v, w, ww, d) assigns to this the value: this + (u + v + w + ww)*d.voidassignPlus(Vector3D v)this.assignPlus(v) assigns to this the value this + v.voidassignSum(Vector3D v, Vector3D w)this.assignSum(v,w) assigns to this the value v + w.voidassignSumTimes(Vector3D v, Vector3D w, double d)this.assignSumTimes(v, w, d) assigns to this the value (v + w)*d.voidassignSumTimes(Vector3D v, Vector3D w, Vector3D vv, Vector3D ww, double d)this.assignSumTimes(v, w, vv, ww, d) assigns to this the value (v + w + vv + ww)*d.voidassignTimes(double d)this.assignTimes(d) assigns to this the value d*this.voidassignTimes(double d, Vector3D v)this.assignTimes(d, v) assigns to this the value d*v.Vector3Dcross(Vector3D v)Returns the cross product of this vector and v.doubledot(Vector3D v)Returns the dot product of this vector and v.booleanequals(java.lang.Object obj)Returns trueobjis a non-null object whose class in Vector3D and such that the three corrdinates of the vectorobjare the same as the coordinates of this vector.static Vector3DfromString(java.lang.String str)Attempts to convert a string into a value of type Vector3D.Vector3DlinComb(double c, double d, Vector3D v)Returns the linear combination c*this + d*v.Vector3Dminus(Vector3D v)Returns the vector difference of this vector and v.voidnegate()Multiplies each component of this vector by -1.Vector3Dnegated()Returns a new vector that is equal to -1 times this vector.doublenorm()Returns the length of this vector, computed asMath.sqrt(x*x+y*y+z*z)doublenorm2()Returns the length^2 of this vector, computed as(x*x+y*y+z*z)voidnormalize()Divides each component of the vector by the norm of the vector, giving a vector that has length 1.Vector3Dnormalized()Returns a new vector that is equal to this vector normalized.Vector3Dplus(Vector3D v)Returns the vector sum of this vector and v.Vector3DreflectInAxis(Vector3D axis)Rotates this around the unit vector axis by 180 degrees: this to -this + 2*axis. Vector3Dtimes(double d)Returns the scalar product of this vector times d.java.lang.StringtoString()Returns a string representation of this vector of the form "(x,y,z)" where x, y, and z are the numerical components of the vector.
-
-
-
Field Detail
-
x
public double x
The first component of the vector.
-
y
public double y
The second component of the vector.
-
z
public double z
The third component of the vector.
-
ORIGIN
public static final Vector3D ORIGIN
The origin, (0,0,0).
-
UNIT_X
public static final Vector3D UNIT_X
The unit vector in the x direction, (1,0,0).
-
UNIT_Y
public static final Vector3D UNIT_Y
The unit vector in the y direction, (0,1,0).
-
UNIT_Z
public static final Vector3D UNIT_Z
The uint vector in the z direction, (0,0,1).
-
-
Constructor Detail
-
Vector3D
public Vector3D()
Construct a vector with all three components initially equal to zero.
-
Vector3D
public Vector3D(double x, double y, double z)Construct a vector that initially has coordinates (x,y,z).
-
Vector3D
public Vector3D(Vector3D v)
Construct a vector that is initially a copy of a specified vector.- Parameters:
v- the constructed vector is (v.x, v.y, v.z), or is (0,0,0) if v is null.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
Returns trueobjis a non-null object whose class in Vector3D and such that the three corrdinates of the vectorobjare the same as the coordinates of this vector.- Overrides:
equalsin classjava.lang.Object
-
norm
public double norm()
Returns the length of this vector, computed asMath.sqrt(x*x+y*y+z*z)
-
norm2
public double norm2()
Returns the length^2 of this vector, computed as(x*x+y*y+z*z)
-
normalize
public void normalize()
Divides each component of the vector by the norm of the vector, giving a vector that has length 1. However, if the vector is zero, or if any of its components are infinite or undefined, then the result of calling this method is to set all the components of the vector to Double.NaN. This method modifies the vector.- See Also:
normalized()
-
negate
public void negate()
Multiplies each component of this vector by -1. This method modifies the vector.- See Also:
negated()
-
normalized
public Vector3D normalized()
Returns a new vector that is equal to this vector normalized. This vector is not modified.- See Also:
normalize()
-
negated
public Vector3D negated()
Returns a new vector that is equal to -1 times this vector. This vector is not modified.- See Also:
negate()
-
plus
public Vector3D plus(Vector3D v)
Returns the vector sum of this vector and v. A new vector object is constructed to contain the result; neither input vector is modified.- Parameters:
v- a non-null vector
-
linComb
public Vector3D linComb(double c, double d, Vector3D v)
Returns the linear combination c*this + d*v. A new vector object contains the result.
-
assign
public void assign(Vector3D v)
this.assign(v) assigns to this the value v.
-
assignPlus
public void assignPlus(Vector3D v)
this.assignPlus(v) assigns to this the value this + v.
-
assignSum
public void assignSum(Vector3D v, Vector3D w)
this.assignSum(v,w) assigns to this the value v + w.
-
assignLinComb
public void assignLinComb(double c, double d, Vector3D v)this.assignLinComb(c,d,v) assigns to this the value c*this + d*v.
-
assignLinComb
public void assignLinComb(double c, Vector3D v, double d, Vector3D w)this.assignLinComb(c,v,d,w) assigns to this the value c*v + d*w.
-
assignPlus_SumTimes
public void assignPlus_SumTimes(Vector3D u, Vector3D v, Vector3D w, Vector3D ww, double d)
this.assignPlus_SumTimes(u, v, w, ww, d) assigns to this the value: this + (u + v + w + ww)*d.
-
minus
public Vector3D minus(Vector3D v)
Returns the vector difference of this vector and v. A new vector object is constructed to contain the result; neither input vector is modified.- Parameters:
v- a non-null vector
-
assignMinus
public void assignMinus(Vector3D v)
this.assignMinus(v) assigns to this the value this (- v).
-
assignMinus
public void assignMinus(Vector3D v, Vector3D w)
this.assignMinus(v, w) assigns to this the value this (v - w).
-
times
public Vector3D times(double d)
Returns the scalar product of this vector times d. A new vector object is constructed to contain the result; the vector is not modified.- Parameters:
d- the scalar that is to be multiplied times this vector
-
assignTimes
public void assignTimes(double d)
this.assignTimes(d) assigns to this the value d*this.
-
assignTimes
public void assignTimes(double d, Vector3D v)this.assignTimes(d, v) assigns to this the value d*v.
-
assignSumTimes
public void assignSumTimes(Vector3D v, Vector3D w, double d)
this.assignSumTimes(v, w, d) assigns to this the value (v + w)*d.
-
assignSumTimes
public void assignSumTimes(Vector3D v, Vector3D w, Vector3D vv, Vector3D ww, double d)
this.assignSumTimes(v, w, vv, ww, d) assigns to this the value (v + w + vv + ww)*d.
-
dot
public double dot(Vector3D v)
Returns the dot product of this vector and v. A new vector object is constructed to contain the result; neither input vector is modified.- Parameters:
v- a non-null vector
-
cross
public Vector3D cross(Vector3D v)
Returns the cross product of this vector and v. A new vector object is constructed to contain the result; neither input vector is modified.- Parameters:
v- a non-null vector
-
reflectInAxis
public Vector3D reflectInAxis(Vector3D axis)
Rotates this around the unit vector axis by 180 degrees: this to -this + 2*axis. Call as this.reflectInAxis(axis).
-
toString
public java.lang.String toString()
Returns a string representation of this vector of the form "(x,y,z)" where x, y, and z are the numerical components of the vector. The special strings NaN, INF and -INF are used to represent the values Double.NaN, Double.POSITIVE_INFINITY, and Double.NEGATIVE_INFINITY.- Overrides:
toStringin classjava.lang.Object
-
fromString
public static Vector3D fromString(java.lang.String str) throws java.lang.NumberFormatException
Attempts to convert a string into a value of type Vector3D. The string should be in the format produced bytoString(), of the form "(x,y,z)". Will also accept strings that use a space as a separator and are not enclosed in parentheses, of the form "x y z".- Parameters:
str- the non-null string that is to be converted- Throws:
java.lang.NumberFormatException- if the string is not of the correct format (or is null)
-
-
DMelt 3.0 © DataMelt by jWork.ORG