I am tinkering with a bit of Java and would like to 'move' a circle along a curved line to simulate a free-kick in football (soccer).
I know how to draw a curve based on three sets of coordinates and I know how to draw a circle and I can make a circle 'move' by re-drawing it in a slightly different position.
But I can't figure out a way of making the circle move along the line.
The only way I can think of doing it is to get the coordinates of each pixel on the line and then use those to repeatedly draw a circle.
Is there a way to get this information without being a maths genius? Or is there a better way?
There are two fairly straightforward ways:
1 — use a FlatteningPathIterator with a suitably small flatness, say 0.01 to start, to get the coordinates along the curve. You can get a PathIterator from both the QuadCurve2D and CubicCurve2D classes.
2 — use the parametric form of the curve to get (x,y) for [0<= t <= 1.0]
These equations are given in the Field Detail section of the PathIterator interface for the SEG_QUADTO and SEG_CUBICTO fields.
I would try to get points closer together than the distance increment along the curve that you want for your animation. Then you can move along the curve and collect points that are close to your desired distance increment.
In the example here it looks like the parametric form is more amenable to this.
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
Free, earth friendly heat - from the CodeRanch trailboss