class PieChart {

  static Point2D calculateEndPoint(double radius, double centerX, double centerY, double ratio) {
    if (ratio > 1) {
      ratio = 1.0;
    }
    
    double radians = ratio * 2 * Math.PI;
    
    // Since we're starting at the top of the circle this is rotated 90 degrees
    // from the normal coordinates. This is why we use sine for x and cosine for y.
    double x = radius * (1 + Math.sin(radians));
    double y = radius * (1 - Math.cos(radians));
    return new Point2D.Double(x + centerX - radius, y + centerY - radius);
  }

}