This week's book giveaway is in the Design forum. We're giving away four copies of Building Microservices and have Sam Newman on-line! See this thread for details.

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.

Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38

posted

0

I've no idea what 2 means... but the first one works perfectly.

Thanks

Harold Lime
Ranch Hand

Joined: Jul 20, 2009
Posts: 38

posted

0

Is it possible to get a set of equally spaced coordinates along curve?

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535

posted

0

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.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com