/** * Returns a <code>String</code> of the form <I>(x,y,z)</I> . * *@return a <code>String</code> of the form <I>(x,y,z)</I> */ public String toString() { return "(" + x + ", " + y + ", " + getZ() + ")"; }
/** * Sets this <code>Coordinate</code>s (x,y,z) values to that of <code>other</code>. * *@param other the <code>Coordinate</code> to copy */ public void setCoordinate(Coordinate other) { x = other.x; y = other.y; z = other.getZ(); }
/** * Computes the 3-dimensional Euclidean distance to another location. * * @param c a coordinate * @return the 3-dimensional Euclidean distance between the locations */ public double distance3D(Coordinate c) { double dx = x - c.x; double dy = y - c.y; double dz = getZ() - c.getZ(); return Math.sqrt(dx * dx + dy * dy + dz * dz); }
/** * Tests if another coordinate has the same values for the X, Y and Z ordinates. * *@param other a <code>Coordinate</code> with which to do the 3D comparison. *@return true if <code>other</code> is a <code>Coordinate</code> * with the same values for X, Y and Z. */ public boolean equals3D(Coordinate other) { return (x == other.x) && (y == other.y) && ((getZ() == other.getZ()) || (Double.isNaN(getZ()) && Double.isNaN(other.getZ()))); }
/** * Tests if another coordinate has the same value for Z, within a tolerance. * * @param c a coordinate * @param tolerance the tolerance value * @return true if the Z ordinates are within the given tolerance */ public boolean equalInZ(Coordinate c, double tolerance){ return NumberUtil.equalsWithTolerance(this.getZ(), c.getZ(), tolerance); }
/** * @see org.locationtech.jts.geom.CoordinateSequence#getZ(int) */ public double getZ(int index) { if (hasZ()) { return coordinates[index].getZ(); } else { return Double.NaN; } }
/** * Gets the start Z ordinate of the segment * * @return the Z ordinate value */ public double getStartZ() { Coordinate p = ls.getCoordinate(0); return p.getZ(); }
@Override public void setCoordinate(Coordinate other) { x = other.x; y = other.y; z = other.getZ(); m = other.getM(); } @Override
@Override public void setCoordinate(Coordinate other) { x = other.x; y = other.y; z = other.getZ(); m = other.getM(); }
@Override public void setCoordinate(Coordinate other) { x = other.x; y = other.y; z = other.getZ(); m = other.getM(); }
@Override public PrecisionWriter calculate(Coordinate[] coordinates, int maxPrecision) { this.hasZ = !Double.isNaN(coordinates[0].getZ()); this.hasM = !Double.isNaN(coordinates[0].getM()); super.calculate(coordinates, maxPrecision); return this; }
public static Coordinate normalize(Coordinate v) { double len = length(v); return new Coordinate(v.x / len, v.y / len, v.getZ() / len); } /**
/** * @param coord1 * @param coord2 subtracted from coord1 * @return a coordinate the supplies the difference of values for each axis between coord1 and * coord2 */ private static Coordinate diff(final Coordinate coord1, final Coordinate coord2) { return new Coordinate( coord1.getX() - coord2.getX(), coord1.getY() - coord2.getY(), coord1.getZ() - coord2.getZ()); }
public void testConstructor3D() { Coordinate c = new Coordinate(350.2, 4566.8, 5266.3); assertEquals(c.x, 350.2); assertEquals(c.y, 4566.8); assertEquals(c.getZ(), 5266.3); }
public void testDefaultConstructor() { Coordinate c = new Coordinate(); assertEquals(c.x, 0.0); assertEquals(c.y, 0.0); assertEquals(c.getZ(), Coordinate.NULL_ORDINATE); } public void testCopyConstructor3D()
/** * Tests that if the input does not have Z ordinates, neither does the output. * */ public void testComputeZNaN() { Geometry linearGeom = read("LINESTRING (0 0, 10 10 10)"); LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double projIndex = indexedLine.project(new Coordinate(5, 5)); Coordinate projPt = indexedLine.extractPoint(projIndex); assertTrue(Double.isNaN(projPt.getZ() )); }
public void testCopyConstructor3D() { Coordinate orig = new Coordinate(350.2, 4566.8, 5266.3); Coordinate c = new Coordinate(orig); assertEquals(c.x, 350.2); assertEquals(c.y, 4566.8); assertEquals(c.getZ(), 5266.3); } public void testSetCoordinate()