Skip to content

Commit

Permalink
perform rotation on ellipse
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jul 12, 2024
1 parent 94f8aaf commit a1800a8
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit a1800a8

Please sign in to comment.