How to use @turf/ellipse - 5 common examples

To help you get started, we’ve selected a few @turf/ellipse 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 uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
const corner1 = this._clickSequence[0];
    const corner2 = groundCoords;

    const minX = Math.min(corner1[0], corner2[0]);
    const minY = Math.min(corner1[1], corner2[1]);
    const maxX = Math.max(corner1[0], corner2[0]);
    const maxY = Math.max(corner1[1], corner2[1]);

    const polygonPoints = bboxPolygon([minX, minY, maxX, maxY]).geometry.coordinates[0];
    const centerCoordinates = getIntermediatePosition(corner1, corner2);

    const xSemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[1])), 0.001);
    const ySemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[3])), 0.001);

    this._setTentativeFeature(ellipse(centerCoordinates, xSemiAxis, ySemiAxis));
  }
github uber / nebula.gl / modules / layers / src / mode-handlers / draw-ellipse-by-bounding-box-handler.js View on Github external
const corner1 = clickSequence[0];
    const corner2 = event.groundCoords;

    const minX = Math.min(corner1[0], corner2[0]);
    const minY = Math.min(corner1[1], corner2[1]);
    const maxX = Math.max(corner1[0], corner2[0]);
    const maxY = Math.max(corner1[1], corner2[1]);

    const polygonPoints = bboxPolygon([minX, minY, maxX, maxY]).geometry.coordinates[0];
    const centerCoordinates = getIntermediatePosition(corner1, corner2);

    const xSemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[1])), 0.001);
    const ySemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[3])), 0.001);

    this._setTentativeFeature(ellipse(centerCoordinates, xSemiAxis, ySemiAxis));

    return result;
  }
}
github uber / nebula.gl / modules / layers / src / mode-handlers / draw-ellipse-using-three-points-handler.js View on Github external
this._setTentativeFeature({
        type: 'Feature',
        geometry: {
          type: 'LineString',
          coordinates: [clickSequence[0], groundCoords]
        }
      });
    } else if (clickSequence.length === 2) {
      const [p1, p2] = clickSequence;

      const centerCoordinates = getIntermediatePosition(p1, p2);
      const xSemiAxis = Math.max(distance(centerCoordinates, point(groundCoords)), 0.001);
      const ySemiAxis = Math.max(distance(p1, p2), 0.001) / 2;
      const options = { angle: bearing(p1, p2) };

      this._setTentativeFeature(ellipse(centerCoordinates, xSemiAxis, ySemiAxis, options));
    }

    return result;
  }
}
github uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
this._setTentativeFeature({
        type: 'Feature',
        geometry: {
          type: 'LineString',
          coordinates: [this._clickSequence[0], groundCoords]
        }
      });
    } else if (this._clickSequence.length === 2) {
      const [p1, p2] = this._clickSequence;

      const centerCoordinates = getIntermediatePosition(p1, p2);
      const xSemiAxis = Math.max(distance(centerCoordinates, point(groundCoords)), 0.001);
      const ySemiAxis = Math.max(distance(p1, p2), 0.001) / 2;
      const options = { angle: bearing(p1, p2) };

      this._setTentativeFeature(ellipse(centerCoordinates, xSemiAxis, ySemiAxis, options));
    }
  }
}
github Turfjs / turf / packages / turf-standard-deviational-ellipse / index.js View on Github external
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,
        semiMinorAxis: semiMinorAxis,
        angle: theta,
        eccentricity: eccentricity,
        pctWithinEllipse: 100 * turf.coordAll(pointsWithinEllipse).length / n
    };
    theEllipse.properties.standardDeviationalEllipse = standardDeviationalEllipseProperties;

    return theEllipse;
};

@turf/ellipse

turf ellipse module

MIT
Latest version published 3 months ago

Package Health Score

96 / 100
Full package analysis

Popular @turf/ellipse functions