public final class VectorUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
VectorUtil.Winding |
| Modifier and Type | Field and Description |
|---|---|
static float[] |
VEC3_ONE |
static float[] |
VEC3_UNIT_Y |
static float[] |
VEC3_UNIT_Y_NEG |
static float[] |
VEC3_UNIT_Z |
static float[] |
VEC3_UNIT_Z_NEG |
static float[] |
VEC3_ZERO |
| Constructor and Description |
|---|
VectorUtil() |
| Modifier and Type | Method and Description |
|---|---|
static float[] |
addVec2(float[] result,
float[] v1,
float[] v2)
Adds two vectors, result = v1 + v2
|
static float[] |
addVec3(float[] result,
float[] v1,
float[] v2)
Adds two vectors, result = v1 + v2
|
static float |
angleVec3(float[] vec1,
float[] vec2)
Return the angle between to vectors in radians
|
static float |
area(ArrayList<? extends Vert2fImmutable> vertices)
Computes the area of a list of vertices to check if ccw
|
static boolean |
ccw(Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c)
Check if points are in ccw order
|
static float[] |
copyVec2(float[] dst,
int dstOffset,
float[] src,
int srcOffset)
Copies a vector of length 2
|
static float[] |
copyVec3(float[] dst,
int dstOffset,
float[] src,
int srcOffset)
Copies a vector of length 3
|
static float[] |
copyVec4(float[] dst,
int dstOffset,
float[] src,
int srcOffset)
Copies a vector of length 4
|
static float |
cosAngleVec3(float[] vec1,
float[] vec2)
Return the cosines of the angle between to vectors
|
static float[] |
crossVec3(float[] result,
float[] v1,
float[] v2)
cross product vec1 x vec2
|
static float[] |
crossVec3(float[] r,
int r_offset,
float[] v1,
int v1_offset,
float[] v2,
int v2_offset)
cross product vec1 x vec2
|
static float |
determinantVec3(float[] a,
float[] b,
float[] c)
Return the determinant of 3 vectors
|
static float |
distSquareVec3(float[] v1,
float[] v2)
Return the squared distance between the given two points described vector v1 and v2.
|
static float |
distVec3(float[] v1,
float[] v2)
Return the distance between the given two points described vector v1 and v2.
|
static float[] |
divVec2(float[] result,
float[] vector,
float scale)
Divides a vector by param using given result float[], result = vector / scale
|
static float[] |
divVec2(float[] result,
float[] vector,
float[] scale)
Divides a vector by param using given result float[], result = vector / scale
|
static float[] |
divVec3(float[] result,
float[] vector,
float scale)
Divides a vector by param using given result float[], result = vector / scale
|
static float[] |
divVec3(float[] result,
float[] vector,
float[] scale)
Divides a vector by param using given result float[], result = vector / scale
|
static float |
dotVec3(float[] vec1,
float[] vec2)
Return the dot product of two points
|
static float[] |
getNormalVec2(float[] result,
float[] v1,
float[] v2) |
static float[] |
getNormalVec3(float[] result,
float[] v1,
float[] v2,
float[] v3,
float[] tmp1Vec3,
float[] tmp2Vec3)
Returns the 3d surface normal of a triangle given three vertices.
|
static float[] |
getPlaneVec3(float[] resultV4,
float[] normalVec3,
float[] pVec3)
Finds the plane equation of a plane given its normal and a point on the plane.
|
static float[] |
getPlaneVec3(float[] resultVec4,
float[] v1,
float[] v2,
float[] v3,
float[] temp1V3,
float[] temp2V3)
This finds the plane equation of a triangle given three vertices.
|
static VectorUtil.Winding |
getWinding(ArrayList<? extends Vert2fImmutable> vertices)
Compute the general winding of the vertices
|
static VectorUtil.Winding |
getWinding(Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c)
Compute the winding of given points
|
static boolean |
isCollinearVec3(float[] v1,
float[] v2,
float[] v3)
Check if three vertices are colliniear
|
static boolean |
isInCircleVec2(Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d)
Check if vertices in triangle circumcircle
|
static boolean |
isInTriangleVec3(float[] a,
float[] b,
float[] c,
float[] p,
float[] ac,
float[] ab,
float[] ap)
Check if a vertex is in triangle using
barycentric coordinates computation.
|
static boolean |
isVec2Equal(float[] vec1,
int vec1Offset,
float[] vec2,
int vec2Offset)
Return true if both vectors are equal w/o regarding an epsilon.
|
static boolean |
isVec2Equal(float[] vec1,
int vec1Offset,
float[] vec2,
int vec2Offset,
float epsilon)
Return true if both vectors are equal, i.e.
|
static boolean |
isVec2Zero(float[] vec,
int vecOffset)
Return true if vector is zero, no
FloatUtil.EPSILON is taken into consideration. |
static boolean |
isVec2Zero(float[] vec,
int vecOffset,
float epsilon)
Return true if vector is zero, i.e.
|
static boolean |
isVec3Equal(float[] vec1,
int vec1Offset,
float[] vec2,
int vec2Offset)
Return true if both vectors are equal w/o regarding an epsilon.
|
static boolean |
isVec3Equal(float[] vec1,
int vec1Offset,
float[] vec2,
int vec2Offset,
float epsilon)
Return true if both vectors are equal, i.e.
|
static boolean |
isVec3InTriangle3(float[] a,
float[] b,
float[] c,
float[] p1,
float[] p2,
float[] p3,
float[] tmpAC,
float[] tmpAB,
float[] tmpAP)
Check if one of three vertices are in triangle using
barycentric coordinates computation.
|
static boolean |
isVec3InTriangle3(float[] a,
float[] b,
float[] c,
float[] p1,
float[] p2,
float[] p3,
float[] tmpAC,
float[] tmpAB,
float[] tmpAP,
float epsilon)
Check if one of three vertices are in triangle using
barycentric coordinates computation, using given epsilon for comparison.
|
static boolean |
isVec3Zero(float[] vec,
int vecOffset)
Return true if vector is zero, no
FloatUtil.EPSILON is taken into consideration. |
static boolean |
isVec3Zero(float[] vec,
int vecOffset,
float epsilon)
Return true if vector is zero, i.e.
|
static boolean |
isZero(float x,
float y,
float epsilon)
Return true if all two vector components are zero, i.e.
|
static boolean |
isZero(float x,
float y,
float z,
float epsilon)
Return true if all three vector components are zero, i.e.
|
static float[] |
line2lineIntersection(float[] result,
Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d)
Compute intersection between two lines
|
static float[] |
line2PlaneIntersection(float[] result,
Ray ray,
float[] plane,
float epsilon)
Return intersection of an infinite line with a plane if exists, otherwise null.
|
static float |
mid(float p1,
float p2)
Calculate the midpoint of two values
|
static float[] |
midVec3(float[] result,
float[] p1,
float[] p2)
Calculate the midpoint of two points
|
static float[] |
mulColMat4Vec3(float[] result,
float[] colMatrix,
float[] vec)
Multiplication of column-major 4x4 matrix with vector
|
static float[] |
mulRowMat4Vec3(float[] result,
float[] rawMatrix,
float[] vec)
Matrix Vector multiplication
|
static float[] |
normalizeVec2(float[] vector)
Normalize a vector in place
|
static float[] |
normalizeVec2(float[] result,
float[] vector)
Normalize a vector
|
static float[] |
normalizeVec3(float[] vector)
Normalize a vector in place
|
static float[] |
normalizeVec3(float[] result,
float[] vector)
Normalize a vector
|
static float[] |
normalizeVec3(float[] vector,
int offset)
Normalize a vector in place
|
static float |
normSquareVec2(float[] vec)
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
|
static float |
normSquareVec2(float[] vec,
int offset)
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
|
static float |
normSquareVec3(float[] vec)
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
|
static float |
normSquareVec3(float[] vec,
int offset)
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
|
static float |
normVec2(float[] vec)
Return the length of a vector, a.k.a the norm or magnitude
|
static float |
normVec3(float[] vec)
Return the length of a vector, a.k.a the norm or magnitude
|
static float[] |
scaleVec2(float[] result,
float[] vector,
float scale)
Scales a vector by param using given result float[], result = vector * scale
|
static float[] |
scaleVec2(float[] result,
float[] vector,
float[] scale)
Scales a vector by param using given result float[], result = vector * scale
|
static float[] |
scaleVec3(float[] result,
float[] vector,
float scale)
Scales a vector by param using given result float[], result = vector * scale
|
static float[] |
scaleVec3(float[] result,
float[] vector,
float[] scale)
Scales a vector by param using given result float[], result = vector * scale
|
static float[] |
seg2SegIntersection(float[] result,
Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d)
Compute intersection between two segments
|
static float[] |
subVec2(float[] result,
float[] v1,
float[] v2)
Subtracts two vectors, result = v1 - v2
|
static float[] |
subVec3(float[] result,
float[] v1,
float[] v2)
Subtracts two vectors, result = v1 - v2
|
static boolean |
testSeg2SegIntersection(Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d)
Compute intersection between two segments
|
static boolean |
testSeg2SegIntersection(Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d,
float epsilon)
Compute intersection between two segments, using given epsilon for comparison.
|
static boolean |
testTri2SegIntersection(Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d,
Vert2fImmutable e)
Check if a segment intersects with a triangle
|
static boolean |
testTri2SegIntersection(Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d,
Vert2fImmutable e,
float epsilon)
Check if a segment intersects with a triangle, using given epsilon for comparison.
|
static float |
triAreaVec2(float[] A,
float[] B,
float[] C)
Computes oriented area of a triangle
|
static float |
triAreaVec2(Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c)
Computes oriented area of a triangle
|
public static final float[] VEC3_ONE
public static final float[] VEC3_ZERO
public static final float[] VEC3_UNIT_Y
public static final float[] VEC3_UNIT_Y_NEG
public static final float[] VEC3_UNIT_Z
public static final float[] VEC3_UNIT_Z_NEG
public static float[] copyVec2(float[] dst,
int dstOffset,
float[] src,
int srcOffset)
dst - output vectordstOffset - offset of dst in arraysrc - input vectorsrcOffset - offset of src in arraypublic static float[] copyVec3(float[] dst,
int dstOffset,
float[] src,
int srcOffset)
dst - output vectordstOffset - offset of dst in arraysrc - input vectorsrcOffset - offset of src in arraypublic static float[] copyVec4(float[] dst,
int dstOffset,
float[] src,
int srcOffset)
dst - output vectordstOffset - offset of dst in arraysrc - input vectorsrcOffset - offset of src in arraypublic static boolean isVec2Equal(float[] vec1,
int vec1Offset,
float[] vec2,
int vec2Offset)
Implementation uses FloatUtil.isEqual(float, float), see API doc for details.
public static boolean isVec3Equal(float[] vec1,
int vec1Offset,
float[] vec2,
int vec2Offset)
Implementation uses FloatUtil.isEqual(float, float), see API doc for details.
public static boolean isVec2Equal(float[] vec1,
int vec1Offset,
float[] vec2,
int vec2Offset,
float epsilon)
epsilon.
Implementation uses FloatUtil.isEqual(float, float, float), see API doc for details.
public static boolean isVec3Equal(float[] vec1,
int vec1Offset,
float[] vec2,
int vec2Offset,
float epsilon)
epsilon.
Implementation uses FloatUtil.isEqual(float, float, float), see API doc for details.
public static boolean isVec2Zero(float[] vec,
int vecOffset)
FloatUtil.EPSILON is taken into consideration.public static boolean isVec3Zero(float[] vec,
int vecOffset)
FloatUtil.EPSILON is taken into consideration.public static boolean isVec2Zero(float[] vec,
int vecOffset,
float epsilon)
epsilon.
Implementation uses FloatUtil.isZero(float, float), see API doc for details.
public static boolean isVec3Zero(float[] vec,
int vecOffset,
float epsilon)
epsilon.
Implementation uses FloatUtil.isZero(float, float), see API doc for details.
public static boolean isZero(float x,
float y,
float epsilon)
epsilon.
Implementation uses FloatUtil.isZero(float, float), see API doc for details.
public static boolean isZero(float x,
float y,
float z,
float epsilon)
epsilon.
Implementation uses FloatUtil.isZero(float, float), see API doc for details.
public static float distSquareVec3(float[] v1,
float[] v2)
When comparing the relative distance between two points it is usually sufficient to compare the squared distances, thus avoiding an expensive square root operation.
public static float distVec3(float[] v1,
float[] v2)
public static float dotVec3(float[] vec1,
float[] vec2)
vec1 - vector 1vec2 - vector 2public static float cosAngleVec3(float[] vec1,
float[] vec2)
vec1 - vector 1vec2 - vector 2public static float angleVec3(float[] vec1,
float[] vec2)
vec1 - vector 1vec2 - vector 2public static float normSquareVec2(float[] vec)
public static float normSquareVec2(float[] vec,
int offset)
public static float normSquareVec3(float[] vec)
public static float normSquareVec3(float[] vec,
int offset)
public static float normVec2(float[] vec)
public static float normVec3(float[] vec)
public static float[] normalizeVec2(float[] result,
float[] vector)
result - output vector, may be vector (in-place)vector - input vectorpublic static float[] normalizeVec2(float[] vector)
vector - input vectorpublic static float[] normalizeVec3(float[] result,
float[] vector)
result - output vector, may be vector (in-place)vector - input vectorpublic static float[] normalizeVec3(float[] vector)
vector - input vectorpublic static float[] normalizeVec3(float[] vector,
int offset)
vector - input vectorpublic static float[] scaleVec2(float[] result,
float[] vector,
float scale)
result - vector for the result, may be vector (in-place)vector - input vectorscale - single scale constant for all vector componentspublic static float[] scaleVec3(float[] result,
float[] vector,
float scale)
result - vector for the result, may be vector (in-place)vector - input vectorscale - single scale constant for all vector componentspublic static float[] scaleVec3(float[] result,
float[] vector,
float[] scale)
result - vector for the result, may be vector (in-place)vector - input vectorscale - 3 component scale constant for each vector componentpublic static float[] scaleVec2(float[] result,
float[] vector,
float[] scale)
result - vector for the result, may be vector (in-place)vector - input vectorscale - 2 component scale constant for each vector componentpublic static float[] divVec2(float[] result,
float[] vector,
float scale)
result - vector for the result, may be vector (in-place)vector - input vectorscale - single scale constant for all vector componentspublic static float[] divVec3(float[] result,
float[] vector,
float scale)
result - vector for the result, may be vector (in-place)vector - input vectorscale - single scale constant for all vector componentspublic static float[] divVec3(float[] result,
float[] vector,
float[] scale)
result - vector for the result, may be vector (in-place)vector - input vectorscale - 3 component scale constant for each vector componentpublic static float[] divVec2(float[] result,
float[] vector,
float[] scale)
result - vector for the result, may be vector (in-place)vector - input vectorscale - 2 component scale constant for each vector componentpublic static float[] addVec2(float[] result,
float[] v1,
float[] v2)
result - float[2] result vector, may be either v1 or v2 (in-place)v1 - vector 1v2 - vector 2public static float[] addVec3(float[] result,
float[] v1,
float[] v2)
result - float[3] result vector, may be either v1 or v2 (in-place)v1 - vector 1v2 - vector 2public static float[] subVec2(float[] result,
float[] v1,
float[] v2)
result - float[2] result vector, may be either v1 or v2 (in-place)v1 - vector 1v2 - vector 2public static float[] subVec3(float[] result,
float[] v1,
float[] v2)
result - float[3] result vector, may be either v1 or v2 (in-place)v1 - vector 1v2 - vector 2public static float[] crossVec3(float[] result,
float[] v1,
float[] v2)
v1 - vector 1v2 - vector 2public static float[] crossVec3(float[] r,
int r_offset,
float[] v1,
int v1_offset,
float[] v2,
int v2_offset)
v1 - vector 1v2 - vector 2public static float[] mulColMat4Vec3(float[] result,
float[] colMatrix,
float[] vec)
colMatrix - column matrix (4x4)vec - vector(x,y,z)public static float[] mulRowMat4Vec3(float[] result,
float[] rawMatrix,
float[] vec)
rawMatrix - column matrix (4x4)vec - vector(x,y,z)public static float mid(float p1,
float p2)
p1 - first valuep2 - second valepublic static float[] midVec3(float[] result,
float[] p1,
float[] p2)
p1 - first point vectorp2 - second point vectorpublic static float determinantVec3(float[] a,
float[] b,
float[] c)
a - vector 1b - vector 2c - vector 3public static boolean isCollinearVec3(float[] v1,
float[] v2,
float[] v3)
v1 - vertex 1v2 - vertex 2v3 - vertex 3public static boolean isInCircleVec2(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
a - triangle vertex 1b - triangle vertex 2c - triangle vertex 3d - vertex in questionpublic static float triAreaVec2(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
a - first vertexb - second vertexc - third vertexpublic static float triAreaVec2(float[] A,
float[] B,
float[] C)
A - first vertexB - second vertexC - third vertexpublic static boolean isInTriangleVec3(float[] a,
float[] b,
float[] c,
float[] p,
float[] ac,
float[] ab,
float[] ap)
a - first triangle vertexb - second triangle vertexc - third triangle vertexp - the vertex in questionpublic static boolean isVec3InTriangle3(float[] a,
float[] b,
float[] c,
float[] p1,
float[] p2,
float[] p3,
float[] tmpAC,
float[] tmpAB,
float[] tmpAP)
a - first triangle vertexb - second triangle vertexc - third triangle vertexp1 - the vertex in questionp2 - the vertex in questionp3 - the vertex in questiontmpAC - tmpAB - tmpAP - public static boolean isVec3InTriangle3(float[] a,
float[] b,
float[] c,
float[] p1,
float[] p2,
float[] p3,
float[] tmpAC,
float[] tmpAB,
float[] tmpAP,
float epsilon)
a - first triangle vertexb - second triangle vertexc - third triangle vertexp1 - the vertex in questionp2 - the vertex in questionp3 - the vertex in questiontmpAC - tmpAB - tmpAP - public static boolean ccw(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
a - first vertexb - second vertexc - third vertexpublic static VectorUtil.Winding getWinding(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
a - first vertexb - second vertexc - third vertexpublic static float area(ArrayList<? extends Vert2fImmutable> vertices)
vertices - public static VectorUtil.Winding getWinding(ArrayList<? extends Vert2fImmutable> vertices)
vertices - array of VerticesVectorUtil.Windingpublic static float[] getNormalVec2(float[] result,
float[] v1,
float[] v2)
result - vec2 result for normalv1 - vec2v2 - vec2public static float[] getNormalVec3(float[] result,
float[] v1,
float[] v2,
float[] v3,
float[] tmp1Vec3,
float[] tmp2Vec3)
result - vec3 result for normalv1 - vec3v2 - vec3v3 - vec3tmp1Vec3 - temp vec3tmp2Vec3 - temp vec3public static float[] getPlaneVec3(float[] resultV4,
float[] normalVec3,
float[] pVec3)
resultV4 - vec4 plane equationnormalVec3 - pVec3 - public static float[] getPlaneVec3(float[] resultVec4,
float[] v1,
float[] v2,
float[] v3,
float[] temp1V3,
float[] temp2V3)
resultVec4 - vec4 plane equationv1 - vec3v2 - vec3v3 - vec3temp1V3 - temp2V3 - public static float[] line2PlaneIntersection(float[] result,
Ray ray,
float[] plane,
float epsilon)
Thanks to Norman Vine -- nhv@yahoo.com (with hacks by Steve)
result - vec3 result buffer for intersecting coordsray - here representing an infinite line, origin and direction.plane - vec4 plane equationepsilon - public static float[] seg2SegIntersection(float[] result,
Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d)
a - vertex 1 of first segmentb - vertex 2 of first segmentc - vertex 1 of second segmentd - vertex 2 of second segmentpublic static boolean testSeg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
a - vertex 1 of first segmentb - vertex 2 of first segmentc - vertex 1 of second segmentd - vertex 2 of second segmentpublic static boolean testSeg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, float epsilon)
a - vertex 1 of first segmentb - vertex 2 of first segmentc - vertex 1 of second segmentd - vertex 2 of second segmentpublic static float[] line2lineIntersection(float[] result,
Vert2fImmutable a,
Vert2fImmutable b,
Vert2fImmutable c,
Vert2fImmutable d)
a - vertex 1 of first lineb - vertex 2 of first linec - vertex 1 of second lined - vertex 2 of second linepublic static boolean testTri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e)
a - vertex 1 of the triangleb - vertex 2 of the trianglec - vertex 3 of the triangled - vertex 1 of first segmente - vertex 2 of first segmentpublic static boolean testTri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e, float epsilon)
a - vertex 1 of the triangleb - vertex 2 of the trianglec - vertex 3 of the triangled - vertex 1 of first segmente - vertex 2 of first segmentCopyright 2010 JogAmp Community.