Refine search
private void updatePts(Coordinate p, Coordinate seg0, Coordinate seg1) { minPts[0] = p; LineSegment seg = new LineSegment(seg0, seg1); minPts[1] = new Coordinate(seg.closestPoint(p)); }
qeDistances.put(qe, qe.toLineSegment().getLength()); for (QuadEdge qe : qeSorted.keySet()) { LineSegment s = qe.toLineSegment(); s.normalize(); eV.setBorder(true); edge = new Edge(i, s, oV, eV, true); if (s.getLength() < this.threshold) { this.shortLengths.put(i, edge); } else { LineSegment sB = qet.getEdge(1).toLineSegment(); LineSegment sC = qet.getEdge(2).toLineSegment(); sA.normalize(); sB.normalize(); sC.normalize(); Entry<Integer, Edge> entry = this.lengths.firstEntry(); int ind = entry.getKey(); if (entry.getValue().getGeometry().getLength() > this.threshold) { index = ind; e = entry.getValue(); if (eB.getGeometry().getLength() < this.threshold) { this.shortLengths.put(eB.getId(), eB); } else { this.lengths.put(eB.getId(), eB);
private int findFurthestPoint(Coordinate[] pts, int i, int j, double[] maxDistance) { LineSegment seg = new LineSegment(); seg.p0 = pts[i]; seg.p1 = pts[j]; double maxDist = -1.0; int maxIndex = i; for (int k = i + 1; k < j; k++) { Coordinate midPt = pts[k]; double distance = seg.distance(midPt); if (distance > maxDist) { maxDist = distance; maxIndex = k; } } maxDistance[0] = maxDist; return maxIndex; }
private double segmentNearestMeasure(LineSegment seg, Coordinate inputPt, double segmentStartMeasure) { // found new minimum, so compute location distance of point double projFactor = seg.projectionFactor(inputPt); if (projFactor <= 0.0) return segmentStartMeasure; if (projFactor <= 1.0) return segmentStartMeasure + projFactor * seg.getLength(); // projFactor > 1.0 return segmentStartMeasure + seg.getLength(); } }
private static LineSegment computeSegmentForLine(double a, double b, double c) { Coordinate p0; Coordinate p1; /* * Line eqn is ax + by = c * Slope is a/b. * If slope is steep, use y values as the inputs */ if (Math.abs(b) > Math.abs(a)) { p0 = new Coordinate(0.0, c/b); p1 = new Coordinate(1.0, c/b - a/b); } else { p0 = new Coordinate(c/a, 0.0); p1 = new Coordinate(c/a - b/a, 1.0); } return new LineSegment(p0, p1); } }
/** * Compute the projection of a point onto the line determined * by this line segment. * <p> * Note that the projected point * may lie outside the line segment. If this is the case, * the projection factor will lie outside the range [0.0, 1.0]. */ public Coordinate project(Coordinate p) { if (p.equals(p0) || p.equals(p1)) return new Coordinate(p); double r = projectionFactor(p); Coordinate coord = new Coordinate(); coord.x = p0.x + r * (p1.x - p0.x); coord.y = p0.y + r * (p1.y - p0.y); return coord; } /**
private LineString voronoiSide(int idgeom, int side,GeometryFactory geometryFactory, Coordinate circumcenter) { boolean triangleCCW = isCCW(idgeom); // Create linestring to envelope LineSegment sideGeom = getTriangleSegment(idgeom, side); Vector2D direction = new Vector2D(sideGeom.p0, sideGeom.p1); direction = direction.normalize().rotate(triangleCCW ? - Math.PI / 2 : Math.PI / 2).multiply(envelope.maxExtent()); LineSegment voronoiLine = new LineSegment(circumcenter, new Coordinate(direction.getX() + circumcenter.x, direction.getY() + circumcenter.y)); Geometry lineString = voronoiLine.toGeometry(geometryFactory).intersection(geometryFactory.toGeometry(envelope)); if(lineString instanceof LineString && lineString.getLength() > epsilon) { return (LineString)lineString; } else { return null; } }
/** * Compute intersection point of two vectors * @param p1 Origin point * @param v1 Direction from p1 * @param p2 Origin point 2 * @param v2 Direction of p2 * @return Null if vectors are collinear or if intersection is done behind one of origin point */ public static Coordinate vectorIntersection(Coordinate p1, Vector3D v1, Coordinate p2, Vector3D v2) { double delta; Coordinate i = null; // Cramer's rule for compute intersection of two planes delta = v1.getX() * (-v2.getY()) - (-v1.getY()) * v2.getX(); if (delta != 0) { double k = ((p2.x - p1.x) * (-v2.getY()) - (p2.y - p1.y) * (-v2.getX())) / delta; // Fix precision problem with big decimal i = new Coordinate(p1.x + k * v1.getX(), p1.y + k * v1.getY(), p1.z + k * v1.getZ()); if(new LineSegment(p1, new Coordinate(p1.x + v1.getX(), p1.y + v1.getY())).projectionFactor(i) < 0 || new LineSegment(p2, new Coordinate(p2.x + v2.getX(), p2.y + v2.getY())).projectionFactor(i) < 0) { return null; } } return i; }
Coordinate bevelMidPt = new Coordinate(bevelMidX, bevelMidY); LineSegment mitreMidLine = new LineSegment(basePt, bevelMidPt); Coordinate bevelEndLeft = mitreMidLine.pointAlongOffset(1.0, bevelHalfLen); Coordinate bevelEndRight = mitreMidLine.pointAlongOffset(1.0, -bevelHalfLen);
double dx = Math.cos(angle) * radius; double dy = Math.sin(angle) * radius; Coordinate to = new Coordinate(center.x + dx, center.y + dy); calculator.setDirection(azimuth, radius); Point2D dp = calculator.getDestinationGeographicPoint(); to.setOrdinate(0, dp.getX()); to.setOrdinate(1, dp.getY()); LineSegment seg = new LineSegment(coordinates[i], coordinates[i + 1]); Geometry lineseg = seg.toGeometry(los.getFactory());
private Coordinate getControlPoint(LineSegment lineSeg) { double radius = lineSeg.getLength() * fraction; double radian = lineSeg.angle() + Math.toRadians(offsetDegree); double dx = lineSeg.p0.x + (Math.cos(radian) * radius); double dy = lineSeg.p0.y + (Math.sin(radian) * radius); return new Coordinate(dx, dy); } }
} else if (subGeom instanceof Polygon) { Polygon p = (Polygon) subGeom; addSegments(p.getExteriorRing().getCoordinates(), factory, sTRtree); int nbInterior = p.getNumInteriorRing(); for (int j = 0; j < nbInterior; j++) { addSegments(p.getInteriorRingN(j).getCoordinates(), factory, sTRtree); double max = 0; for (int j = 0; j < stepCount; j++) { LineSegment stepLine = new LineSegment(vStart.add(v.multiply(j)).toCoordinate(), vStart.add(v.multiply(j + 1)).toCoordinate()); LineString rayStep = stepLine.toGeometry(factory); List<LineString> interEnv = sTRtree.query(rayStep.getEnvelopeInternal()); if (!interEnv.isEmpty()) { for (LineString lineGeoms : interEnv) {
/** * Gets a {@link LineSegment} representing the segment of the * given linear {@link Geometry} which contains this location. * * @param linearGeom a linear geometry * @return the <tt>LineSegment</tt> containing the location */ public LineSegment getSegment(Geometry linearGeom) { LineString lineComp = (LineString) linearGeom.getGeometryN(componentIndex); Coordinate p0 = lineComp.getCoordinateN(segmentIndex); // check for endpoint - return last segment of the line if so if (segmentIndex >= lineComp.getNumPoints() - 1) { Coordinate prev = lineComp.getCoordinateN(lineComp.getNumPoints() - 2); return new LineSegment(prev, p0); } Coordinate p1 = lineComp.getCoordinateN(segmentIndex + 1); return new LineSegment(p0, p1); }
private void computeMinDistance(LineString line0, LineString line1, GeometryLocation[] locGeom) { if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > minDistance) return; Coordinate[] coord0 = line0.getCoordinates(); Coordinate[] coord1 = line1.getCoordinates(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { for (int j = 0; j < coord1.length - 1; j++) { double dist = CGAlgorithms.distanceLineLine( coord0[i], coord0[i + 1], coord1[j], coord1[j + 1] ); if (dist < minDistance) { minDistance = dist; LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]); LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]); Coordinate[] closestPt = seg0.closestPoints(seg1); locGeom[0] = new GeometryLocation(line0, i, closestPt[0]); locGeom[1] = new GeometryLocation(line1, j, closestPt[1]); } if (minDistance <= terminateDistance) return; } } }
public static void computeDistance(LineString line, Coordinate pt, PointPairDistance ptDist) { Coordinate[] coords = line.getCoordinates(); LineSegment tempSegment = new LineSegment(); for (int i = 0; i < coords.length - 1; i++) { tempSegment.setCoordinates(coords[i], coords[i + 1]); // this is somewhat inefficient - could do better Coordinate closestPt = tempSegment.closestPoint(pt); ptDist.setMinimum(closestPt, pt); } }
private void computeMinDistance(LineString line, Point pt, GeometryLocation[] locGeom) { if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > minDistance) return; Coordinate[] coord0 = line.getCoordinates(); Coordinate coord = pt.getCoordinate(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { double dist = CGAlgorithms.distancePointLine( coord, coord0[i], coord0[i + 1] ); if (dist < minDistance) { minDistance = dist; LineSegment seg = new LineSegment(coord0[i], coord0[i + 1]); Coordinate segClosestPoint = seg.closestPoint(coord); locGeom[0] = new GeometryLocation(line, i, segClosestPoint); locGeom[1] = new GeometryLocation(pt, 0, coord); } if (minDistance <= terminateDistance) return; } }
targetPoint = transformGeometry(targetPoint, crs); LineSegment segment = new LineSegment(observerPoint.getCoordinate(), targetPoint.getCoordinate()); LineString userLine = segment.toGeometry(observerPoint.getFactory()); int previsible = -1; List<Geometry> segments = new ArrayList<Geometry>(); GeometryFactory gf = los.getFactory(); for (int idx = 0; idx < los.getNumGeometries(); idx++) { Coordinate[] coordinates = los.getCoordinates(); for (int i = 0; i < coordinates.length - 1; i++) { int visible = (int) coordinates[i + 1].z; LineSegment seg = new LineSegment(coordinates[i], coordinates[i + 1]); Geometry lineseg = seg.toGeometry(los.getFactory());
private void computeMinDistanceLineLine(LineString line0, LineString line1, boolean flip) { Coordinate[] coord0 = line0.getCoordinates(); Coordinate[] coord1 = line1.getCoordinates(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { for (int j = 0; j < coord1.length - 1; j++) { double dist = CGAlgorithms3D.distanceSegmentSegment(coord0[i], coord0[i + 1], coord1[j], coord1[j + 1]); if (dist < minDistance) { minDistance = dist; // TODO: compute closest pts in 3D LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]); LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]); Coordinate[] closestPt = seg0.closestPoints(seg1); updateDistance(dist, new GeometryLocation(line0, i, closestPt[0]), new GeometryLocation(line1, j, closestPt[1]), flip ); } if (isDone) return; } } }
private void computeMinDistanceLinePoint(LineString line,Point point, boolean flip) { Coordinate[] lineCoord = line.getCoordinates(); Coordinate coord = point.getCoordinate(); // brute force approach! for (int i = 0; i < lineCoord.length - 1; i++) { double dist = CGAlgorithms3D.distancePointSegment(coord, lineCoord[i], lineCoord[i + 1]); if (dist < minDistance) { LineSegment seg = new LineSegment(lineCoord[i], lineCoord[i + 1]); Coordinate segClosestPoint = seg.closestPoint(coord); updateDistance(dist, new GeometryLocation(line, i, segClosestPoint), new GeometryLocation(point, 0, coord), flip); } if (isDone) return; } }
public static void computeDistance(LineString line, Coordinate pt, PointPairDistance ptDist) { Coordinate[] coords = line.getCoordinates(); for (int i = 0; i < coords.length - 1; i++) { tempSegment.setCoordinates(coords[i], coords[i + 1]); // this is somewhat inefficient - could do better Coordinate closestPt = tempSegment.closestPoint(pt); ptDist.setMinimum(closestPt, pt); } }