@@ -125,26 +125,51 @@ public static Shape createRect(double x1, double y1, double x2, double y2) {
125
125
}
126
126
127
127
/**
128
- * Creates a {@link Shape} representing a circle.
129
- * @param centerPos the center of the circle
130
- * @param radius the radius of the circle
131
- * @param points the amount of points used to create the circle (at least 3)
128
+ * Creates a {@link Shape} representing an ellipse.
129
+ * @param centerPos the center of the ellipse
130
+ * @param radiusX the x radius of the ellipse
131
+ * @param radiusY the y radius of the ellipse
132
+ * @param points the amount of points used to create the ellipse (at least 3)
132
133
* @return the created {@link Shape}
133
134
*/
134
- public static Shape createCircle (Vector2d centerPos , double radius , int points ) {
135
+ public static Shape createEllipse (Vector2d centerPos , double radiusX , double radiusY , int points ) {
135
136
if (points < 3 ) throw new IllegalArgumentException ("A shape has to have at least 3 points!" );
136
137
137
138
Vector2d [] pointArray = new Vector2d [points ];
138
139
double segmentAngle = 2 * Math .PI / points ;
139
140
double angle = 0d ;
140
141
for (int i = 0 ; i < points ; i ++) {
141
- pointArray [i ] = centerPos .add (Math .sin (angle ) * radius , Math .cos (angle ) * radius );
142
+ pointArray [i ] = centerPos .add (Math .sin (angle ) * radiusX , Math .cos (angle ) * radiusY );
142
143
angle += segmentAngle ;
143
144
}
144
145
145
146
return new Shape (pointArray );
146
147
}
147
148
149
+ /**
150
+ * Creates a {@link Shape} representing an ellipse.
151
+ * @param centerX the x-position of the center of the ellipse
152
+ * @param centerY the y-position of the center of the ellipse
153
+ * @param radiusX the x radius of the ellipse
154
+ * @param radiusY the y radius of the ellipse
155
+ * @param points the amount of points used to create the ellipse (at least 3)
156
+ * @return the created {@link Shape}
157
+ */
158
+ public static Shape createEllipse (double centerX , double centerY , double radiusX , double radiusY , int points ) {
159
+ return createEllipse (new Vector2d (centerX , centerY ), radiusX , radiusY , points );
160
+ }
161
+
162
+ /**
163
+ * Creates a {@link Shape} representing a circle.
164
+ * @param centerPos the center of the circle
165
+ * @param radius the radius of the circle
166
+ * @param points the amount of points used to create the circle (at least 3)
167
+ * @return the created {@link Shape}
168
+ */
169
+ public static Shape createCircle (Vector2d centerPos , double radius , int points ) {
170
+ return createEllipse (centerPos , radius , radius , points );
171
+ }
172
+
148
173
/**
149
174
* Creates a {@link Shape} representing a circle.
150
175
* @param centerX the x-position of the center of the circle
0 commit comments