Skip to main content

 Eclipse Community Forums Forum Search:

Home » Modeling » Graphiti » Using polygons to replicate semicircles
Using polygons to replicate semicircles Tue, 26 November 2013 17:52
 Dwight NaylorMessages: 23Registered: 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 272 times)
• Attachment: example2.png
(Size: 22.31KB, Downloaded 314 times)

[Updated on: Tue, 26 November 2013 17:57]

Report message to a moderator

Re: Using polygons to replicate semicircles [message #1216765 is a reply to message #1211952] Thu, 28 November 2013 16:19
 Martin HanyszMessages: 30Registered: November 2013 Member
Hello Dwight,

The first thing that comes to my mind is to use an Ellipse and have half of it clipped by placing it inside an invisible rectangle.

Let's say you want a half-circle with a radius of 10. You create an invisible rectangle with the dimensions 20 x 10 and put an ellipse with the size 20 x 20 at the coordinates (0,0) relative to the invisible rectangle. This should cut off the lower half of the circle. Add a Polyline from (0,10) to (20,10) relative to the invisible rectangle to close the half circle and you have an nicely round semi circle.

I have not tried this myself, but from what I know about how the rendering in Graphiti works, this should be possible.

Best regards,
Martin
Re: Using polygons to replicate semicircles [message #1219209 is a reply to message #1216765] Mon, 02 December 2013 16:04
 Dwight NaylorMessages: 23Registered: June 2012 Junior Member
Thanks Martin, This worked perfectly!

[Updated on: Mon, 02 December 2013 16:05]

Report message to a moderator

 Previous Topic: Hide pin/unpin icon in PaletteCompartmentEntry Next Topic: PropertyChangeListener in new View
Goto Forum:

Current Time: Wed Jun 20 15:41:21 GMT 2018

Powered by FUDForum. Page generated in 0.02074 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software