Creating shapes with constructive area
JavaFX offers a rich set of tools for creating basic and complex shapes. Sometimes, though,
those drawing tools alone are not enough to express intricate and delicate shapes. In this
recipe, we will show you how to use the notion of constructive geometry to create new shapes
from the combination of existing shapes.
The approach covered in this recipe is known as Constructive-Area-Geometry (CAG).
It uses Boolean operations to create new shapes from existing sets of shapes. Given
shapes (or sets of shapes) represented by circles A and B, JavaFX supports the following
CAG Boolean operations:
A OR B
Returns the shaded area formed by
both shapes A and B.
(A union B)
A NOT B
Returns the shaded area calculated by
subtracting shape A from B.
(A subtract B)
A AND B
Returns the shaded area created by the
intersection of shapes A and B.
(A intersect B)
These operations are implemented in JavaFX by classes ShapeIntersect and
ShapeSubtract , found in the package javafx.scene.shape . These two classes
are container nodes with sequence properties a:Shape and b:Shape that
represent shape set A and set B used as operands in the geometric operations.