private Coordinate[] generateSegmentCurve(Coordinate p0, Coordinate p1, double width0, double width1) { LineSegment seg = new LineSegment(p0, p1); double dist0 = width0 / 2; double dist1 = width1 / 2; Coordinate s0 = seg.pointAlongOffset(0, dist0); Coordinate s1 = seg.pointAlongOffset(1, dist1); Coordinate s2 = seg.pointAlongOffset(1, -dist1); Coordinate s3 = seg.pointAlongOffset(0, -dist0); Coordinate[] pts = new Coordinate[] { s0, s1, s2, s3, s0 }; return pts; }
private static Set<Coordinate> computePoints(Coordinate[] coords, double segmentLengthFraction, double offsetDistance) { Set<Coordinate> pointsToAdd = new HashSet<Coordinate>(); for (int j = 0; j < coords.length - 1; j++) { LineSegment segment = new LineSegment(coords[j], coords[j + 1]); pointsToAdd.add(segment.pointAlongOffset(segmentLengthFraction, offsetDistance)); } return pointsToAdd; } }
private Coordinate displaceFromSeg(LineSegment nearSeg, double dist) { double frac = nearSeg.projectionFactor(vertexPt); // displace away from the segment on the same side as the original point int side = nearSeg.orientationIndex(vertexPt); if (side == Orientation.RIGHT) dist = -dist; return nearSeg.pointAlongOffset(frac, dist); }
private Coordinate computeRandomOffset(Coordinate p0, Coordinate p1, double segFrac) { double len = p0.distance(p1); double len2 = len / 2; double offsetLen = (len * Math.random()) - len2; LineSegment seg = new LineSegment(p0, p1); return seg.pointAlongOffset(segFrac, offsetLen); }
/** * Computes the {@link Coordinate} for the point * on the line at the given index, offset by the given distance. * If the index is out of range the first or last point on the * line will be returned. * The computed point is offset to the left of the line if the offset distance is * positive, to the right if negative. * * The Z-ordinate of the computed point will be interpolated from * the Z-ordinates of the line segment containing it, if they exist. * * @param index the index of the desired point * @param offsetDistance the distance the point is offset from the segment * (positive is to the left, negative is to the right) * @return the Coordinate at the given index */ public Coordinate extractPoint(LinearLocation index, double offsetDistance) { LinearLocation indexLow = index.toLowest(linearGeom); return indexLow.getSegment(linearGeom).pointAlongOffset(indexLow.getSegmentFraction(), offsetDistance); }
/** * Computes the {@link Coordinate} for the point * on the line at the given index, offset by the given distance. * If the index is out of range the first or last point on the * line will be returned. * The computed point is offset to the left of the line if the offset distance is * positive, to the right if negative. * * The Z-ordinate of the computed point will be interpolated from * the Z-ordinates of the line segment containing it, if they exist. * * @param index the index of the desired point * @param offsetDistance the distance the point is offset from the segment * (positive is to the left, negative is to the right) * @return the Coordinate at the given index */ public Coordinate extractPoint(double index, double offsetDistance) { LinearLocation loc = LengthLocationMap.getLocation(linearGeom, index); LinearLocation locLow = loc.toLowest(linearGeom); return locLow.getSegment(linearGeom).pointAlongOffset(locLow.getSegmentFraction(), offsetDistance); }
Coordinate bevelEndLeft = mitreMidLine.pointAlongOffset(1.0, bevelHalfLen); Coordinate bevelEndRight = mitreMidLine.pointAlongOffset(1.0, -bevelHalfLen);
void checkOffset(double x0, double y0, double x1, double y1, double segFrac, double offset, double expectedX, double expectedY) { LineSegment seg = new LineSegment(x0, y0, x1, y1); Coordinate p = seg.pointAlongOffset(segFrac, offset); assertTrue(equalsTolerance(new Coordinate(expectedX, expectedY), p, 0.000001)); }