Java examples for java.lang:Math Geometry Line
Find the 3D extent of a polyline.
//package com.java2s; public class Main { /**//w ww .j a v a 2 s.c o m * Find the 3D extent of a polyline. * * @param x X coordinates of polyline. * @param y Y coordinates of polyline. * @param z Z coordinates of polyline. May be null if this is a 2D case. * @param xExtent Will upon return contain [xMin,xMax]. * @param yExtent Will upon return contain [xMin,xMax]. * @param zExtent Will upon return contain [xMin,xMax]. Unused (may be set * to null) if z is null. */ public static void findPolygonExtent(double[] x, double[] y, double[] z, double[] xExtent, double[] yExtent, double[] zExtent) { double xMin = +Double.MAX_VALUE; double xMax = -Double.MAX_VALUE; double yMin = +Double.MAX_VALUE; double yMax = -Double.MAX_VALUE; double zMin = +Double.MAX_VALUE; double zMax = -Double.MAX_VALUE; for (int i = 0; i < x.length; i++) { if (x[i] < xMin) { xMin = x[i]; } if (x[i] > xMax) { xMax = x[i]; } if (y[i] < yMin) { yMin = y[i]; } if (y[i] > yMax) { yMax = y[i]; } if (z != null) { if (z[i] < zMin) { zMin = z[i]; } if (z[i] > zMax) { zMax = z[i]; } } } xExtent[0] = xMin; xExtent[1] = xMax; yExtent[0] = yMin; yExtent[1] = yMax; if (z != null) { zExtent[0] = zMin; zExtent[1] = zMax; } } /** * Find the extent of a polygon. * * @param x X coordinates of polygon. * @param y Y coordinates of polygon. * @param xExtent Will upon return contain [xMin, xMax] * @param yExtent Will upon return contain [yMin, yMax] */ public static void findPolygonExtent(int[] x, int[] y, int[] xExtent, // xMin, xMax int[] yExtent) // yMin, yMax { int xMin = +Integer.MAX_VALUE; int xMax = -Integer.MAX_VALUE; int yMin = +Integer.MAX_VALUE; int yMax = -Integer.MAX_VALUE; for (int i = 0; i < x.length; i++) { if (x[i] < xMin) { xMin = x[i]; } if (x[i] > xMax) { xMax = x[i]; } if (y[i] < yMin) { yMin = y[i]; } if (y[i] > yMax) { yMax = y[i]; } } xExtent[0] = xMin; xExtent[1] = xMax; yExtent[0] = yMin; yExtent[1] = yMax; } }