coordinateByRadian method

GeoCoordinate2D coordinateByRadian(
  1. double angle, [
  2. GeoCoordinate2D? center,
  3. double factor = 1.0
])

Get coordinate on an ellipse centered at center at an angle given in radians. If center is not specified, origin (0,0) is assumed. Factor factor is multiplied with the amplitude at the angle to support polar charting

Implementation

GeoCoordinate2D coordinateByRadian(double angle,
    [GeoCoordinate2D? center, double factor = 1.0]) {
  // calculate sin and cos of angle
  double sinr = sin(angle);
  double cosr = cos(angle);
  // calculate x and y positions in ellipse
  // x = +/- ( xradius * yradius * cos(angle) / sqrt( (yradius * cos(angle))^2 + (xradius * sin(angle))^2 )
  // y = +/- ( xradius * yradius * sin(angle) / sqrt( (yradius * cos(angle))^2 + (xradius * sin(angle))^2 )
  double cx = factor *
      (_xy * cosr) /
      sqrt(pow(yRadius * cosr, 2) + pow(xRadius * sinr, 2));
  double cy = factor *
      (_xy * sinr) /
      sqrt(pow(yRadius * cosr, 2) + pow(xRadius * sinr, 2));
  return center == null
      ? GeoCoordinate2D(cx, cy)
      : GeoCoordinate2D(center.x + cx, center.y + cy);
}