Search in sources :

Example 11 with PointDoubleXYZ

use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.

the class Graph method moveNodesToMidpoint.

public boolean moveNodesToMidpoint(final String typePath, final Node<Record> node1, final Node<Record> node2) {
    final Point point1 = node1.get3dCoordinates(typePath);
    final Point point2 = node2.get3dCoordinates(typePath);
    final Graph<Record> graph = node1.getGraph();
    final Point midPoint = LineSegmentUtil.midPoint(GeometryFactory.fixed3d(0, 1000.0, 1000.0, 1.0), node2, node1);
    final double x = midPoint.getX();
    final double y = midPoint.getY();
    final double z1 = point1.getZ();
    final double z2 = point2.getZ();
    double z;
    if (z1 == 0 || !Double.isFinite(z1)) {
        z = z2;
    } else if (z2 == 0 || !Double.isFinite(z1)) {
        z = z1;
    } else {
        z = Double.NaN;
    }
    final Point newPoint = new PointDoubleXYZ(x, y, z);
    final Node<Record> newNode = graph.getNode(midPoint);
    if (!Node.hasEdgesBetween(typePath, node1, newNode) && !Node.hasEdgesBetween(typePath, node2, newNode)) {
        if (node1.equals(2, newNode)) {
            moveNode(typePath, node2, node1, newPoint);
        } else if (node2.equals(2, newNode)) {
            moveNode(typePath, node1, node2, newPoint);
        } else {
            moveNode(typePath, node1, newNode, newPoint);
            moveNode(typePath, node2, newNode, newPoint);
        }
        return true;
    } else {
        return false;
    }
}
Also used : PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Record(com.revolsys.record.Record) Point(com.revolsys.geometry.model.Point)

Example 12 with PointDoubleXYZ

use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.

the class PlanarPolygon3D method averagePoint.

/**
 * Computes a point which is the average of all coordinates
 * in a sequence.
 * If the sequence lies in a single plane,
 * the computed point also lies in the plane.
 *
 * @param seq a coordinate sequence
 * @return a Point with averaged ordinates
 */
private Point averagePoint(final LineString line) {
    final int vertexCount = line.getVertexCount();
    double sumX = 0;
    double sumY = 0;
    double sumZ = 0;
    for (int i = 0; i < vertexCount; i++) {
        sumX += line.getCoordinate(i, Geometry.X);
        sumY += line.getCoordinate(i, Geometry.Y);
        sumZ += line.getCoordinate(i, Geometry.Z);
    }
    final double x = sumX / vertexCount;
    final double y = sumY / vertexCount;
    final double z = sumZ / vertexCount;
    return new PointDoubleXYZ(x, y, z);
}
Also used : PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Point(com.revolsys.geometry.model.Point)

Example 13 with PointDoubleXYZ

use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.

the class MiscellaneousTest method testCoordinateNaN.

public void testCoordinateNaN() {
    final Point c1 = GeometryFactory.DEFAULT_3D.point();
    final Point c2 = new PointDoubleXY(3, 4);
    assertEquals(3, c2.getX(), 1E-10);
    assertEquals(4, c2.getY(), 1E-10);
    assertTrue(Double.isNaN(c2.getZ()));
    assertEquals(c1, c1);
    assertEquals(c2, c2);
    assertTrue(!c1.equals(c2));
    assertEquals(new PointDoubleXY(3, 5), new PointDoubleXY(3, 5));
    assertEquals(new PointDoubleXY(3, 5), new PointDoubleXY(3, 5));
    assertTrue(new PointDoubleXYZ(3, 5, 0).equals(new PointDoubleXY(3, 5)));
}
Also used : PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 14 with PointDoubleXYZ

use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.

the class CoordinatesTest method testEquals.

public void testEquals() {
    final Point c1 = new PointDoubleXYZ(1.0, 2, 3);
    final String s = "Not a coordinate";
    assertTrue(!c1.equals(s));
    final Point c2 = new PointDoubleXYZ(1.0, 2.0, 3.0);
    assertTrue(c1.equals(2, c2));
    final Point c3 = new PointDoubleXYZ(1.0, 22.0, 3.0);
    assertTrue(!c1.equals(2, c3));
}
Also used : PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Point(com.revolsys.geometry.model.Point)

Example 15 with PointDoubleXYZ

use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.

the class CoordinatesTest method testEquals2D.

public void testEquals2D() {
    final Point c1 = new PointDoubleXYZ(1.0, 2.0, 3.0);
    final Point c2 = new PointDoubleXYZ(1.0, 2.0, 3.0);
    assertTrue(c1.equals(2, c2));
    final Point c3 = new PointDoubleXYZ(1.0, 22.0, 3.0);
    assertTrue(!c1.equals(2, c3));
}
Also used : PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Point(com.revolsys.geometry.model.Point)

Aggregations

PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)20 Point (com.revolsys.geometry.model.Point)17 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)4 Geometry (com.revolsys.geometry.model.Geometry)2 Record (com.revolsys.record.Record)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BPlusTreeMap (com.revolsys.collection.bplus.BPlusTreeMap)1 IntHashMap (com.revolsys.collection.map.IntHashMap)1 LengthIndexedLine (com.revolsys.geometry.linearref.LengthIndexedLine)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 LineString (com.revolsys.geometry.model.LineString)1 Triangle (com.revolsys.geometry.model.Triangle)1 CoordinatesDistanceComparator (com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator)1 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)1 PointDouble (com.revolsys.geometry.model.impl.PointDouble)1 LineSegment (com.revolsys.geometry.model.segment.LineSegment)1 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)1 List (java.util.List)1 Map (java.util.Map)1