Class Vec4
- java.lang.Object
-
- gov.nasa.worldwind.geom.Vec4
-
public class Vec4 extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static Vec4INFINITYstatic Vec4ONEstatic Vec4UNIT_NEGATIVE_Wstatic Vec4UNIT_NEGATIVE_Xstatic Vec4UNIT_NEGATIVE_Ystatic Vec4UNIT_NEGATIVE_Zstatic Vec4UNIT_Wstatic Vec4UNIT_Xstatic Vec4UNIT_Ystatic Vec4UNIT_Zdoublewdoublexdoubleydoublezstatic Vec4ZERO
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vec4add3(double x, double y, double z)Vec4add3(Vec4 vec4)AngleangleBetween3(Vec4 vec4)static booleanareColinear(Vec4 a, Vec4 b, Vec4 c)Indicates whether three vectors are colinear.static AngleaxisAngle(Vec4 v1, Vec4 v2, Vec4[] result)Compute the angle and rotation axis required to rotate one vector to align with another.static Vec4clamp3(Vec4 vec4, double min, double max)static Vec4computeAveragePoint(java.lang.Iterable<? extends Vec4> points)Returns the arithmetic mean of the x, y, z, and w coordinates of the specified points Iterable.static Vec4computeAveragePoint3(BufferWrapper coordinates, int stride)Returns the arithmetic mean of the x, y, z coordinates of the specified points buffer.static Vec4[]computeExtrema(Vec4[] points)Calculate the extrema of a given array ofVec4s.static Vec4[]computeExtrema(BufferWrapper buffer)Vec4cross3(Vec4 vec4)doubledistanceTo2(Vec4 vec4)doubledistanceTo3(Vec4 vec4)doubledistanceToSquared3(Vec4 vec4)Vec4divide3(double value)Vec4divide3(Vec4 vec4)doubledot3(Vec4 vec4)doubledot4(Vec4 vec4)doubledotSelf3()doubledotSelf4()booleanequals(java.lang.Object obj)static Vec4fromArray2(double[] array, int offset)Constructs a new Vec4 withxandyvalues from the specified double array.static Vec4fromArray3(double[] array, int offset)Constructs a new Vec4 withx,yandzvalues from the specified double array.static Vec4fromArray4(double[] array, int offset)Constructs a new Vec4 withx,y,zandwvalues from the specified double array.static Vec4fromDoubleArray(double[] array, int offset, int length)Constructs a new Vec4 with coordinate values read from the specified double array.static Vec4fromFloatArray(float[] array, int offset, int length)Constructs a new Vec4 with coordinate values read from the specified float array.static Vec4fromLine3(Vec4 origin, double t, Vec4 direction)Vec4getAbs3()static doublegetAverageDistance(java.lang.Iterable<? extends Vec4> points)doublegetLength3()doublegetLengthSquared3()Vec4getNegative3()doublegetW()doublegetX()doublegetY()doublegetZ()inthashCode()static Vec4max3(Vec4 value1, Vec4 value2)static Vec4min3(Vec4 value1, Vec4 value2)static Vec4mix3(double amount, Vec4 value1, Vec4 value2)Vec4multiply3(double value)Vec4multiply3(Vec4 vec4)Vec4normalize3()Vec4perpendicularTo3(Vec4 vec4)Vec4[]perpendicularVectors()Computes two vectors mutually perpendicular to this vector and each other.Vec4projectOnto3(Vec4 vec4)Vec4subtract3(double x, double y, double z)Vec4subtract3(Vec4 vec4)double[]toArray2(double[] array, int offset)Writes this Vec4'sxandyvalues to the specified double array.double[]toArray3(double[] array, int offset)Writes this Vec4'sx,yandzvalues to the specified double array.double[]toArray4(double[] array, int offset)Writes this Vec4'sx,y,zandwvalues to the specified double array.double[]toDoubleArray(double[] array, int offset, int length)Writes this Vec4's coordinate values to the specified double array.float[]toFloatArray(float[] array, int offset, int length)Writes this Vec4's coordinate values to the specified float array.Vec4toHomogeneousDirection3()Returns a representation of this vector as anx y zdirection suitable for use where four-dimensional homogeneous coordinates are required.Vec4toHomogeneousPoint3()Returns a representation of this vector as anx y zpoint suitable for use where four-dimensional homogeneous coordinates are required.java.lang.StringtoString()Vec4transformBy3(Matrix matrix)Vec4transformBy3(Quaternion quaternion)Vec4transformBy4(Matrix matrix)doublew()doublex()doubley()doublez()
-
-
-
Field Detail
-
INFINITY
public static final Vec4 INFINITY
-
ZERO
public static final Vec4 ZERO
-
ONE
public static final Vec4 ONE
-
UNIT_X
public static final Vec4 UNIT_X
-
UNIT_NEGATIVE_X
public static final Vec4 UNIT_NEGATIVE_X
-
UNIT_Y
public static final Vec4 UNIT_Y
-
UNIT_NEGATIVE_Y
public static final Vec4 UNIT_NEGATIVE_Y
-
UNIT_Z
public static final Vec4 UNIT_Z
-
UNIT_NEGATIVE_Z
public static final Vec4 UNIT_NEGATIVE_Z
-
UNIT_W
public static final Vec4 UNIT_W
-
UNIT_NEGATIVE_W
public static final Vec4 UNIT_NEGATIVE_W
-
x
public final double x
-
y
public final double y
-
z
public final double z
-
w
public final double w
-
-
Method Detail
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
fromDoubleArray
public static Vec4 fromDoubleArray(double[] array, int offset, int length)
Constructs a new Vec4 with coordinate values read from the specified double array. The specified offset must be 0 or greater, the specified length must be 1 or greater, and the array must have capacity equal to or greater thanoffset + length. Coordinates are assigned as follows:x = array[offset]
y = array[offset + 1]iflength > 1, otherwisey=0z = array[offset + 2]iflength > 2, otherwisez=0w = array[offset + 3]iflength > 3, otherwisew=1- Parameters:
array- the double array from which to read coordinate data.offset- the array starting index.length- the number of coordinates to read.- Returns:
- a new Vec4 with coordinate values read from the specified double array.
- Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, if length is less than 1, or if the array's capacity is less thanoffset + length.
-
fromFloatArray
public static Vec4 fromFloatArray(float[] array, int offset, int length)
Constructs a new Vec4 with coordinate values read from the specified float array. The specified offset must be 0 or greater, the specified length must be 1 or greater, and the array must have capacity equal to or greater thanoffset + length. Coordinates are assigned as follows:x = array[offset]
y = array[offset + 1]iflength > 1, otherwisey=0z = array[offset + 2]iflength > 2, otherwisez=0w = array[offset + 3]iflength > 3, otherwisew=1- Parameters:
array- the float array from which to read coordinate data.offset- the array starting index.length- the number of coordinates to read.- Returns:
- a new Vec4 with coordinate values read from the specified double array.
- Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, if length is less than 1, or if the array's capacity is less thanoffset + length.
-
fromArray2
public static Vec4 fromArray2(double[] array, int offset)
Constructs a new Vec4 withxandyvalues from the specified double array. The specified offset must be 0 or greater, and the array must have capacity equal to or greater thanoffset + 2. Coordinates are assigned as follows:x = array[offset]y = array[offset + 1]- Parameters:
array- the double array from which to read coordinate data.offset- the array starting index.- Returns:
- a new Vec4 with
xandycoordinate values from the specified double array. - Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, or if the array's capacity is less thanoffset + 2.
-
fromArray3
public static Vec4 fromArray3(double[] array, int offset)
Constructs a new Vec4 withx,yandzvalues from the specified double array. The specified offset must be 0 or greater, and the array must have capacity equal to or greater thanoffset + 3. Coordinates are assigned as follows:x = array[offset]y = array[offset + 1]z = array[offset + 2]- Parameters:
array- the double array from which to read coordinate data.offset- the array starting index.- Returns:
- a new Vec4 with
x,yandzcoordinate values from the specified double array. - Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, or if the array's capacity is less thanoffset + 3.
-
fromArray4
public static Vec4 fromArray4(double[] array, int offset)
Constructs a new Vec4 withx,y,zandwvalues from the specified double array. The specified offset must be 0 or greater, and the array must have capacity equal to or greater thanoffset + 4. Coordinates are assigned as follows:x = array[offset]y = array[offset + 1]z = array[offset + 2]w = array[offset + 3]- Parameters:
array- the double array from which to read coordinate data.offset- the array starting index.- Returns:
- a new Vec4 with
x,y,zandwcoordinate values from the specified double array. - Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, or if the array's capacity is less thanoffset + 4.
-
toDoubleArray
public final double[] toDoubleArray(double[] array, int offset, int length)Writes this Vec4's coordinate values to the specified double array. The specified offset must be 0 or greater, the specified length must be 1 or greater, and the array must have capacity equal to or greater thanoffset + length. Coordinates are written to the array as follows:array[offset] = xarray[offset + 1] = yiflength > 1, otherwisearray[offset + 1]is not written to
array[offset + 2] = ziflength > 2, otherwisearray[offset + 2]is not written toarray[offset + 3] = wiflength > 3, otherwisearray[offset + 3]is not written to- Parameters:
array- the double array to receive the coordinate data.offset- the array starting index.length- the number of coordinates to write.- Returns:
- the specified double array.
- Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, if length is less than 1, or if the array's capacity is less thanoffset + length.
-
toFloatArray
public final float[] toFloatArray(float[] array, int offset, int length)Writes this Vec4's coordinate values to the specified float array. The specified offset must be 0 or greater, the specified length must be 1 or greater, and the array must have capacity equal to or greater thanoffset + length. Coordinates are written to the array as follows:array[offset] = xarray[offset + 1] = yiflength > 1, otherwisearray[offset + 1]is not written to
array[offset + 2] = ziflength > 2, otherwisearray[offset + 2]is not written toarray[offset + 3] = wiflength > 3, otherwisearray[offset + 3]is not written to- Parameters:
array- the float array to receive the coordinate data.offset- the array starting index.length- the number of coordinates to write.- Returns:
- the specified double array.
- Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, if length is less than 1, or if the array's capacity is less thanoffset + length.
-
toArray2
public final double[] toArray2(double[] array, int offset)Writes this Vec4'sxandyvalues to the specified double array. The specified offset must be 0 or greater, and the array must have have capacity equal to or greater thanoffset + 2. Coordinates are written to the array as follows:array[offset] = xarray[offset + 1] = y- Parameters:
array- the double array to receive the coordinate data.offset- the array starting index.- Returns:
- the specified double array.
- Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, or if the array's capacity is less thanoffset + 2.
-
toArray3
public final double[] toArray3(double[] array, int offset)Writes this Vec4'sx,yandzvalues to the specified double array. The specified offset must be 0 or greater, and the array must have have capacity equal to or greater thanoffset + 3. Coordinates are written to the array as follows:array[offset] = xarray[offset + 1] = yarray[offset + 2] = z- Parameters:
array- the double array to receive the coordinate data.offset- the array starting index.- Returns:
- the specified double array.
- Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, or if the array's capacity is less thanoffset + 3.
-
toArray4
public final double[] toArray4(double[] array, int offset)Writes this Vec4'sx,y,zandwvalues to the specified double array. The specified offset must be 0 or greater, and the array must have have capacity equal to or greater thanoffset + 4. Coordinates are written to the array as follows:array[offset] = xarray[offset + 1] = yarray[offset + 2] = zarray[offset + 3] = w- Parameters:
array- the double array to receive the coordinate data.offset- the array starting index.- Returns:
- the specified double array.
- Throws:
java.lang.IllegalArgumentException- if the array is null, if offset is negative, or if the array's capacity is less thanoffset + 4.
-
toHomogeneousPoint3
public Vec4 toHomogeneousPoint3()
Returns a representation of this vector as anx y zpoint suitable for use where four-dimensional homogeneous coordinates are required. The returned vector hasx y zcoordinates are equal to this vector'sx y zcoordinates, and haswcoordinate equal to 1.0.A three-dimensional point in homogeneous coordinates is necessary when transforming that point by a 4x4 transformation matrix, or when calculating the dot product of the point and the equation of a plane. The returned vector is affected by the translation component of a 4x4 transformation matrix.
- Returns:
- this
Vec4converted to a point vector in four-dimensional homogeneous coordinates.
-
toHomogeneousDirection3
public Vec4 toHomogeneousDirection3()
Returns a representation of this vector as anx y zdirection suitable for use where four-dimensional homogeneous coordinates are required. The returned vector hasx y zcoordinates are equal to this vector'sx y zcoordinates, and haswcoordinate equal to 0.0.A three-dimensional direction in homogeneous coordinates is necessary when transforming that direction by a 4x4 transformation matrix. The returned vector is not affected by the translation component of a 4x4 transformation matrix, and therefore remains invariant under translation.
- Returns:
- this
Vec4converted to a direction vector in four-dimensional homogeneous coordinates.
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getX
public final double getX()
-
getY
public final double getY()
-
getZ
public final double getZ()
-
getW
public final double getW()
-
x
public final double x()
-
y
public final double y()
-
z
public final double z()
-
w
public final double w()
-
add3
public final Vec4 add3(double x, double y, double z)
-
subtract3
public final Vec4 subtract3(double x, double y, double z)
-
multiply3
public final Vec4 multiply3(double value)
-
divide3
public final Vec4 divide3(double value)
-
getNegative3
public final Vec4 getNegative3()
-
getAbs3
public final Vec4 getAbs3()
-
getLength3
public final double getLength3()
-
getLengthSquared3
public final double getLengthSquared3()
-
normalize3
public final Vec4 normalize3()
-
distanceTo2
public final double distanceTo2(Vec4 vec4)
-
distanceTo3
public final double distanceTo3(Vec4 vec4)
-
distanceToSquared3
public final double distanceToSquared3(Vec4 vec4)
-
dot3
public final double dot3(Vec4 vec4)
-
dot4
public final double dot4(Vec4 vec4)
-
dotSelf3
public final double dotSelf3()
-
dotSelf4
public final double dotSelf4()
-
axisAngle
public static Angle axisAngle(Vec4 v1, Vec4 v2, Vec4[] result)
Compute the angle and rotation axis required to rotate one vector to align with another.- Parameters:
v1- The base vector.v2- The vector to rotate into alignment withv1.result- A reference to an array in which to return the computed axis. May not be null.- Returns:
- The rotation angle.
- Throws:
java.lang.IllegalArgumentException- if any parameter is null.
-
perpendicularVectors
public Vec4[] perpendicularVectors()
Computes two vectors mutually perpendicular to this vector and each other.- Returns:
- an array of two unit vectors mutually orthogonal to this vector.
-
transformBy3
public final Vec4 transformBy3(Quaternion quaternion)
-
computeAveragePoint
public static Vec4 computeAveragePoint(java.lang.Iterable<? extends Vec4> points)
Returns the arithmetic mean of the x, y, z, and w coordinates of the specified points Iterable. This returns null if the Iterable contains no points, or if all of the points are null.- Parameters:
points- the Iterable of points which define the returned arithmetic mean.- Returns:
- the arithmetic mean point of the specified points Iterable, or null if the Iterable is empty or contains only null points.
- Throws:
java.lang.IllegalArgumentException- if the Iterable is null.
-
computeAveragePoint3
public static Vec4 computeAveragePoint3(BufferWrapper coordinates, int stride)
Returns the arithmetic mean of the x, y, z coordinates of the specified points buffer. This returns null if the buffer is empty.The buffer must contain XYZ coordinate tuples which are either tightly packed or offset by the specified stride. The stride specifies the number of buffer elements between the first coordinate of consecutive tuples. For example, a stride of 3 specifies that each tuple is tightly packed as XYZXYZXYZ, whereas a stride of 5 specifies that there are two elements between each tuple as XYZabXYZab (the elements "a" and "b" are ignored). The stride must be at least 3. If the buffer's length is not evenly divisible into stride-sized tuples, this ignores the remaining elements that follow the last complete tuple.
- Parameters:
coordinates- the buffer containing the point coordinates for which to compute a bounding volume.stride- the number of elements between the first coordinate of consecutive points. If stride is 3, this interprets the buffer has having tightly packed XYZ coordinate tuples.- Returns:
- the arithmetic mean point of the specified points Iterable, or null if the Iterable is empty or contains only null points.
- Throws:
java.lang.IllegalArgumentException- if the buffer is null, or if the stride is less than three.
-
getAverageDistance
public static double getAverageDistance(java.lang.Iterable<? extends Vec4> points)
-
computeExtrema
public static Vec4[] computeExtrema(Vec4[] points)
Calculate the extrema of a given array ofVec4s. The resulting array is always of length 2, with the first element containing the minimum extremum, and the second containing the maximum. The minimum extremum is composed by taking the smallest x, y and z values from all theVec4s in the array. These values are not necessarily taken from the sameVec4. The maximum extrema is composed in the same fashion.- Parameters:
points- any array ofVec4s- Returns:
- a array with length of 2, comprising the most extreme values in the given array
- Throws:
java.lang.IllegalArgumentException- ifpointsis null
-
computeExtrema
public static Vec4[] computeExtrema(BufferWrapper buffer)
-
areColinear
public static boolean areColinear(Vec4 a, Vec4 b, Vec4 c)
Indicates whether three vectors are colinear.- Parameters:
a- the first vector.b- the second vector.c- the third vector.- Returns:
- true if the vectors are colinear, otherwise false.
- Throws:
java.lang.IllegalArgumentException- if any argument is null.
-
-