• Post Reply Bookmark Topic Watch Topic
  • New Topic
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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

'Moving' a circle along a line

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've no idea what 2 means... but the first one works perfectly.

Thanks
 
Harold Lime
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to get a set of equally spaced coordinates along curve?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic