com.jogamp.opengl.math
Class VectorUtil

java.lang.Object
  extended by com.jogamp.opengl.math.VectorUtil

public class VectorUtil
extends Object


Nested Class Summary
static class VectorUtil.Winding
           
 
Field Summary
static int COLLINEAR
           
 
Constructor Summary
VectorUtil()
           
 
Method Summary
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 boolean checkCollinear(float[] v1, float[] v2, float[] v3)
          Check if three vertices are colliniear
static boolean checkEquality(float[] v1, float[] v2)
          Check equality of 2 vec3 vectors
static boolean checkEqualityVec2(float[] v1, float[] v2)
          Check equality of 2 vec2 vectors
static float[] colMatrixVectorMult(float[] colMatrix, float[] vec)
          Column Matrix Vector multiplication
static float computeDeterminant(float[] a, float[] b, float[] c)
          Compute the determinant of 3 vectors
static float computeLength(float[] p0, float[] point)
          Compute distance between 2 points
static float[] computeVector(float[] v1, float[] v2)
          Compute Vector
static float[] cross(float[] vec1, float[] vec2)
          cross product vec1 x vec2
static float dot(float[] vec1, float[] vec2)
          compute the dot product of two points
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 inCircle(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
          Check if vertices in triangle circumcircle
static float[] line2lineIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
          Compute intersection between two lines
static float[] mid(float[] p1, float[] p2)
          Calculate the midpoint of two points
static float mid(float p1, float p2)
          Calculate the midpoint of two values
static float norm(float[] vec)
          Compute the norm of a vector
static float[] normalize(float[] vector)
          Normalize a vector
static float[] rowMatrixVectorMult(float[] rawMatrix, float[] vec)
          Matrix Vector multiplication
static float[] scale(float[] vector, float scale)
          Scales a vector by param
static float[] seg2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d)
          Compute intersection between two segments
static boolean tri2SegIntersection(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c, Vert2fImmutable d, Vert2fImmutable e)
          Check if a segment intersects with a triangle
static float triArea(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
          Computes oriented area of a triangle
static float[] vectorAdd(float[] v1, float[] v2)
          Adds to vectors
static boolean vertexInTriangle(float[] a, float[] b, float[] c, float[] p)
          Check if a vertex is in triangle using barycentric coordinates computation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLLINEAR

public static final int COLLINEAR
See Also:
Constant Field Values
Constructor Detail

VectorUtil

public VectorUtil()
Method Detail

dot

public static float dot(float[] vec1,
                        float[] vec2)
compute the dot product of two points

Parameters:
vec1 - vector 1
vec2 - vector 2
Returns:
the dot product as float

normalize

public static float[] normalize(float[] vector)
Normalize a vector

Parameters:
vector - input vector
Returns:
normalized vector

scale

public static float[] scale(float[] vector,
                            float scale)
Scales a vector by param

Parameters:
vector - input vector
scale - constant to scale by
Returns:
scaled vector

vectorAdd

public static float[] vectorAdd(float[] v1,
                                float[] v2)
Adds to vectors

Parameters:
v1 - vector 1
v2 - vector 2
Returns:
v1 + v2

cross

public static float[] cross(float[] vec1,
                            float[] vec2)
cross product vec1 x vec2

Parameters:
vec1 - vector 1
vec2 - vecttor 2
Returns:
the resulting vector

colMatrixVectorMult

public static float[] colMatrixVectorMult(float[] colMatrix,
                                          float[] vec)
Column Matrix Vector multiplication

Parameters:
colMatrix - column matrix (4x4)
vec - vector(x,y,z)
Returns:
result new float[3]

rowMatrixVectorMult

public static float[] rowMatrixVectorMult(float[] rawMatrix,
                                          float[] vec)
Matrix Vector multiplication

Parameters:
rawMatrix - column matrix (4x4)
vec - vector(x,y,z)
Returns:
result new float[3]

mid

public static float mid(float p1,
                        float p2)
Calculate the midpoint of two values

Parameters:
p1 - first value
p2 - second vale
Returns:
midpoint

mid

public static float[] mid(float[] p1,
                          float[] p2)
Calculate the midpoint of two points

Parameters:
p1 - first point
p2 - second point
Returns:
midpoint

norm

public static float norm(float[] vec)
Compute the norm of a vector

Parameters:
vec - vector
Returns:
vorm

computeLength

public static float computeLength(float[] p0,
                                  float[] point)
Compute distance between 2 points

Parameters:
p0 - a ref point on the line
vec - vector representing the direction of the line
point - the point to compute the relative distance of
Returns:
distance float

checkEquality

public static boolean checkEquality(float[] v1,
                                    float[] v2)
Check equality of 2 vec3 vectors

Parameters:
v1 - vertex 1
v2 - vertex 2
Returns:

checkEqualityVec2

public static boolean checkEqualityVec2(float[] v1,
                                        float[] v2)
Check equality of 2 vec2 vectors

Parameters:
v1 - vertex 1
v2 - vertex 2
Returns:

computeDeterminant

public static float computeDeterminant(float[] a,
                                       float[] b,
                                       float[] c)
Compute the determinant of 3 vectors

Parameters:
a - vector 1
b - vector 2
c - vector 3
Returns:
the determinant value

checkCollinear

public static boolean checkCollinear(float[] v1,
                                     float[] v2,
                                     float[] v3)
Check if three vertices are colliniear

Parameters:
v1 - vertex 1
v2 - vertex 2
v3 - vertex 3
Returns:
true if collinear, false otherwise

computeVector

public static float[] computeVector(float[] v1,
                                    float[] v2)
Compute Vector

Parameters:
v1 - vertex 1
v2 - vertex2 2
Returns:
Vector V1V2

inCircle

public static boolean inCircle(Vert2fImmutable a,
                               Vert2fImmutable b,
                               Vert2fImmutable c,
                               Vert2fImmutable d)
Check if vertices in triangle circumcircle

Parameters:
a - triangle vertex 1
b - triangle vertex 2
c - triangle vertex 3
d - 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).

