Class VectorUtil


  • public final class VectorUtil
    extends Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  VectorUtil.Winding  
    • 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 + 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​(Vert2fImmutable a, Vert2fImmutable b, Vert2fImmutable c)
      Compute the winding of given points
      static VectorUtil.Winding getWinding​(ArrayList<? extends Vert2fImmutable> vertices)
      Compute the general winding of the vertices
      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
    • 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
    • Constructor Detail

      • VectorUtil

        public VectorUtil()
    • Method Detail

      • copyVec2

        public static float[] copyVec2​(float[] dst,
                                       int dstOffset,
                                       float[] src,
                                       int srcOffset)
        Copies a vector of length 2
        Parameters:
        dst - output vector
        dstOffset - offset of dst in array
        src - input vector
        srcOffset - 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 vector
        dstOffset - offset of dst in array
        src - input vector
        srcOffset - 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 vector
        dstOffset - offset of dst in array
        src - input vector
        srcOffset - 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, no FloatUtil.EPSILON is taken into consideration.
      • isVec3Zero

        public static boolean isVec3Zero​(float[] vec,
                                         int vecOffset)
        Return true if vector is zero, no FloatUtil.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 1
        vec2 - 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 1
        vec2 - vector 2
      • angleVec3

        public static float angleVec3​(float[] vec1,
                                      float[] vec2)
        Return the angle between to vectors in radians
        Parameters:
        vec1 - vector 1
        vec2 - 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 vector
        scale - 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 vector
        scale - 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 vector
        scale - 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 vector
        scale - 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 vector
        scale - 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 vector
        scale - 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 vector
        scale - 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 vector
        scale - 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 1
        v2 - 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 1
        v2 - 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 1
        v2 - 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 1
        v2 - 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 1
        v2 - 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 1
        v2 - 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 value
        p2 - 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 vector
        p2 - 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 1
        b - vector 2
        c - 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 1
        v2 - vertex 2
        v3 - 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 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).
      • triAreaVec2

        public static float triAreaVec2​(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.
      • triAreaVec2

        public static float triAreaVec2​(float[] A,
                                        float[] B,
                                        float[] 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.
      • 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 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.
      • 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 vertex
        b - second triangle vertex
        c - third triangle vertex
        p1 - the vertex in question
        p2 - the vertex in question
        p3 - the vertex in question
        tmpAC -
        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 vertex
        b - second triangle vertex
        c - third triangle vertex
        p1 - the vertex in question
        p2 - the vertex in question
        p3 - the vertex in question
        tmpAC -
        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 vertex
        b - second vertex
        c - third vertex
        Returns:
        true if the points a,b,c are in a ccw order
      • 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
      • getNormalVec2

        public static float[] getNormalVec2​(float[] result,
                                            float[] v1,
                                            float[] v2)
        Parameters:
        result - vec2 result for normal
        v1 - vec2
        v2 - 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 normal
        v1 - vec3
        v2 - vec3
        v3 - vec3
        tmp1Vec3 - temp vec3
        tmp2Vec3 - 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 equation
        normalVec3 -
        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 equation
        v1 - vec3
        v2 - vec3
        v3 - vec3
        temp1V3 -
        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 coords
        ray - here representing an infinite line, origin and direction.
        plane - vec4 plane equation
        epsilon -
        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 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
      • testSeg2SegIntersection

        public static boolean testSeg2SegIntersection​(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:
        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 segment
        b - vertex 2 of first segment
        c - vertex 1 of second segment
        d - 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 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
      • 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 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
      • 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 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