com.pump.geom.Spiral2D
shape.
You can construct a spiral by calling:
Shape spiral = Spiral2D(centerX, centerY, coilGap, coils, angularOffset, coilOffset, isClockwise)
This demo uses some static helper methods in Spiral2D
that let you define a spiral by its starting and ending coordinates. The static helper methods are:
public static Spiral2D createWithFixedCoilGap( Point2D center, Point2D end, double coilGap); public static Spiral2D createWithFixedCoilCount( Point2D center, Point2D end, double numCoils);
This relies on two other classes:
AbstractShape
: this class takes care of a lot of the details of implementing a java.awt.Shape
object. As long as you provide the PathIterator
this class will take care of methods like Shape#contains(Rectangle2D)
and Shape#intersects(Rectangle2D)
.ParametricPathIterator
: If you supply the x(t) and y(t) function, a function for dx/dt(t) and dy/dt(t), and a model for how to increment t, then this class can convert your parametric graph to a java.awt.geom.PathIterator
. For example a spiral can be expressed as:
x(t) = centerX + coilGap * (t + coilOffset) * cos(2*pi*t + angularOffset) y(t) = centerY + coilGap * (t + coilOffset) * sin(2*pi*t + angularOffset)
The value t
increments by 1.0/8.0 (so there are eight bezier segments per coil), and never exceeds Spiral2D#getCoils()
.
It may be possible to further improve this class by automating the calculation of the derivative and scanning for changes to the control points, but for the time being this implementation satisfies the original requirements for this class.