Using polygons to replicate semicircles [message #1211952] |
Tue, 26 November 2013 17:52 |
Dwight Naylor Messages: 23 Registered: June 2012 |
Junior Member |
|
|
Hello,
I was hoping someone could help me with a graphical issue I've been having.
I've been trying to create a type of node that is represented by a semicircle, and I haven't been having much luck. I was unable to find a native class that would do this, and I've instead used the polygon class, placing a number of points in a semicircle form.
The results are shown below. They aren't bad, but compared with real circles, they're not easy on the eyes.
I've tried increasing the number of points in the polygon, to approach a more rounded circle, but the results were erratic and ugly. The number of points also slowed down re-sizing of the shape significantly.
Can anyone help me on this issue? If there's a better approach than polygons I'd love to hear it, but if not, could polygons be made to look better? Thanks in advance for your time and effort.
-Dwight
EDIT: Including polygon-generation code:
public static Polygon getPolygonForSpecifications(int width, int height,
IGaService gaService, Rectangle invisible) {
int radius = width / 2;
if (height <= width / 2 + 20) {
width = (height - 20);
}
int numPoints = 2* Math.max(radius / 3 + 3, 11);
ArrayList<Point> points = new ArrayList<Point>();
//Create the points in a semicircle
for (int i = 0; i < numPoints; i++) {
double a = i * Math.PI / (numPoints - 1);
double xloc = radius - Math.cos(a) * radius;
//These two IFs are just to make the ends look nicer.
if (i > numPoints / 2) {
xloc += 0.5;
}
if (i <= 1) {
xloc--;
}
points.add(gaService.createPoint((int) xloc,
(int) (radius - Math.sin(a) * radius + 0.5)));
}
return gaService.createPolygon(invisible, points);
}
-
Attachment: example1.png
(Size: 20.71KB, Downloaded 494 times) -
Attachment: example2.png
(Size: 22.31KB, Downloaded 538 times)
[Updated on: Tue, 26 November 2013 17:57] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02184 seconds