Package org.oscim.utils.geom
Class GeometryUtils
java.lang.Object
org.oscim.utils.geom.GeometryUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic floatarea(float[] points, int size) Returns the unsigned area of polygon.static floatarea(float[] a, int p1, int p2, int p3) static floatarea(float ax, float ay, float bx, float by, float cx, float cy) static float[]bisectionNorm2D(float[] v1, float[] v2) static float[]center(float[] points, int pointPos, int n, float[] out) Calculates the center of a set of points.static float[]closestPointOnLine2D(float[] pP, float[] pL, float[] vL) Calculate the closest point on a line.static float[]diffVec(float[] a, float[] b) static doubledistance(float[] p, int a, int b) static doubledistance2D(float[] a, float[] b) static floatdistancePointLine2D(float[] pP, float[] pL, float[] vL) Calculate the distance from a point to a line.static floatdotProduct(float[] a, float[] b) static doubledotProduct(float[] p, int a, int b, int c) static float[]intersectionLinePlane(float[] pL, float[] vL, float[] pP, float[] vP) Calculate intersection of a plane with a linestatic float[]intersectionLines2D(float[] pA, float[] vA, float[] pB, float[] vB) static floatisClockwise(float[] points, int size) Is polygon clockwise.static floatisTrisClockwise(float[] pA, float[] pB, float[] pC) Indicates the turn of tris pA-pB-pC.static doublelength(float[] vec) static float[]normalize(float[] vec) static List<float[]>normalizedVectors2D(List<float[]> points, List<Float> outLengths) Calculate the normalized direction vectors of point list (polygon)static float[]normalOfPlane(float[] pA, float[] pB, float[] pC) static booleanpointInPoly(float x, float y, float[] vertices, int length, int offset) Test if point x/y is in polygon defined by vertices[offset ...static float[]scale(float[] v, float scale) static floatsquaredDistance(float[] p, int a, int b) static floatsquareSegmentDistance(float[] p, int a, int b, int c) square distance from a point a to a segment b,cstatic float[]sumVec(float[] a, float[] b)
-
Method Details
-
pointInPoly
public static boolean pointInPoly(float x, float y, float[] vertices, int length, int offset) Test if point x/y is in polygon defined by vertices[offset ... offset+length] -- from www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html If there is only one connected component, then it is optional to repeat the first vertex at the end. It's also optional to surround the component with zero vertices. The polygon may contain multiple separate components, and/or holes, provided that you separate the components and holes with a (0,0) vertex, as follows.- First, include a (0,0) vertex.
- Then include the first component' vertices, repeating its first vertex after the last vertex.
- Include another (0,0) vertex.
- Include another component or hole, repeating its first vertex after the last vertex.
- Repeat the above two steps for each component and hole.
- Include a final (0,0) vertex. Each component or hole's vertices may be listed either clockwise or counter-clockwise.
-
area
public static float area(float[] points, int size) Returns the unsigned area of polygon.- Parameters:
size- the number of point coordinates- Returns:
- unsigned polygon area
-
area
public static float area(float ax, float ay, float bx, float by, float cx, float cy) -
area
public static float area(float[] a, int p1, int p2, int p3) -
bisectionNorm2D
public static float[] bisectionNorm2D(float[] v1, float[] v2) - Parameters:
v1- the first normalized vectorv2- the second normalized vector- Returns:
- the bisection of the to vectors
-
center
public static float[] center(float[] points, int pointPos, int n, float[] out) Calculates the center of a set of points.- Parameters:
points- the points arraypointPos- the start position of pointsn- the number of pointsout- the center output- Returns:
- the center of points
-
closestPointOnLine2D
public static float[] closestPointOnLine2D(float[] pP, float[] pL, float[] vL) Calculate the closest point on a line. See: https://en.wikipedia.org/wiki/Vector_projection#Vector_projection_2- Parameters:
pP- pointpL- point of linevL- vector of line- Returns:
- the closest point on line
-
diffVec
public static float[] diffVec(float[] a, float[] b) - Parameters:
a- first vectorb- second vector- Returns:
- a - b
-
sumVec
public static float[] sumVec(float[] a, float[] b) - Parameters:
a- first vectorb- second vector- Returns:
- a + b
-
squaredDistance
public static float squaredDistance(float[] p, int a, int b) -
squareSegmentDistance
public static float squareSegmentDistance(float[] p, int a, int b, int c) square distance from a point a to a segment b,c -
distance
public static double distance(float[] p, int a, int b) -
distance2D
public static double distance2D(float[] a, float[] b) - Parameters:
a- point a[x,y]b- point b[x,y]- Returns:
- the distance between a and b.
-
distancePointLine2D
public static float distancePointLine2D(float[] pP, float[] pL, float[] vL) Calculate the distance from a point to a line. See: https://en.wikipedia.org/wiki/Vector_projection#Vector_projection_2- Parameters:
pP- pointpL- point of linevL- vector of line- Returns:
- the minimum distance between line and point
-
dotProduct
public static double dotProduct(float[] p, int a, int b, int c) -
dotProduct
public static float dotProduct(float[] a, float[] b) - Parameters:
a- first vectorb- second vector- Returns:
- the dot product
-
intersectionLines2D
public static float[] intersectionLines2D(float[] pA, float[] vA, float[] pB, float[] vB) - Parameters:
pA- position vector of AvA- direction vector of ApB- position vector of BvB- direction vector of B- Returns:
- the intersection point
-
intersectionLinePlane
public static float[] intersectionLinePlane(float[] pL, float[] vL, float[] pP, float[] vP) Calculate intersection of a plane with a line- Parameters:
pL- position vector of linevL- direction vector of linepP- position vector of planevP- normal vector of plane- Returns:
- the intersection point
-
isClockwise
public static float isClockwise(float[] points, int size) Is polygon clockwise. Note that the coordinate system is left hand side.- Parameters:
points- the points arraysize- the number of point coordinates- Returns:
- the signed area of the polygon positive: clockwise negative: counter-clockwise 0: collinear
-
isTrisClockwise
public static float isTrisClockwise(float[] pA, float[] pB, float[] pC) Indicates the turn of tris pA-pB-pC. Note that the coordinate system is left hand side.- Returns:
- positive: clockwise negative: counter-clockwise 0: collinear
-
length
public static double length(float[] vec) - Returns:
- the length of the vector
-
normalize
public static float[] normalize(float[] vec) - Returns:
- the normalized vector (with length 1)
-
normalizedVectors2D
Calculate the normalized direction vectors of point list (polygon)- Parameters:
points- the list of 2D pointsoutLengths- the optional list to store lengths of vectors- Returns:
- the normalized direction vectors
-
normalOfPlane
public static float[] normalOfPlane(float[] pA, float[] pB, float[] pC) - Parameters:
pA- first point of planepB- second point of planepC- third point of plane- Returns:
- the normal of plane
-
scale
public static float[] scale(float[] v, float scale) - Parameters:
v- the vectorscale- the scale- Returns:
- the scaled vector
-