java.lang.Object
imagingbook.common.geometry.basic.PntUtils
Defines static methods for manipulating 2D points.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Pnt2dCalculates and returns the centroid of the specified point set.static Pnt2dCalculates and returns the centroid of the specified point set.static intSimply counts the points in the specified point set.static Pnt2d[]fromDoubleArray(double[][] da) Converts a given 2D double arraydouble[n][2]to a point arrayPnt2d[n], taking x-coordinates from column 0 and y-coordinates from column 1.static Pnt2d[]makeDoublePoints(double... xy) Creates and returns an array ofPnt2d.PntDoublepoints from the given sequence ofdoublecoordinate values, interpreted as x/y pairs.static Pnt2d[]makeIntPoints(int... xy) Creates and returns an array ofPnt2d.PntIntpoints from the given sequence ofintcoordinate values, interpreted as x/y pairs.static double[][]toDoubleArray(Pnt2d[] pts) Converts a given point arrayPnt2d[n]to a 2D double arraydouble[n][2], with x-coordinates in column 0 and y-coordinates in column 1.
-
Method Details
-
count
Simply counts the points in the specified point set. -
centroid
Calculates and returns the centroid of the specified point set. -
centroid
Calculates and returns the centroid of the specified point set. -
toDoubleArray
Converts a given point arrayPnt2d[n]to a 2D double arraydouble[n][2], with x-coordinates in column 0 and y-coordinates in column 1.- Parameters:
pts- the point array- Returns:
- a 2D double array
-
fromDoubleArray
Converts a given 2D double arraydouble[n][2]to a point arrayPnt2d[n], taking x-coordinates from column 0 and y-coordinates from column 1.- Parameters:
da- a 2D double array- Returns:
- a point array
-
makeIntPoints
Creates and returns an array ofPnt2d.PntIntpoints from the given sequence ofintcoordinate values, interpreted as x/y pairs. Throws an exception if the length of the coordinate sequence is not even. Usage example:Pnt2d[] pts = PntUtils.makeIntPoints(1, 2, 3, 4, 5, 6); // gives [PntInt(1, 2), PntInt(3, 4), PntInt(5, 6)]- Parameters:
xy- an even-numbered sequence of point coordinates- Returns:
- an array of
Pnt2d.PntIntpoints
-
makeDoublePoints
Creates and returns an array ofPnt2d.PntDoublepoints from the given sequence ofdoublecoordinate values, interpreted as x/y pairs. Throws an exception if the length of the coordinate sequence is not even. Usage example:Pnt2d[] pts = PntUtils.makeDoublePoints(1, 2, 3, 4, 5, 6); // gives [PntDouble(1.0, 2.0), PntDouble(3.0, 4.0), PntDouble(5.0, 6.0)]
- Parameters:
xy- an even-numbered sequence of point coordinates- Returns:
- an array of
Pnt2d.PntDoublepoints
-