Skip to content

Instantly share code, notes, and snippets.

@RustyKnight
Created January 2, 2022 04:53
Show Gist options
  • Save RustyKnight/be17d1744340f4d8c15373b736745c0f to your computer and use it in GitHub Desktop.
Save RustyKnight/be17d1744340f4d8c15373b736745c0f to your computer and use it in GitHub Desktop.
Find point on ellipse
protected Point2D pointOnEllipse(double angle, Point2D center, double width, double height) {
width = width / 2d;
height = height / 2d;
angle = Math.toRadians(angle);
double t = Math.atan(width * Math.tan(angle) / height);
return new Point2D.Double(center.getX() + width * Math.cos(t), center.getY() + height * Math.sin(t));
}
protected Point2D pointOnEllipse(double angle, double width, double height) {
width = width / 2d;
height = height / 2d;
angle = Math.toRadians(angle);
double t = Math.atan(width * Math.tan(angle) / height);
return new Point2D.Double(width * Math.cos(t), height * Math.sin(t));
}
@RustyKnight
Copy link
Author

Because it's one of things I'll do once in a while and never remember

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment