aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes 'Moving' a circle along a line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark " Watch " New topic
Author

'Moving' a circle along a line

Harold Lime
Ranch Hand

Joined: Jul 20, 2009
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?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
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

Joined: Jul 20, 2009
Posts: 38
I've no idea what 2 means... but the first one works perfectly.

Thanks
Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38
Is it possible to get a set of equally spaced coordinates along curve?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
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.
 
Don't get me started about those stupid light bulbs.
 
subject: 'Moving' a circle along a line