mikera.vectorz
Class Vector3
- java.lang.Object
-
- mikera.arrayz.impl.AbstractArray<java.lang.Double>
-
- mikera.vectorz.AVector
-
- mikera.vectorz.impl.APrimitiveVector
-
- mikera.vectorz.Vector3
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<INDArray>, java.lang.Iterable<java.lang.Double>, INDArray, IVector
public final class Vector3 extends APrimitiveVector
Specialised 3D vector Represents a point in 3D x,y,z space.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Vector3()Vector3(AVector v)Vector3(double... values)Vector3(double x, double y, double z)Vector3(Vector3 source)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(AVector v)Adds another vector to this onevoidadd(double constant)Adds a double value to all elements in this array.voidadd(double dx, double dy, double dz)voidadd(Vector3 v)voidaddAt(int i, double value)Adds a value to a specific element of the vector This function does not perform bounds checking, i.e.Vector3addCopy(AVector v)Adds a vector element-wise to this vector, returning a new vector.Vector3addCopy(Vector3 v)voidaddMultiple(AVector v, double factor)Adds a scaled multiple of another vector to this vectorvoidaddMultiple(double dx, double dy, double dz, double factor)voidaddMultiple(Vector3 v, double factor)voidaddProduct(Vector3 a, Vector3 b)voidaddProduct(Vector3 a, Vector3 b, double factor)doubleangle(AVector v)Returns the Euclidean angle between this vector and another vectordoubleangle(Vector3 v)voidapplyOp(Op op)Applies a unary operator to all elements of the array (in-place)Vector3clone()Clones the vector, creating a new mutable copy of all data.Vector3copy()Returns a defensive copy of the array data.static Vector3create(AVector v)static Vector3create(java.lang.Object o)voidcrossProduct(AVector a)Computes the crossProduct of this vector with another vector, and stores the result in this vector.voidcrossProduct(Vector3 a)Computes the crossProduct of this vector with another vector, and stores the result in this vector.doubledistance(AVector v)Returns the Euclidean distance to another vector.doubledistance(Vector3 v)doubledistanceSquared(Vector3 v)doubledotProduct(AVector v)Returns the dot product of this vector with another vector The vectors must have the same length: if not the result is undefineddoubledotProduct(double[] data, int offset)Fast dot product with a double[] array.doubledotProduct(Vector3 a)doubleelementProduct()Returns the product of all elements in the array.doubleelementSquaredSum()Returns the sum of squared elements in this array.doubleelementSum()Returns the sum of all elements in a vectorbooleanequals(AVector v)Returns true if this array is exactly equal to a vector.booleanequals(Vector3 v)booleanequalsArray(double[] data, int offset)Returns true if this vector exactly matches the elements in double[] array, starting from the specified offsetVector3exactClone()Returns an exact clone of this vector, i.e.voidfill(double v)Fills the entire vector with a given valuedoubleget(int i)Returns the double value at the specified position in a 1D vectorvoidgetElements(double[] data, int offset)Copies all elements of this array a double array at the specified offsetdoublegetX()doublegetY()doublegetZ()booleanisZero()Returns true if this vector is a zero vector (all components zero)intlength()Returns the length of a vector, in terms of the number of elements.doublemagnitude()Returns the magnitude (Euclidean length) of the vectorvoidmultiply(double d)Multiplies the vector by a constant factorVector3multiplyCopy(double d)Returns a copy of the array with all elements multiplied by a single constant valuevoidnegate()Negates all emlements of this vector in place.Vector3negateCopy()Negates all elements in the array, returning a new arraydoublenormalise()Normalises this vector to a magnitude of 1.0 Has no effect on a zero-length vector (i.e.static Vector3of(double... values)static Vector3of(double x, double y, double z)voidprojectToPlane(AVector normal, double distance)Projects the vector to the plane defined by: x.normal=distancevoidprojectToPlane(Vector3 normal, double distance)doublereduce(Op2 op)Reduces over all elements of the array in row-major order.doublereduce(Op2 op, double init)Reduces over all elements of the array in row-major order.voidscaleAdd(double factor, AVector constant)Scales this vector then adds another vectorvoidscaleAdd(double factor, double constant)Scales this vector and adds a constant to every elementvoidscaleAdd(double factor, Vector3 constant)voidset(AVector v)Sets the vector to equal the value of another vectorvoidset(int i, double value)Sets a value at a given position in a mutable 1D arrayvoidset(Vector3 a)voidsetValues(double x, double y, double z)voidsub(Vector3 v)voidsubMultiple(Vector3 v, double factor)voidsubtractMultiple(Vector3 v, double factor)double[]toDoubleArray()Copies the elements of this array to a new double[] array.voidtoDoubleBuffer(java.nio.DoubleBuffer dest)Copies the elements of this INDArray to the specified double buffer.Vector3toNormal()Creates a new mutable vector representing the normalised value of this vector Returns null if the vector cannot be normalised (i.e.doubleunsafeGet(int i)Like get, but performs no bounds checking.voidunsafeSet(int i, double value)Like set, but performs no bounds checking.-
Methods inherited from class mikera.vectorz.impl.APrimitiveVector
getT, isFullyMutable, isMutable, isView, sparse, sparseClone, visitNonZero
-
Methods inherited from class mikera.vectorz.AVector
abs, absCopy, absDiff, absDiff, absDiff, absDiffCopy, add, add, add, add, add, add, add, addAt, addCopy, addCopy, addInnerProduct, addInnerProduct, addInnerProduct, addInnerProduct, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultiple, addMultipleCopy, addMultipleSparse, addMultipleSparse, addMultipleToArray, addMultipleToArray, addPower, addPower, addProduct, addProduct, addProduct, addProductCopy, addProductCopy, addProductToArray, addProductToArray, addSparse, addSparse, addToArray, addToArray, addToArray, addWeighted, applyOp, applyOp, applyOp, applyOp, applyOpCopy, asDoubleArray, asElementList, asVector, broadcast, broadcastLike, broadcastLike, broadcastLike, checkIndex, checkLength, checkRange, clamp, clampMax, clampMin, compareTo, compareTo, copyTo, copyTo, copyTo, copyTo, copyTo, dense, denseClone, dimensionality, distanceL1, distanceLinf, distanceSquared, divide, divide, divide, divide, divideCopy, divideCopy, divideCopy, divideTo, dotProduct, dotProduct, dotProduct, elementAbsPowSum, elementCount, elementIterator, elementMax, elementMaxAbs, elementMin, elementPowSum, elementsEqual, epsilonEquals, epsilonEquals, epsilonEquals, equals, equals, equalsArray, fillRange, get, get, get, get, get, get, getElement, getElements, getElements, getLongShape, getShape, getShape, getShapeClone, getSlices, getTranspose, getTransposeCopy, getTransposeView, hashCode, hasUncountable, immutable, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, innerProduct, interpolate, isElementConstrained, isRangeZero, isSameShape, isSameShape, isUnitLengthVector, isUnitLengthVector, iterator, join, join, join, log, logistic, magnitudeSquared, maxAbsElement, maxAbsElementIndex, maxElement, maxElementIndex, minElement, minElementIndex, multiply, multiply, multiply, multiply, multiplyCopy, multiplyCopy, multiplyTo, mutable, nonSparseIndex, nonZeroCount, nonZeroIndices, nonZeroValues, normaliseCopy, normaliseMaxAbsElement, outerProduct, outerProduct, pow, reciprocal, reciprocalCopy, reduceSlices, reduceSlices, reorder, reorder, reshape, rotateCopy, rotateView, rotateView, scale, scaleAdd, scaleAdd, scaleCopy, scaleToMagnitude, select, selectClone, selectView, set, set, set, set, set, set, set, set, set, setApplyOp, setApplyOp, setApplyOp, setElements, setElements, setElements, setInnerProduct, setInnerProduct, setInnerProduct, setMultiple, setMultiple, setMultiple, setMultiple, setSparse, setSparse, setSparse, shiftCopy, signum, slice, slice, sliceCount, sliceValue, softmax, softmaxCopy, sqrtCopy, square, squareCopy, sub, sub, subArray, subAt, subCopy, subCopy, subMultiple, subVector, tanh, toList, toSliceArray, toString, toStringFull, toVector, tryEfficientJoin, validate
-
Methods inherited from class mikera.arrayz.impl.AbstractArray
add, addApplyOp, addCopy, addInnerProduct, addInnerProduct, addOuterProduct, addOuterProductSparse, addSparse, broadcastCloneLike, broadcastCopyLike, componentCount, density, ensureMutable, epsilonEquals, exp, get, get, getComponent, getComponents, getElements, getElements, getSlices, getSliceViews, isBoolean, isDense, isSparse, scale, set, set, signumCopy, sqrt, sub, sub, withComponents
-
Methods inherited from interface mikera.arrayz.INDArray
addApplyOp, addInnerProduct, addOuterProduct, addOuterProductSparse, addSparse, broadcastCloneLike, broadcastCopyLike, componentCount, ensureMutable, epsilonEquals, exp, get, get, getComponent, getComponents, getElements, getElements, getSlices, getSliceViews, isBoolean, isDense, isSparse, scale, set, set, signumCopy, sqrt, sub, withComponents
-
-
-
-
Constructor Detail
-
Vector3
public Vector3()
-
Vector3
public Vector3(Vector3 source)
-
Vector3
public Vector3(double x, double y, double z)
-
Vector3
public Vector3(double... values)
-
Vector3
public Vector3(AVector v)
-
-
Method Detail
-
applyOp
public void applyOp(Op op)
Description copied from interface:INDArrayApplies a unary operator to all elements of the array (in-place)
-
reduce
public double reduce(Op2 op, double init)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the initial/previous result at each step. Returns the final result.
-
reduce
public double reduce(Op2 op)
Description copied from interface:INDArrayReduces over all elements of the array in row-major order. Applies the operator to the previous result at each step. Returns the final result.
-
normalise
public double normalise()
Description copied from class:AVectorNormalises this vector to a magnitude of 1.0 Has no effect on a zero-length vector (i.e. it will remain zero)
-
of
public static Vector3 of(double x, double y, double z)
-
of
public static Vector3 of(double... values)
-
create
public static Vector3 create(java.lang.Object o)
-
isZero
public boolean isZero()
Description copied from class:AVectorReturns true if this vector is a zero vector (all components zero)
-
angle
public double angle(AVector v)
Description copied from class:AVectorReturns the Euclidean angle between this vector and another vector
-
angle
public double angle(Vector3 v)
-
add
public void add(double dx, double dy, double dz)
-
elementSquaredSum
public double elementSquaredSum()
Description copied from interface:INDArrayReturns the sum of squared elements in this array.- Specified by:
elementSquaredSumin interfaceINDArray- Overrides:
elementSquaredSumin classAVector
-
distanceSquared
public double distanceSquared(Vector3 v)
-
distance
public double distance(Vector3 v)
-
distance
public double distance(AVector v)
Description copied from class:AVectorReturns the Euclidean distance to another vector.
-
magnitude
public double magnitude()
Description copied from class:AVectorReturns the magnitude (Euclidean length) of the vector
-
set
public void set(Vector3 a)
-
multiply
public void multiply(double d)
Description copied from class:AVectorMultiplies the vector by a constant factor
-
multiplyCopy
public Vector3 multiplyCopy(double d)
Description copied from interface:INDArrayReturns a copy of the array with all elements multiplied by a single constant value- Specified by:
multiplyCopyin interfaceINDArray- Overrides:
multiplyCopyin classAVector- Parameters:
d- A scalar factor- Returns:
- A new array, with all element values scaled by the given factor
-
addMultiple
public void addMultiple(double dx, double dy, double dz, double factor)
-
addMultiple
public void addMultiple(AVector v, double factor)
Description copied from class:AVectorAdds a scaled multiple of another vector to this vector- Overrides:
addMultiplein classAVector
-
addMultiple
public void addMultiple(Vector3 v, double factor)
-
subtractMultiple
public void subtractMultiple(Vector3 v, double factor)
-
add
public void add(AVector v)
Description copied from class:AVectorAdds another vector to this one
-
addCopy
public Vector3 addCopy(AVector v)
Description copied from interface:IVectorAdds a vector element-wise to this vector, returning a new vector.
-
add
public void add(Vector3 v)
-
sub
public void sub(Vector3 v)
-
subMultiple
public void subMultiple(Vector3 v, double factor)
-
dotProduct
public double dotProduct(Vector3 a)
-
dotProduct
public double dotProduct(AVector v)
Description copied from class:AVectorReturns the dot product of this vector with another vector The vectors must have the same length: if not the result is undefined- Overrides:
dotProductin classAVector- Returns:
-
dotProduct
public double dotProduct(double[] data, int offset)Description copied from class:AVectorFast dot product with a double[] array. Performs no bounds checking. Likely to be faster than most other dot product operations- Specified by:
dotProductin classAVector
-
crossProduct
public void crossProduct(AVector a)
Description copied from class:AVectorComputes the crossProduct of this vector with another vector, and stores the result in this vector. Both vectors must have length 3.- Overrides:
crossProductin classAVector
-
crossProduct
public void crossProduct(Vector3 a)
Description copied from class:AVectorComputes the crossProduct of this vector with another vector, and stores the result in this vector. Both vectors must have length 3.- Overrides:
crossProductin classAVector
-
projectToPlane
public void projectToPlane(AVector normal, double distance)
Description copied from class:AVectorProjects the vector to the plane defined by: x.normal=distance- Overrides:
projectToPlanein classAVector- Parameters:
normal- A Vector of unit length
-
projectToPlane
public void projectToPlane(Vector3 normal, double distance)
-
length
public int length()
Description copied from interface:IVectorReturns the length of a vector, in terms of the number of elements. For Euclidean length, use magnitude() instead
-
elementSum
public double elementSum()
Description copied from class:AVectorReturns the sum of all elements in a vector- Specified by:
elementSumin interfaceINDArray- Overrides:
elementSumin classAVector
-
elementProduct
public double elementProduct()
Description copied from interface:INDArrayReturns the product of all elements in the array.- Specified by:
elementProductin interfaceINDArray- Overrides:
elementProductin classAVector- Returns:
-
scaleAdd
public void scaleAdd(double factor, double constant)Description copied from class:AVectorScales this vector and adds a constant to every element
-
scaleAdd
public void scaleAdd(double factor, AVector constant)Description copied from class:AVectorScales this vector then adds another vector
-
scaleAdd
public void scaleAdd(double factor, Vector3 constant)
-
add
public void add(double constant)
Description copied from interface:INDArrayAdds a double value to all elements in this array. Implementations may optimize the case of 0.0
-
get
public double get(int i)
Description copied from interface:INDArrayReturns the double value at the specified position in a 1D vector
-
unsafeGet
public double unsafeGet(int i)
Description copied from class:AVectorLike get, but performs no bounds checking. Results are undefined if the index is out of range
-
set
public void set(AVector v)
Description copied from class:AVectorSets the vector to equal the value of another vector
-
fill
public void fill(double v)
Description copied from class:AVectorFills the entire vector with a given value
-
set
public void set(int i, double value)Description copied from interface:INDArraySets a value at a given position in a mutable 1D array
-
unsafeSet
public void unsafeSet(int i, double value)Description copied from class:AVectorLike set, but performs no bounds checking. Results are undefined if the index is out of range
-
addAt
public void addAt(int i, double value)Description copied from class:AVectorAdds a value to a specific element of the vector This function does not perform bounds checking, i.e. is an unsafe operation
-
setValues
public void setValues(double x, double y, double z)
-
negate
public void negate()
Description copied from class:AVectorNegates all emlements of this vector in place.
-
negateCopy
public Vector3 negateCopy()
Description copied from interface:INDArrayNegates all elements in the array, returning a new array- Specified by:
negateCopyin interfaceINDArray- Overrides:
negateCopyin classAVector
-
getElements
public void getElements(double[] data, int offset)Description copied from interface:INDArrayCopies all elements of this array a double array at the specified offset- Specified by:
getElementsin interfaceINDArray- Overrides:
getElementsin classAVector
-
toDoubleBuffer
public void toDoubleBuffer(java.nio.DoubleBuffer dest)
Description copied from interface:INDArrayCopies the elements of this INDArray to the specified double buffer.- Specified by:
toDoubleBufferin interfaceINDArray- Overrides:
toDoubleBufferin classAVector
-
toDoubleArray
public double[] toDoubleArray()
Description copied from interface:INDArrayCopies the elements of this array to a new double[] array.- Specified by:
toDoubleArrayin interfaceINDArray- Overrides:
toDoubleArrayin classAVector
-
toNormal
public Vector3 toNormal()
Description copied from class:AVectorCreates a new mutable vector representing the normalised value of this vector Returns null if the vector cannot be normalised (i.e. is a zero length vector)- Overrides:
toNormalin classAPrimitiveVector- Returns:
-
clone
public Vector3 clone()
Description copied from class:AVectorClones the vector, creating a new mutable copy of all data. The clone is: - not guaranteed to be of the same type. - guaranteed to be fully mutable - guaranteed not to contain a reference (i.e. is a full deep copy)
-
copy
public Vector3 copy()
Description copied from interface:INDArrayReturns a defensive copy of the array data. Use this if the original array might change and you need a defensive copy. May return the same array if the original was immutable, otherwise will return a defensive copy.
-
getX
public double getX()
- Overrides:
getXin classAPrimitiveVector
-
getY
public double getY()
- Overrides:
getYin classAPrimitiveVector
-
getZ
public double getZ()
- Overrides:
getZin classAPrimitiveVector
-
exactClone
public Vector3 exactClone()
Description copied from class:AVectorReturns an exact clone of this vector, i.e. of the same type- Specified by:
exactClonein interfaceINDArray- Specified by:
exactClonein classAPrimitiveVector- Returns:
- A clone of the original array
-
equals
public boolean equals(AVector v)
Description copied from class:AbstractArrayReturns true if this array is exactly equal to a vector.
-
equals
public boolean equals(Vector3 v)
-
equalsArray
public boolean equalsArray(double[] data, int offset)Description copied from class:AVectorReturns true if this vector exactly matches the elements in double[] array, starting from the specified offset- Specified by:
equalsArrayin interfaceINDArray- Overrides:
equalsArrayin classAVector- Parameters:
data- Array of double element values to check for equalityoffset- Offset into the data array- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG