/** * Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians, * miles, or kilometers; and steps for precision. * * @param center a {@link Point} which the circle will center around * @param radius the radius of the circle * @param steps number of steps which make up the circle parameter * @param units one of the units found inside {@link TurfConstants.TurfUnitCriteria} * @return a {@link Polygon} which represents the newly created circle * @since 3.0.0 */ public static Polygon circle(@NonNull Point center, double radius, int steps, @TurfConstants.TurfUnitCriteria String units) { List<Point> coordinates = new ArrayList<>(); for (int i = 0; i < steps; i++) { coordinates.add(TurfMeasurement.destination(center, radius, i * 360d / steps, units)); } coordinates.add(coordinates.get(0)); List<List<Point>> coordinate = new ArrayList<>(); coordinate.add(coordinates); return Polygon.fromLngLats(coordinate); } }
/** * Takes two {@link Point}s and returns a point midway between them. The midpoint is calculated * geodesically, meaning the curvature of the earth is taken into account. * * @param from first point used for calculating the midpoint * @param to second point used for calculating the midpoint * @return a {@link Point} midway between point1 and point2 * @see <a href="http://turfjs.org/docs/#midpoint">Turf Midpoint documentation</a> * @since 1.3.0 */ public static Point midpoint(@NonNull Point from, @NonNull Point to) { double dist = distance(from, to, TurfConstants.UNIT_MILES); double heading = bearing(from, to); return destination(from, dist / 2, heading, TurfConstants.UNIT_MILES); }
} else { double direction = bearing(coords.get(i), coords.get(i - 1)) - 180; return destination(coords.get(i), overshot, direction, units);
Point interpolated = TurfMeasurement.destination(coords.get(i), overshot, direction, units); slice.add(interpolated); Point interpolated = TurfMeasurement.destination(coords.get(i), overshot, direction, units); slice.add(interpolated); return LineString.fromLngLats(slice);
@Test public void testDestination() throws TurfException { Point pt1 = Point.fromLngLat(-75.0, 39.0); double dist = 100; double bear = 180; assertNotNull(TurfMeasurement.destination(pt1, dist, bear, TurfConstants.UNIT_KILOMETERS)); }
(Point) stop.geometry()); Feature perpendicularPt1 = Feature.fromGeometry( TurfMeasurement.destination(pt, heightDistance, direction + 90, TurfConstants.UNIT_MILES)); Feature perpendicularPt2 = Feature.fromGeometry( TurfMeasurement.destination(pt, heightDistance, direction - 90, TurfConstants.UNIT_MILES)); LineIntersectsResult intersect = lineIntersects(