From a1800a8184724fa39c7a2d8091060666be3c0e89 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:45:45 +0400 Subject: [PATCH] perform rotation on ellipse --- .../model/calculator/EllipseCalculator.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/creme332/model/calculator/EllipseCalculator.java b/src/main/java/com/github/creme332/model/calculator/EllipseCalculator.java index 3ffdb0cf..fe205a1b 100644 --- a/src/main/java/com/github/creme332/model/calculator/EllipseCalculator.java +++ b/src/main/java/com/github/creme332/model/calculator/EllipseCalculator.java @@ -308,7 +308,23 @@ public int[][] getOrderedPoints(Point2D firstFocus, Point2D secondFocus, Point2D if ((int) rx == 0 || (int) ry == 0) return new int[][] {}; - return getOrderedPoints((int) center.getX(), (int) center.getY(), + int[][] points = getOrderedPoints((int) center.getX(), (int) center.getY(), (int) rx, (int) ry); + + /** + * Angle which the semi-major axis makes with the horizontal. + */ + final double inclinationAngle = (Math.atan2(secondFocus.getY() - firstFocus.getY(), + secondFocus.getX() - firstFocus.getX())); + + // rotate calculated points based on inclination + for (int i = 0; i < points[0].length; i++) { + Point2D vector = new Point2D.Double(points[0][i] - center.getX(), points[1][i] - center.getY()); + vector = PolygonCalculator.rotateVector(vector, inclinationAngle); + points[0][i] = (int) (vector.getX() + center.getX()); + points[1][i] = (int) (vector.getY() + center.getY()); + } + + return points; } }