Class VectorUtil
- java.lang.Object
-
- com.jogamp.opengl.math.VectorUtil
-
public final class VectorUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VectorUtil.Winding
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description VectorUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static float[]
addVec2(float[] result, float[] v1, float[] v2)
Adds two vectors, result = v1 + v2static float[]
addVec3(float[] result, float[] v1, float[] v2)
Adds two vectors, result = v1 + v2static float
angleVec3(float[] vec1, float[] vec2)
Return the angle between to vectors in radiansstatic float
area(ArrayList<? extends Vert2fImmutable> vertices)
Computes the area of a list of vertices to check if ccwstatic boolean
ccw(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
Check if points are in ccw orderstatic float[]
copyVec2(float[] dst, int dstOffset, float[] src, int srcOffset)
Copies a vector of length 2static float[]
copyVec3(float[] dst, int dstOffset, float[] src, int srcOffset)
Copies a vector of length 3static float[]
copyVec4(float[] dst, int dstOffset, float[] src, int srcOffset)
Copies a vector of length 4static float
cosAngleVec3(float[] vec1, float[] vec2)
Return the cosines of the angle between to vectorsstatic float[]
crossVec3(float[] result, float[] v1, float[] v2)
cross product vec1 x vec2static float[]
crossVec3(float[] r, int r_offset, float[] v1, int v1_offset, float[] v2, int v2_offset)
cross product vec1 x vec2static float
determinantVec3(float[] a, float[] b, float[] c)
Return the determinant of 3 vectorsstatic 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 / scalestatic float[]
divVec2(float[] result, float[] vector, float[] scale)
Divides a vector by param using given result float[], result = vector / scalestatic float[]
divVec3(float[] result, float[] vector, float scale)
Divides a vector by param using given result float[], result = vector / scalestatic float[]
divVec3(float[] result, float[] vector, float[] scale)
Divides a vector by param using given result float[], result = vector / scalestatic float
dotVec3(float[] vec1, float[] vec2)
Return the dot product of two pointsstatic 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(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
Compute the winding of given pointsstatic VectorUtil.Winding
getWinding(ArrayList<? extends Vert2fImmutable> vertices)
Compute the general winding of the verticesstatic boolean
isCollinearVec3(float[] v1, float[] v2, float[] v3)
Check if three vertices are colliniearstatic boolean
isInCircleVec2(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
Check if vertices in triangle circumcirclestatic 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, noFloatUtil.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, noFloatUtil.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 linesstatic 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 valuesstatic float[]
midVec3(float[] result, float[] p1, float[] p2)
Calculate the midpoint of two pointsstatic float[]
mulColMat4Vec3(float[] result, float[] colMatrix, float[] vec)
Multiplication of column-major 4x4 matrix with vectorstatic float[]
mulRowMat4Vec3(float[] result, float[] rawMatrix, float[] vec)
Matrix Vector multiplicationstatic float[]
normalizeVec2(float[] vector)
Normalize a vector in placestatic float[]
normalizeVec2(float[] result, float[] vector)
Normalize a vectorstatic float[]
normalizeVec3(float[] vector)
Normalize a vector in placestatic float[]
normalizeVec3(float[] result, float[] vector)
Normalize a vectorstatic float[]
normalizeVec3(float[] vector, int offset)
Normalize a vector in placestatic float
normSquareVec2(float[] vec)
Return the squared length of a vector, a.k.a the squared norm or squared magnitudestatic float
normSquareVec2(float[] vec, int offset)
Return the squared length of a vector, a.k.a the squared norm or squared magnitudestatic float
normSquareVec3(float[] vec)
Return the squared length of a vector, a.k.a the squared norm or squared magnitudestatic float
normSquareVec3(float[] vec, int offset)
Return the squared length of a vector, a.k.a the squared norm or squared magnitudestatic float
normVec2(float[] vec)
Return the length of a vector, a.k.a the norm or magnitudestatic float
normVec3(float[] vec)
Return the length of a vector, a.k.a the norm or magnitudestatic float[]
scaleVec2(float[] result, float[] vector, float scale)
Scales a vector by param using given result float[], result = vector * scalestatic float[]
scaleVec2(float[] result, float[] vector, float[] scale)
Scales a vector by param using given result float[], result = vector * scalestatic float[]
scaleVec3(float[] result, float[] vector, float scale)
Scales a vector by param using given result float[], result = vector * scalestatic float[]
scaleVec3(float[] result, float[] vector, float[] scale)
Scales a vector by param using given result float[], result = vector * scalestatic float[]
seg2SegIntersection(float[] result, Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
Compute intersection between two segmentsstatic float[]
subVec2(float[] result, float[] v1, float[] v2)
Subtracts two vectors, result = v1 - v2static float[]
subVec3(float[] result, float[] v1, float[] v2)
Subtracts two vectors, result = v1 - v2static boolean
testSeg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
Compute intersection between two segmentsstatic 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 trianglestatic 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 trianglestatic float
triAreaVec2(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
Computes oriented area of a triangle
-
-
-
Field Detail
-
VEC3_ONE
public static final float[] VEC3_ONE
-
VEC3_ZERO
public static final float[] VEC3_ZERO
-
VEC3_UNIT_Y
public static final float[] VEC3_UNIT_Y
-
VEC3_UNIT_Y_NEG
public static final float[] VEC3_UNIT_Y_NEG
-
VEC3_UNIT_Z
public static final float[] VEC3_UNIT_Z
-
VEC3_UNIT_Z_NEG
public static final float[] VEC3_UNIT_Z_NEG
-
-
Method Detail
-
copyVec2
public static float[] copyVec2(float[] dst, int dstOffset, float[] src, int srcOffset)
Copies a vector of length 2- Parameters:
dst
- output vectordstOffset
- offset of dst in arraysrc
- input vectorsrcOffset
- offset of src in array- Returns:
- copied output vector for chaining
-
copyVec3
public static float[] copyVec3(float[] dst, int dstOffset, float[] src, int srcOffset)
Copies a vector of length 3- Parameters:
dst
- output vectordstOffset
- offset of dst in arraysrc
- input vectorsrcOffset
- offset of src in array- Returns:
- copied output vector for chaining
-
copyVec4
public static float[] copyVec4(float[] dst, int dstOffset, float[] src, int srcOffset)
Copies a vector of length 4- Parameters:
dst
- output vectordstOffset
- offset of dst in arraysrc
- input vectorsrcOffset
- offset of src in array- Returns:
- copied output vector for chaining
-
isVec2Equal
public static boolean isVec2Equal(float[] vec1, int vec1Offset, float[] vec2, int vec2Offset)
Return true if both vectors are equal w/o regarding an epsilon.Implementation uses
FloatUtil.isEqual(float, float)
, see API doc for details.
-
isVec3Equal
public static boolean isVec3Equal(float[] vec1, int vec1Offset, float[] vec2, int vec2Offset)
Return true if both vectors are equal w/o regarding an epsilon.Implementation uses
FloatUtil.isEqual(float, float)
, see API doc for details.
-
isVec2Equal
public static boolean isVec2Equal(float[] vec1, int vec1Offset, float[] vec2, int vec2Offset, float epsilon)
Return true if both vectors are equal, i.e. their absolute delta <epsilon
.Implementation uses
FloatUtil.isEqual(float, float, float)
, see API doc for details.
-
isVec3Equal
public static boolean isVec3Equal(float[] vec1, int vec1Offset, float[] vec2, int vec2Offset, float epsilon)
Return true if both vectors are equal, i.e. their absolute delta <epsilon
.Implementation uses
FloatUtil.isEqual(float, float, float)
, see API doc for details.
-
isVec2Zero
public static boolean isVec2Zero(float[] vec, int vecOffset)
Return true if vector is zero, noFloatUtil.EPSILON
is taken into consideration.
-
isVec3Zero
public static boolean isVec3Zero(float[] vec, int vecOffset)
Return true if vector is zero, noFloatUtil.EPSILON
is taken into consideration.
-
isVec2Zero
public static boolean isVec2Zero(float[] vec, int vecOffset, float epsilon)
Return true if vector is zero, i.e. it's absolute components <epsilon
.Implementation uses
FloatUtil.isZero(float, float)
, see API doc for details.
-
isVec3Zero
public static boolean isVec3Zero(float[] vec, int vecOffset, float epsilon)
Return true if vector is zero, i.e. it's absolute components <epsilon
.Implementation uses
FloatUtil.isZero(float, float)
, see API doc for details.
-
isZero
public static boolean isZero(float x, float y, float epsilon)
Return true if all two vector components are zero, i.e. it's their absolute value <epsilon
.Implementation uses
FloatUtil.isZero(float, float)
, see API doc for details.
-
isZero
public static boolean isZero(float x, float y, float z, float epsilon)
Return true if all three vector components are zero, i.e. it's their absolute value <epsilon
.Implementation uses
FloatUtil.isZero(float, float)
, see API doc for details.
-
distSquareVec3
public static float distSquareVec3(float[] v1, float[] v2)
Return the squared distance between the given two points described vector v1 and 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.
-
distVec3
public static float distVec3(float[] v1, float[] v2)
Return the distance between the given two points described vector v1 and v2.
-
dotVec3
public static float dotVec3(float[] vec1, float[] vec2)
Return the dot product of two points- Parameters:
vec1
- vector 1vec2
- vector 2- Returns:
- the dot product as float
-
cosAngleVec3
public static float cosAngleVec3(float[] vec1, float[] vec2)
Return the cosines of the angle between to vectors- Parameters:
vec1
- vector 1vec2
- vector 2
-
angleVec3
public static float angleVec3(float[] vec1, float[] vec2)
Return the angle between to vectors in radians- Parameters:
vec1
- vector 1vec2
- vector 2
-
normSquareVec2
public static float normSquareVec2(float[] vec)
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
-
normSquareVec2
public static float normSquareVec2(float[] vec, int offset)
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
-
normSquareVec3
public static float normSquareVec3(float[] vec)
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
-
normSquareVec3
public static float normSquareVec3(float[] vec, int offset)
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
-
normVec2
public static float normVec2(float[] vec)
Return the length of a vector, a.k.a the norm or magnitude
-
normVec3
public static float normVec3(float[] vec)
Return the length of a vector, a.k.a the norm or magnitude
-
normalizeVec2
public static float[] normalizeVec2(float[] result, float[] vector)
Normalize a vector- Parameters:
result
- output vector, may be vector (in-place)vector
- input vector- Returns:
- normalized output vector
-
normalizeVec2
public static float[] normalizeVec2(float[] vector)
Normalize a vector in place- Parameters:
vector
- input vector- Returns:
- normalized output vector
-
normalizeVec3
public static float[] normalizeVec3(float[] result, float[] vector)
Normalize a vector- Parameters:
result
- output vector, may be vector (in-place)vector
- input vector- Returns:
- normalized output vector
-
normalizeVec3
public static float[] normalizeVec3(float[] vector)
Normalize a vector in place- Parameters:
vector
- input vector- Returns:
- normalized output vector
-
normalizeVec3
public static float[] normalizeVec3(float[] vector, int offset)
Normalize a vector in place- Parameters:
vector
- input vector- Returns:
- normalized output vector
-
scaleVec2
public static float[] scaleVec2(float[] result, float[] vector, float scale)
Scales a vector by param using given result float[], result = vector * scale- Parameters:
result
- vector for the result, may be vector (in-place)vector
- input vectorscale
- single scale constant for all vector components- Returns:
- result vector for chaining
-
scaleVec3
public static float[] scaleVec3(float[] result, float[] vector, float scale)
Scales a vector by param using given result float[], result = vector * scale- Parameters:
result
- vector for the result, may be vector (in-place)vector
- input vectorscale
- single scale constant for all vector components- Returns:
- result vector for chaining
-
scaleVec3
public static float[] scaleVec3(float[] result, float[] vector, float[] scale)
Scales a vector by param using given result float[], result = vector * scale- Parameters:
result
- vector for the result, may be vector (in-place)vector
- input vectorscale
- 3 component scale constant for each vector component- Returns:
- result vector for chaining
-
scaleVec2
public static float[] scaleVec2(float[] result, float[] vector, float[] scale)
Scales a vector by param using given result float[], result = vector * scale- Parameters:
result
- vector for the result, may be vector (in-place)vector
- input vectorscale
- 2 component scale constant for each vector component- Returns:
- result vector for chaining
-
divVec2
public static float[] divVec2(float[] result, float[] vector, float scale)
Divides a vector by param using given result float[], result = vector / scale- Parameters:
result
- vector for the result, may be vector (in-place)vector
- input vectorscale
- single scale constant for all vector components- Returns:
- result vector for chaining
-
divVec3
public static float[] divVec3(float[] result, float[] vector, float scale)
Divides a vector by param using given result float[], result = vector / scale- Parameters:
result
- vector for the result, may be vector (in-place)vector
- input vectorscale
- single scale constant for all vector components- Returns:
- result vector for chaining
-
divVec3
public static float[] divVec3(float[] result, float[] vector, float[] scale)
Divides a vector by param using given result float[], result = vector / scale- Parameters:
result
- vector for the result, may be vector (in-place)vector
- input vectorscale
- 3 component scale constant for each vector component- Returns:
- result vector for chaining
-
divVec2
public static float[] divVec2(float[] result, float[] vector, float[] scale)
Divides a vector by param using given result float[], result = vector / scale- Parameters:
result
- vector for the result, may be vector (in-place)vector
- input vectorscale
- 2 component scale constant for each vector component- Returns:
- result vector for chaining
-
addVec2
public static float[] addVec2(float[] result, float[] v1, float[] v2)
Adds two vectors, result = v1 + v2- Parameters:
result
- float[2] result vector, may be either v1 or v2 (in-place)v1
- vector 1v2
- vector 2- Returns:
- result vector for chaining
-
addVec3
public static float[] addVec3(float[] result, float[] v1, float[] v2)
Adds two vectors, result = v1 + v2- Parameters:
result
- float[3] result vector, may be either v1 or v2 (in-place)v1
- vector 1v2
- vector 2- Returns:
- result vector for chaining
-
subVec2
public static float[] subVec2(float[] result, float[] v1, float[] v2)
Subtracts two vectors, result = v1 - v2- Parameters:
result
- float[2] result vector, may be either v1 or v2 (in-place)v1
- vector 1v2
- vector 2- Returns:
- result vector for chaining
-
subVec3
public static float[] subVec3(float[] result, float[] v1, float[] v2)
Subtracts two vectors, result = v1 - v2- Parameters:
result
- float[3] result vector, may be either v1 or v2 (in-place)v1
- vector 1v2
- vector 2- Returns:
- result vector for chaining
-
crossVec3
public static float[] crossVec3(float[] result, float[] v1, float[] v2)
cross product vec1 x vec2- Parameters:
v1
- vector 1v2
- vector 2- Returns:
- the resulting vector
-
crossVec3
public static float[] crossVec3(float[] r, int r_offset, float[] v1, int v1_offset, float[] v2, int v2_offset)
cross product vec1 x vec2- Parameters:
v1
- vector 1v2
- vector 2- Returns:
- the resulting vector
-
mulColMat4Vec3
public static float[] mulColMat4Vec3(float[] result, float[] colMatrix, float[] vec)
Multiplication of column-major 4x4 matrix with vector- Parameters:
colMatrix
- column matrix (4x4)vec
- vector(x,y,z)- Returns:
- result
-
mulRowMat4Vec3
public static float[] mulRowMat4Vec3(float[] result, float[] rawMatrix, float[] vec)
Matrix Vector multiplication- Parameters:
rawMatrix
- column matrix (4x4)vec
- vector(x,y,z)- Returns:
- result
-
mid
public static float mid(float p1, float p2)
Calculate the midpoint of two values- Parameters:
p1
- first valuep2
- second vale- Returns:
- midpoint
-
midVec3
public static float[] midVec3(float[] result, float[] p1, float[] p2)
Calculate the midpoint of two points- Parameters:
p1
- first point vectorp2
- second point vector- Returns:
- midpoint
-
determinantVec3
public static float determinantVec3(float[] a, float[] b, float[] c)
Return the determinant of 3 vectors- Parameters:
a
- vector 1b
- vector 2c
- vector 3- Returns:
- the determinant value
-
isCollinearVec3
public static boolean isCollinearVec3(float[] v1, float[] v2, float[] v3)
Check if three vertices are colliniear- Parameters:
v1
- vertex 1v2
- vertex 2v3
- vertex 3- Returns:
- true if collinear, false otherwise
-
isInCircleVec2
public static boolean isInCircleVec2(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
Check if vertices in triangle circumcircle- Parameters:
a
- triangle vertex 1b
- triangle vertex 2c
- triangle vertex 3d
- vertex in question- Returns:
- true if the vertex d is inside the circle defined by the vertices a, b, c. from paper by Guibas and Stolfi (1985).
-
triAreaVec2
public static float triAreaVec2(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
Computes oriented area of a triangle- Parameters:
a
- first vertexb
- second vertexc
- third vertex- Returns:
- compute twice the area of the oriented triangle (a,b,c), the area is positive if the triangle is oriented counterclockwise.
-
triAreaVec2
public static float triAreaVec2(float[] A, float[] B, float[] C)
Computes oriented area of a triangle- Parameters:
A
- first vertexB
- second vertexC
- third vertex- Returns:
- compute twice the area of the oriented triangle (a,b,c), the area is positive if the triangle is oriented counterclockwise.
-
isInTriangleVec3
public 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.- Parameters:
a
- first triangle vertexb
- second triangle vertexc
- third triangle vertexp
- the vertex in question- Returns:
- true if p is in triangle (a, b, c), false otherwise.
-
isVec3InTriangle3
public 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.- Parameters:
a
- first triangle vertexb
- second triangle vertexc
- third triangle vertexp1
- the vertex in questionp2
- the vertex in questionp3
- the vertex in questiontmpAC
-tmpAB
-tmpAP
-- Returns:
- true if p1 or p2 or p3 is in triangle (a, b, c), false otherwise.
-
isVec3InTriangle3
public 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.- Parameters:
a
- first triangle vertexb
- second triangle vertexc
- third triangle vertexp1
- the vertex in questionp2
- the vertex in questionp3
- the vertex in questiontmpAC
-tmpAB
-tmpAP
-- Returns:
- true if p1 or p2 or p3 is in triangle (a, b, c), false otherwise.
-
ccw
public static boolean ccw(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
Check if points are in ccw order- Parameters:
a
- first vertexb
- second vertexc
- third vertex- Returns:
- true if the points a,b,c are in a ccw order
-
getWinding
public static VectorUtil.Winding getWinding(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
Compute the winding of given points- Parameters:
a
- first vertexb
- second vertexc
- third vertex- Returns:
- Winding
-
area
public static float area(ArrayList<? extends Vert2fImmutable> vertices)
Computes the area of a list of vertices to check if ccw- Parameters:
vertices
-- Returns:
- positive area if ccw else negative area value
-
getWinding
public static VectorUtil.Winding getWinding(ArrayList<? extends Vert2fImmutable> vertices)
Compute the general winding of the vertices- Parameters:
vertices
- array of Vertices- Returns:
- CCW or CW
VectorUtil.Winding
-
getNormalVec2
public static float[] getNormalVec2(float[] result, float[] v1, float[] v2)
- Parameters:
result
- vec2 result for normalv1
- vec2v2
- vec2- Returns:
- result for chaining
-
getNormalVec3
public 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.- Parameters:
result
- vec3 result for normalv1
- vec3v2
- vec3v3
- vec3tmp1Vec3
- temp vec3tmp2Vec3
- temp vec3- Returns:
- result for chaining
-
getPlaneVec3
public 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.- Parameters:
resultV4
- vec4 plane equationnormalVec3
-pVec3
-- Returns:
- result for chaining
-
getPlaneVec3
public 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.- Parameters:
resultVec4
- vec4 plane equationv1
- vec3v2
- vec3v3
- vec3temp1V3
-temp2V3
-- Returns:
- result for chaining
-
line2PlaneIntersection
public static float[] line2PlaneIntersection(float[] result, Ray ray, float[] plane, float epsilon)
Return intersection of an infinite line with a plane if exists, otherwise null.Thanks to Norman Vine -- nhv@yahoo.com (with hacks by Steve)
- Parameters:
result
- vec3 result buffer for intersecting coordsray
- here representing an infinite line, origin and direction.plane
- vec4 plane equationepsilon
-- Returns:
- resulting intersecting if exists, otherwise null
-
seg2SegIntersection
public static float[] seg2SegIntersection(float[] result, Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
Compute intersection between two segments- Parameters:
a
- vertex 1 of first segmentb
- vertex 2 of first segmentc
- vertex 1 of second segmentd
- vertex 2 of second segment- Returns:
- the intersection coordinates if the segments intersect, otherwise returns null
-
testSeg2SegIntersection
public static boolean testSeg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
Compute intersection between two segments- Parameters:
a
- vertex 1 of first segmentb
- vertex 2 of first segmentc
- vertex 1 of second segmentd
- vertex 2 of second segment- Returns:
- true if the segments intersect, otherwise returns false
-
testSeg2SegIntersection
public static boolean testSeg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, float epsilon)
Compute intersection between two segments, using given epsilon for comparison.- Parameters:
a
- vertex 1 of first segmentb
- vertex 2 of first segmentc
- vertex 1 of second segmentd
- vertex 2 of second segment- Returns:
- true if the segments intersect, otherwise returns false
-
line2lineIntersection
public static float[] line2lineIntersection(float[] result, Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
Compute intersection between two lines- Parameters:
a
- vertex 1 of first lineb
- vertex 2 of first linec
- vertex 1 of second lined
- vertex 2 of second line- Returns:
- the intersection coordinates if the lines intersect, otherwise returns null
-
testTri2SegIntersection
public static boolean testTri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e)
Check if a segment intersects with a triangle- Parameters:
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 segment- Returns:
- true if the segment intersects at least one segment of the triangle, false otherwise
-
testTri2SegIntersection
public 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.- Parameters:
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 segment- Returns:
- true if the segment intersects at least one segment of the triangle, false otherwise
-
-