triArea

public static float triArea(Vert2fImmutable a,
                            Vert2fImmutable b,
                            Vert2fImmutable c)
Computes oriented area of a triangle

Parameters:
a - first vertex
b - second vertex
c - third vertex
Returns:
compute twice the area of the oriented triangle (a,b,c), the area is positive if the triangle is oriented counterclockwise.

vertexInTriangle

public static boolean vertexInTriangle(float[] a,
                                       float[] b,
                                       float[] c,
                                       float[] p)
Check if a vertex is in triangle using barycentric coordinates computation.

Parameters:
a - first triangle vertex
b - second triangle vertex
c - third triangle vertex
p - the vertex in question
Returns:
true if p 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 vertex
b - second vertex
c - 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 vertex
b - second vertex
c - 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

seg2SegIntersection

public static float[] seg2SegIntersection(Vert2fImmutable a,
                                          Vert2fImmutable b,
                                          Vert2fImmutable c,
                                          Vert2fImmutable d)
Compute intersection between two segments

Parameters:
a - vertex 1 of first segment
b - vertex 2 of first segment
c - vertex 1 of second segment
d - vertex 2 of second segment
Returns:
the intersection coordinates if the segments intersect, otherwise returns null

line2lineIntersection

public static float[] line2lineIntersection(Vert2fImmutable a,
                                            Vert2fImmutable b,
                                            Vert2fImmutable c,
                                            Vert2fImmutable d)
Compute intersection between two lines

Parameters:
a - vertex 1 of first line
b - vertex 2 of first line
c - vertex 1 of second line
d - vertex 2 of second line
Returns:
the intersection coordinates if the lines intersect, otherwise returns null

tri2SegIntersection

public static boolean tri2SegIntersection(Vert2fImmutable a,
                                          Vert2fImmutable b,
                                          Vert2fImmutable c,
                                          Vert2fImmutable d,
                                          Vert2fImmutable e)
Check if a segment intersects with a triangle

Parameters:
a - vertex 1 of the triangle
b - vertex 2 of the triangle
c - vertex 3 of the triangle
d - vertex 1 of first segment
e - vertex 2 of first segment
Returns:
true if the segment intersects at least one segment of the triangle, false otherwise


Copyright 2010 JogAmp Community.