View RSS Feed

Java AWT

Constructing Complex Shapes from Geometry Primitives

Rate this Entry
by , 03-06-2012 at 07:40 PM (1455 Views)
New geometric shapes are created by operations of Boolean at the existing ones. This is what is known as CAG i.e. constructive area geometry. In Java 2D API, shape interface is implemented by the area class. Following Boolean operations are supported by it.

Name:  1.JPG
Views: 2563
Size:  12.4 KB
Constructing Complex Shapes from Geometry Primitives


An intersection at 2 overlapping circles is performed to create the leaves

Java Code:
leaf = new Ellipse2D.Double();
...
leaf1 = new Area(leaf);
leaf2 = new Area(leaf);
...
leaf.setFrame(ew-16, eh-29, 15.0, 15.0);
leaf1 = new Area(leaf);
leaf.setFrame(ew-14, eh-47, 30.0, 30.0);
leaf2 = new Area(leaf);
leaf1.intersect(leaf2);
g2.fill(leaf1);
...
leaf.setFrame(ew+1, eh-29, 15.0, 15.0);
leaf1 = new Area(leaf);
leaf2.intersect(leaf1);
g2.fill(leaf2);
Through subtraction operation, stem is created by overlapping circles.

Java Code:
stem = new Ellipse2D.Double();
...
stem.setFrame(ew, eh-42, 40.0, 40.0);
st1 = new Area(stem);
stem.setFrame(ew+3, eh-47, 50.0, 50.0);
st2 = new Area(stem);
st1.subtract(st2);
g2.fill(st1);
The body of the pear is constructed by performing a union operation on a circle and an oval.

Java Code:
circle = new Ellipse2D.Double();
oval = new Ellipse2D.Double();
circ = new Area(circle);
ov = new Area(oval);
...
circle.setFrame(ew-25, eh, 50.0, 50.0);
oval.setFrame(ew-19, eh-20, 40.0, 70.0);
circ = new Area(circle);
ov = new Area(oval);
circ.add(ov);
g2.fill(circ);

Submit "Constructing Complex Shapes from Geometry Primitives" to Facebook Submit "Constructing Complex Shapes from Geometry Primitives" to Digg Submit "Constructing Complex Shapes from Geometry Primitives" to del.icio.us Submit "Constructing Complex Shapes from Geometry Primitives" to StumbleUpon Submit "Constructing Complex Shapes from Geometry Primitives" to Google

Comments