Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Jeanne Boyarsky
• Liutauras Vilda
• Campbell Ritchie
• Tim Cooke
• Bear Bibeault
Sheriffs:
• Paul Clapham
• Junilu Lacar
• Knute Snortum
Saloon Keepers:
• Ron McLeod
• Ganesh Patekar
• Tim Moores
• Pete Letkeman
• Stephan van Hulst
Bartenders:
• Carey Brown
• Tim Holloway
• Joe Ess

# 'Moving' a circle along a line

Ranch Hand
Posts: 38

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?

Ranch Hand
Posts: 1535
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.

Harold Lime
Ranch Hand
Posts: 38
I've no idea what 2 means... but the first one works perfectly.

Thanks

Harold Lime
Ranch Hand
Posts: 38
Is it possible to get a set of equally spaced coordinates along curve?

Craig Wood
Ranch Hand
Posts: 1535
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.

 It is sorta covered in the JavaRanch Style Guide.