How to use the @turf/helpers.radiansToDegrees function in @turf/helpers

To help you get started, we’ve selected a few @turf/helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Turfjs / turf / packages / turf-destination / index.ts View on Github external
} = {},
): Feature {
    // Handle input
    const coordinates1 = getCoord(origin);
    const longitude1 = degreesToRadians(coordinates1[0]);
    const latitude1 = degreesToRadians(coordinates1[1]);
    const bearingRad = degreesToRadians(bearing);
    const radians = lengthToRadians(distance, options.units);

    // Main
    const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
        Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
    const longitude2 = longitude1 + Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),
        Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
    const lng = radiansToDegrees(longitude2);
    const lat = radiansToDegrees(latitude2);

    return point([lng, lat], options.properties);
}
github Turfjs / turf / packages / turf-bearing / index.ts View on Github external
} = {}): number {
    // Reverse calculation
    if (options.final === true) { return calculateFinalBearing(start, end); }

    const coordinates1 = getCoord(start);
    const coordinates2 = getCoord(end);

    const lon1 = degreesToRadians(coordinates1[0]);
    const lon2 = degreesToRadians(coordinates2[0]);
    const lat1 = degreesToRadians(coordinates1[1]);
    const lat2 = degreesToRadians(coordinates2[1]);
    const a = Math.sin(lon2 - lon1) * Math.cos(lat2);
    const b = Math.cos(lat1) * Math.sin(lat2) -
        Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);

    return radiansToDegrees(Math.atan2(a, b));
}
github cheeaun / taxirouter-sg / assets / turf.js View on Github external
var properties = options.properties;

    // Handle input
    var coordinates1 = invariant.getCoord(origin);
    var longitude1 = helpers.degreesToRadians(coordinates1[0]);
    var latitude1 = helpers.degreesToRadians(coordinates1[1]);
    var bearing_rad = helpers.degreesToRadians(bearing);
    var radians = helpers.lengthToRadians(distance, units);

    // Main
    var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
        Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_rad));
    var longitude2 = longitude1 + Math.atan2(Math.sin(bearing_rad) * Math.sin(radians) * Math.cos(latitude1),
        Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
    var lng = helpers.radiansToDegrees(longitude2);
    var lat = helpers.radiansToDegrees(latitude2);

    return helpers.point([lng, lat], properties);
}
github Turfjs / turf / packages / turf-rhumb-bearing / index.ts View on Github external
// φ => phi
    // Δλ => deltaLambda
    // Δψ => deltaPsi
    // θ => theta
    const phi1 = degreesToRadians(from[1]);
    const phi2 = degreesToRadians(to[1]);
    let deltaLambda = degreesToRadians((to[0] - from[0]));
    // if deltaLambdaon over 180° take shorter rhumb line across the anti-meridian:
    if (deltaLambda > Math.PI) { deltaLambda -= 2 * Math.PI; }
    if (deltaLambda < -Math.PI) { deltaLambda += 2 * Math.PI; }

    const deltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));

    const theta = Math.atan2(deltaLambda, deltaPsi);

    return (radiansToDegrees(theta) + 360) % 360;
}
github cheeaun / taxirouter-sg / assets / turf.js View on Github external
var units = options.units;
    var properties = options.properties;

    // Handle input
    var coordinates1 = invariant.getCoord(origin);
    var longitude1 = helpers.degreesToRadians(coordinates1[0]);
    var latitude1 = helpers.degreesToRadians(coordinates1[1]);
    var bearing_rad = helpers.degreesToRadians(bearing);
    var radians = helpers.lengthToRadians(distance, units);

    // Main
    var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
        Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_rad));
    var longitude2 = longitude1 + Math.atan2(Math.sin(bearing_rad) * Math.sin(radians) * Math.cos(latitude1),
        Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
    var lng = helpers.radiansToDegrees(longitude2);
    var lat = helpers.radiansToDegrees(latitude2);

    return helpers.point([lng, lat], properties);
}
github Turfjs / turf / packages / turf-destination / index.ts View on Github external
properties?: P,
    } = {},
): Feature {
    // Handle input
    const coordinates1 = getCoord(origin);
    const longitude1 = degreesToRadians(coordinates1[0]);
    const latitude1 = degreesToRadians(coordinates1[1]);
    const bearingRad = degreesToRadians(bearing);
    const radians = lengthToRadians(distance, options.units);

    // Main
    const latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
        Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad));
    const longitude2 = longitude1 + Math.atan2(Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),
        Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
    const lng = radiansToDegrees(longitude2);
    const lat = radiansToDegrees(latitude2);

    return point([lng, lat], options.properties);
}
github Turfjs / turf / packages / turf-standard-deviational-ellipse / index.js View on Github external
// sigmaY = sqrt((1 / n - 2) * sum((((x - X) * sin(theta)) - ((y - Y) * cos(theta)))^2))
    var sigmaXsum = 0;
    var sigmaYsum = 0;
    featureEach(points, function(point){
      xDeviation = getCoords(point)[0] - getCoords(theMeanCenter)[0];
      yDeviation = getCoords(point)[1] - getCoords(theMeanCenter)[1];
      sigmaXsum += Math.pow((xDeviation * Math.cos(theta)) - (yDeviation * Math.sin(theta)), 2);
      sigmaYsum += Math.pow((xDeviation * Math.sin(theta)) - (yDeviation * Math.cos(theta)), 2);
    });

    var sigmaX = Math.sqrt(sigmaXsum * (1 / (n)));
    var sigmaY = Math.sqrt(sigmaYsum * (1 / (n)));
    sigmaX = radiansToLength(degreesToRadians(sigmaX));
    sigmaY = radiansToLength(degreesToRadians(sigmaY));

    theta = radiansToDegrees(theta);
    var semiMajorAxis, semiMinorAxis;
    if (sigmaX > sigmaY) {
      semiMajorAxis = sigmaX;
      semiMinorAxis = sigmaY;
    } else {
      semiMinorAxis = sigmaX;
      semiMajorAxis = sigmaY;
      theta = theta - 90;
    }

    var theEllipse = ellipse(meanCenter, semiMajorAxis, semiMinorAxis, {angle: theta, steps: steps, properties: properties});
    var eccentricity = (Math.sqrt(Math.pow(semiMajorAxis, 2) - Math.pow(semiMinorAxis, 2))) / semiMajorAxis;
    var pointsWithinEllipse = pointsWithinPolygon(points, turf.featureCollection([theEllipse]));
    var standardDeviationalEllipseProperties = {
        meanCenterCoordinates: getCoord(theMeanCenter),
        semiMajorAxis: semiMajorAxis,