no.geosoft.cc.geometry
Class Geometry
- java.lang.Object
-
- no.geosoft.cc.geometry.Geometry
-
public final class Geometry extends java.lang.ObjectCollection of geometry utility methods. All methods are static.
-
-
Constructor Summary
Constructors Constructor and Description Geometry()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doublecomputeAngle(double[] p0, double[] p1, double[] p2)Find the angle between twree points.static double[]computeCrossProduct(double[] v0, double[] v1)Compute the cross product (a vector) of two vectors.static doublecomputeDotProduct(double[] v0, double[] v1)Compute the dot product (a scalar) between two vectors.static double[]computePointOnLine(double[] p0, double[] p1, double fractionFromP0)Find the point on the line p0,p1 [x,y,z] a given fraction from p0.static double[]computePointOnLine(double x0, double y0, double x1, double y1, double fractionFrom0)Find the point on the line defined by x0,y0,x1,y1 a given fraction from x0,y0.static doublecomputePolygonArea(double[] xy)Compute the area of the specfied polygon.static doublecomputePolygonArea(double[] x, double[] y)Compute the area of the specfied polygon.static double[]computePolygonCentroid(double[] x, double[] y)Compute centorid (center of gravity) of specified polygon.static int[]createArrow(int[] x, int[] y, double length, double angle, double inset)Create the geometry of an arrow.static int[]createArrow(int x0, int y0, int x1, int y1, double length, double angle, double inset)Create geometry for an arrow along the specified line and with tip at x1,y1.static double[]createCircle(double x0, double y0, double radius)Create geometry for a circle.static int[]createCircle(int x0, int y0, int radius)Create geometry for a circle.static double[]createEllipse(double x0, double y0, double dx, double dy)Create the geometry for an unrotated, unskewed ellipse.static int[]createEllipse(int[] x, int[] y)Return the geometry of an ellipse based on its four top points.static int[]createEllipse(int x0, int y0, int dx, int dy)Create the geometry for an unrotated, unskewed ellipse.static double[]createRectangle(double x0, double y0, double width, double height)Create geometry for a rectangle.static int[]createRectangle(int x0, int y0, int width, int height)Create geometry for a rectangle.static int[]createSector(int x0, int y0, int radius, double angle0, double angle1)Create the geometry of a sector of a circle.static int[]createSector(int x0, int y0, int dx, int dy, double angle0, double angle1)Create the geometry of a sector of an ellipse.static double[]createStar(double x0, double y0, double innerRadius, double outerRadius, int nArms)Create geometry of a star.static int[]createStar(int x0, int y0, int innerRadius, int outerRadius, int nArms)Create geometry of a star.static double[]createVector(double[] p0, double[] p1)Construct the vector specified by two points.static doubledistance(double x0, double y0, double x1, double y1, double x, double y)Return distance bwetween the line defined by (x0,y0) and (x1,y1) and the point (x,y).static doubledistance(int x0, int y0, int x1, int y1, int x, int y)Return distance bwetween the line defined by (x0,y0) and (x1,y1) and the point (x,y).static voidextendLine(double[] p0, double[] p1, double toLength)Extend a given line segment to a given length and holding the first point of the line as fixed.static voidextendLine(double[] p0, double[] p1, double toLength, double anchor)Extend a given line segment to a specified length.static double[]findLinePolygonIntersections(double[] x, double[] y, double x0, double y0, double x1, double y1)Find the intersections between a polygon and a straight line.static intfindLineSegmentIntersection(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double[] intersection)Compute the intersection between two line segments, or two lines of infinite length.static voidfindPolygonExtent(double[] x, double[] y, double[] z, double[] xExtent, double[] yExtent, double[] zExtent)Find the 3D extent of a polyline.static voidfindPolygonExtent(int[] x, int[] y, int[] xExtent, int[] yExtent)Find the extent of a polygon.static booleanfindPolygonPosition(int[] x, int[] y, double length, int[] position)Return the x,y position at distance "length" into the given polyline.static booleanisLineIntersectingLine(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)Check if two line segments intersects.static booleanisLineIntersectingRectangle(int lx0, int ly0, int lx1, int ly1, int x0, int y0, int x1, int y1)Check if a specified line intersects a specified rectangle.static booleanisPointInsidePolygon(double[] x, double[] y, double pointX, double pointY)Check if a given point is inside a given (complex) polygon.static booleanisPointInsidePolygon(int[] x, int[] y, int pointX, int pointY)Check if a given point is inside a given polygon.static booleanisPointInsideRectangle(int x0, int y0, int x1, int y1, int x, int y)Check if a specified point is inside a specified rectangle.static booleanisPolygonIntersectingRectangle(int[] x, int[] y, int x0, int y0, int x1, int y1)Check if a specified polygon intersects a specified rectangle.static booleanisPolylineIntersectingRectangle(int[] x, int[] y, int x0, int y0, int x1, int y1)Check if a specified polyline intersects a specified rectangle.static doublelength(double[] v)Return the length of a vector.static doublelength(double[] p0, double[] p1)Compute distance between two points.static doublelength(double x0, double y0, double x1, double y1)Compute the length of the line from (x0,y0) to (x1,y1)static doublelength(int[] x, int[] y, boolean isClosed)Compute the length of a polyline.static doublelength(int x0, int y0, int x1, int y1)Compute the length of the line from (x0,y0) to (x1,y1)static intsameSide(double x0, double y0, double x1, double y1, double px0, double py0, double px1, double py1)Check if two points are on the same side of a given line.
-
-
-
Method Detail
-
isPointInsideRectangle
public static boolean isPointInsideRectangle(int x0, int y0, int x1, int y1, int x, int y)Check if a specified point is inside a specified rectangle.- Parameters:
x0,- y0, x1, y1 Upper left and lower right corner of rectangle (inclusive)x,y- Point to check.- Returns:
- True if the point is inside the rectangle, false otherwise.
-
isPointInsidePolygon
public static boolean isPointInsidePolygon(double[] x, double[] y, double pointX, double pointY)Check if a given point is inside a given (complex) polygon.- Parameters:
x,- y Polygon.pointX,- pointY Point to check.- Returns:
- True if the given point is inside the polygon, false otherwise.
-
isPointInsidePolygon
public static boolean isPointInsidePolygon(int[] x, int[] y, int pointX, int pointY)Check if a given point is inside a given polygon. Integer domain.- Parameters:
x,- y Polygon.pointX,- pointY Point to check.- Returns:
- True if the given point is inside the polygon, false otherwise.
-
computePointOnLine
public static double[] computePointOnLine(double[] p0, double[] p1, double fractionFromP0)Find the point on the line p0,p1 [x,y,z] a given fraction from p0. Fraction of 0.0 whould give back p0, 1.0 give back p1, 0.5 returns midpoint of line p0,p1 and so on. F raction can be >1 and it can be negative to return any point on the line specified by p0,p1.- Parameters:
p0- First coordinale of line [x,y,z].p1- Second coordinale of line [x,y,z].fractionFromP0- Point we are looking for coordinates of- Returns:
- Coordinate of point we are looking for
-
computePointOnLine
public static double[] computePointOnLine(double x0, double y0, double x1, double y1, double fractionFrom0)Find the point on the line defined by x0,y0,x1,y1 a given fraction from x0,y0. 2D version of method above..- Parameters:
x0,- y0 First point defining the linex1,- y1 Second point defining the linefractionFrom0- Distance from (x0,y0)- Returns:
- x, y Coordinate of point we are looking for
-
extendLine
public static void extendLine(double[] p0, double[] p1, double toLength, double anchor)Extend a given line segment to a specified length.- Parameters:
p0,- p1 Line segment to extend [x,y,z].toLength- Length of new line segment.anchor- Specifies the fixed point during extension. If anchor is 0.0, p0 is fixed and p1 is adjusted. If anchor is 1.0, p1 is fixed and p0 is adjusted. If anchor is 0.5, the line is adjusted equally in each direction and so on.
-
extendLine
public static void extendLine(double[] p0, double[] p1, double toLength)Extend a given line segment to a given length and holding the first point of the line as fixed.- Parameters:
p0,- p1 Line segment to extend. p0 is fixed during extensiontoLength- Length of new line segment.
-
length
public static double length(double[] v)
Return the length of a vector.- Parameters:
v- Vector to compute length of [x,y,z].- Returns:
- Length of vector.
-
length
public static double length(double[] p0, double[] p1)Compute distance between two points.- Parameters:
p0,- p1 Points to compute distance between [x,y,z].- Returns:
- Distance between points.
-
length
public static double length(int x0, int y0, int x1, int y1)Compute the length of the line from (x0,y0) to (x1,y1)- Parameters:
x0,- y0 First line end point.x1,- y1 Second line end point.- Returns:
- Length of line from (x0,y0) to (x1,y1).
-
length
public static double length(double x0, double y0, double x1, double y1)Compute the length of the line from (x0,y0) to (x1,y1)- Parameters:
x0,- y0 First line end point.x1,- y1 Second line end point.- Returns:
- Length of line from (x0,y0) to (x1,y1).
-
length
public static double length(int[] x, int[] y, boolean isClosed)Compute the length of a polyline.- Parameters:
x,- y Arrays of x,y coordinatesisClosed- True if this is a closed polygon, false otherwise- Returns:
- Length of polyline defined by x, y and nPoints.
-
distance
public static double distance(int x0, int y0, int x1, int y1, int x, int y)Return distance bwetween the line defined by (x0,y0) and (x1,y1) and the point (x,y). Ref: http://astronomy.swin.edu.au/pbourke/geometry/pointline/ The 3D case should be similar.- Parameters:
x0,- y0 First point of line.x1,- y1 Second point of line.x,- y, Point to consider.- Returns:
- Distance from x,y down to the (extended) line defined by x0, y0, x1, y1.
-
distance
public static double distance(double x0, double y0, double x1, double y1, double x, double y)Return distance bwetween the line defined by (x0,y0) and (x1,y1) and the point (x,y). Ref: http://astronomy.swin.edu.au/pbourke/geometry/pointline/- Parameters:
x0,- y0 First point of line.x1,- y1 Second point of line.x,- y, Point to consider.- Returns:
- Distance from x,y down to the (extended) line defined by x0, y0, x1, y1.
-
computeAngle
public static double computeAngle(double[] p0, double[] p1, double[] p2)Find the angle between twree points. P0 is center point- Parameters:
p0,- p1, p2 Three points finding angle between [x,y,z].- Returns:
- Angle (in radians) between given points.
-
computeDotProduct
public static double computeDotProduct(double[] v0, double[] v1)Compute the dot product (a scalar) between two vectors.- Parameters:
v0,- v1 Vectors to compute dot product between [x,y,z].- Returns:
- Dot product of given vectors.
-
computeCrossProduct
public static double[] computeCrossProduct(double[] v0, double[] v1)Compute the cross product (a vector) of two vectors.- Parameters:
v0,- v1 Vectors to compute cross product between [x,y,z].- Returns:
- Cross product of specified vectors [x,y,z].
-
createVector
public static double[] createVector(double[] p0, double[] p1)Construct the vector specified by two points.- Parameters:
p0,- p1 Points the construct vector between [x,y,z].- Returns:
- v Vector from p0 to p1 [x,y,z].
-
sameSide
public static int sameSide(double x0, double y0, double x1, double y1, double px0, double py0, double px1, double py1)Check if two points are on the same side of a given line. Algorithm from Sedgewick page 350.- Parameters:
x0,- y0, x1, y1 The line.px0,- py0 First point.px1,- py1 Second point.- Returns:
- <0 if points on opposite sides. =0 if one of the points is exactly on the line >0 if points on same side.
-
isLineIntersectingLine
public static boolean isLineIntersectingLine(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)Check if two line segments intersects. Integer domain.- Parameters:
x0,- y0, x1, y1 End points of first line to check.x2,- yy, x3, y3 End points of second line to check.- Returns:
- True if the two lines intersects.
-
isLineIntersectingRectangle
public static boolean isLineIntersectingRectangle(int lx0, int ly0, int lx1, int ly1, int x0, int y0, int x1, int y1)Check if a specified line intersects a specified rectangle. Integer domain.- Parameters:
lx0,- ly0 1st end point of linely1,- ly1 2nd end point of linex0,- y0, x1, y1 Upper left and lower right corner of rectangle (inclusive).- Returns:
- True if the line intersects the rectangle, false otherwise.
-
isPolylineIntersectingRectangle
public static boolean isPolylineIntersectingRectangle(int[] x, int[] y, int x0, int y0, int x1, int y1)Check if a specified polyline intersects a specified rectangle. Integer domain.- Parameters:
x,- y Polyline to check.x0,- y0, x1, y1 Upper left and lower left corner of rectangle (inclusive).- Returns:
- True if the polyline intersects the rectangle, false otherwise.
-
isPolygonIntersectingRectangle
public static boolean isPolygonIntersectingRectangle(int[] x, int[] y, int x0, int y0, int x1, int y1)Check if a specified polygon intersects a specified rectangle. Integer domain.- Parameters:
x- X coordinates of polyline.y- Y coordinates of polyline.x0- X of upper left corner of rectangle.y0- Y of upper left corner of rectangle.x1- X of lower right corner of rectangle.y1- Y of lower right corner of rectangle.- Returns:
- True if the polyline intersects the rectangle, false otherwise.
-
computePolygonArea
public static double computePolygonArea(double[] x, double[] y)Compute the area of the specfied polygon.- Parameters:
x- X coordinates of polygon.y- Y coordinates of polygon.- Returns:
- Area of specified polygon.
-
computePolygonArea
public static double computePolygonArea(double[] xy)
Compute the area of the specfied polygon.- Parameters:
xy- Geometry of polygon [x,y,...]- Returns:
- Area of specified polygon.
-
computePolygonCentroid
public static double[] computePolygonCentroid(double[] x, double[] y)Compute centorid (center of gravity) of specified polygon.- Parameters:
x- X coordinates of polygon.y- Y coordinates of polygon.- Returns:
- Centroid [x,y] of specified polygon.
-
findPolygonExtent
public static void findPolygonExtent(double[] x, double[] y, double[] z, double[] xExtent, double[] yExtent, double[] zExtent)Find the 3D extent of a polyline.- Parameters:
x- X coordinates of polyline.y- Y coordinates of polyline.z- Z coordinates of polyline. May be null if this is a 2D case.xExtent- Will upon return contain [xMin,xMax].yExtent- Will upon return contain [xMin,xMax].zExtent- Will upon return contain [xMin,xMax]. Unused (may be set to null) if z is null.
-
findPolygonExtent
public static void findPolygonExtent(int[] x, int[] y, int[] xExtent, int[] yExtent)Find the extent of a polygon.- Parameters:
x- X coordinates of polygon.y- Y coordinates of polygon.xExtent- Will upon return contain [xMin, xMax]yExtent- Will upon return contain [yMin, yMax]
-
findLineSegmentIntersection
public static int findLineSegmentIntersection(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double[] intersection)Compute the intersection between two line segments, or two lines of infinite length.- Parameters:
x0- X coordinate first end point first line segment.y0- Y coordinate first end point first line segment.x1- X coordinate second end point first line segment.y1- Y coordinate second end point first line segment.x2- X coordinate first end point second line segment.y2- Y coordinate first end point second line segment.x3- X coordinate second end point second line segment.y3- Y coordinate second end point second line segment.intersection[2]- Preallocated by caller to double[2]- Returns:
- -1 if lines are parallel (x,y unset), -2 if lines are parallel and overlapping (x, y center) 0 if intersection outside segments (x,y set) +1 if segments intersect (x,y set)
-
findLinePolygonIntersections
public static double[] findLinePolygonIntersections(double[] x, double[] y, double x0, double y0, double x1, double y1)Find the intersections between a polygon and a straight line. NOTE: This method is only guaranteed to work if the polygon is first preprocessed so that "unneccesary" vertices are removed (i.e vertices on the straight line between its neighbours).- Parameters:
x- X coordinates of polygon.y- Y coordinates of polygon.x0- X first end point of line.y0- Y first end point of line.x1- X second end point of line.y1- Y second end point of line.- Returns:
- Intersections [x,y,x,y...].
-
createEllipse
public static int[] createEllipse(int[] x, int[] y)Return the geometry of an ellipse based on its four top points. Integer domain. The method use the generic createEllipse() method for the main task, and then transforms this according to any rotation or skew defined by the given top points.- Parameters:
x- X array of four top points of ellipse.y- Y array of four top points of ellipse.- Returns:
- Geometry of ellipse [x,y,x,y...].
-
createEllipse
public static int[] createEllipse(int x0, int y0, int dx, int dy)Create the geometry for an unrotated, unskewed ellipse. Integer domain.- Parameters:
x0- X center of ellipse.y0- Y center of ellipse.dx- X ellipse radius.dy- Y ellipse radius.- Returns:
- Ellipse geometry [x,y,x,y,...].
-
createEllipse
public static double[] createEllipse(double x0, double y0, double dx, double dy)Create the geometry for an unrotated, unskewed ellipse. Floating point domain.- Parameters:
x0- X center of ellipse.y0- Y center of ellipse.dx- X ellipse radius.dy- Y ellipse radius.- Returns:
- Ellipse geometry [x,y,x,y,...].
-
createCircle
public static int[] createCircle(int x0, int y0, int radius)Create geometry for a circle. Integer domain.- Parameters:
x0- X center of circle.y0- Y center of circle.radius- Radius of circle.- Returns:
- Geometry of circle [x,y,...]
-
createCircle
public static double[] createCircle(double x0, double y0, double radius)Create geometry for a circle. Floating point domain.- Parameters:
x0- X center of circle.y0- Y center of circle.radius- Radius of circle.- Returns:
- Geometry of circle [x,y,...]
-
createSector
public static int[] createSector(int x0, int y0, int dx, int dy, double angle0, double angle1)Create the geometry of a sector of an ellipse.- Parameters:
x0- X coordinate of center of ellipse.y0- Y coordinate of center of ellipse.dx- X radius of ellipse.dy- Y radius of ellipse.angle0- First angle of sector (in radians).angle1- Second angle of sector (in radians).- Returns:
- Geometry of secor [x,y,...]
-
createSector
public static int[] createSector(int x0, int y0, int radius, double angle0, double angle1)Create the geometry of a sector of a circle.- Parameters:
x0- X coordinate of center of circle.y0- Y coordinate of center of circle.radius- radius of circle.angle0- First angle of sector (in radians).angle1- Second angle of sector (in radians).- Returns:
- Geometry of secor [x,y,...]
-
createArrow
public static int[] createArrow(int[] x, int[] y, double length, double angle, double inset)Create the geometry of an arrow. The arrow is positioned at the end (last point) of the specified polyline, as follows: 0,4--, \ --, \ --, \ --, \ --, -------------------------3-----------1 / --' / --' / --' / --' 2--'- Parameters:
x- X coordinates of polyline of where arrow is positioned in the end. Must contain at least two points.y- Y coordinates of polyline of where arrow is positioned in the end.length- Length along the main axis from point 1 to the projection of point 0.angle- Angle between the main axis and the line 1,0 (and 1,2) in radians.inset- Specification of point 3 [0.0-1.0], 1.0 will put point 3 at distance length from 1, 0.0 will put it at point 1.- Returns:
- Array of the five coordinates [x,y,...].
-
createArrow
public static int[] createArrow(int x0, int y0, int x1, int y1, double length, double angle, double inset)Create geometry for an arrow along the specified line and with tip at x1,y1. See general method above.- Parameters:
x0- X first end point of line.y0- Y first end point of line.x1- X second end point of line.y1- Y second end point of line.length- Length along the main axis from point 1 to the projection of point 0.angle- Angle between the main axis and the line 1,0 (and 1.2)inset- Specification of point 3 [0.0-1.0], 1.0 will put point 3 at distance length from 1, 0.0 will put it at point 1.- Returns:
- Array of the four coordinates [x,y,...].
-
createRectangle
public static int[] createRectangle(int x0, int y0, int width, int height)Create geometry for a rectangle. Returns a closed polygon; first and last points matches. Integer domain.- Parameters:
x0- X corner of rectangle.y0- Y corner of rectangle.width- Width (may be negative to indicate leftwards direction)height- Height (may be negative to indicaten upwards direction)
-
createRectangle
public static double[] createRectangle(double x0, double y0, double width, double height)Create geometry for a rectangle. Returns a closed polygon; first and last points matches. Floating point domain.- Parameters:
x0- X corner of rectangle.y0- Y corner of rectangle.width- Width (may be negative to indicate leftwards direction)height- Height (may be negative to indicaten upwards direction)
-
createStar
public static int[] createStar(int x0, int y0, int innerRadius, int outerRadius, int nArms)Create geometry of a star. Integer domain.- Parameters:
x0- X center of star.y0- Y center of star.innerRadius- Inner radis of arms.outerRadius- Outer radius of arms.nArms- Number of arms.- Returns:
- Geometry of star [x,y,x,y,...].
-
createStar
public static double[] createStar(double x0, double y0, double innerRadius, double outerRadius, int nArms)Create geometry of a star. Floating point domain.- Parameters:
x0- X center of star.y0- Y center of star.innerRadius- Inner radis of arms.outerRadius- Outer radius of arms.nArms- Number of arms.- Returns:
- Geometry of star [x,y,x,y,...].
-
findPolygonPosition
public static boolean findPolygonPosition(int[] x, int[] y, double length, int[] position)Return the x,y position at distance "length" into the given polyline.- Parameters:
x- X coordinates of polyliney- Y coordinates of polylinelength- Requested positionposition- Preallocated to int[2]- Returns:
- True if point is within polyline, false otherwise
-
-
DataMelt 3.0 © DataMelt by jWork.ORG