• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

arcs

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it possible to draw an arc on an applet, and then have an object follow that arc by its x, y coordinates? basically, i'd like to drop a ball down the web page, and have it fall in a realistic curve, and thought that having it follow an arc would be the best solution, if possible.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Meridian,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Chant Dhames
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thx. updated.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wish that the standard Java API provided more tools for animation (something akin to Flash would be great!). Unfortunately, there is nothing that allows you to simply describe a path for a sprite to follow - at least there is nothing that I've yet run across (I'd love to be wrong). You have to move the image the hard way - from point to point to point.
I would imagine that more than one person has devised an animation API that does provide the desired functionality. I'd recommend a search on google. If you ever do find something, or if you write something yourself, do let us know, won't you?
Good Luck.
 
Chant Dhames
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I also posted the question on Suns website and received the following reply:
Arc2D.Double ar1;
Rectangle r;
ar1 = new Arc2D.Double(x,y,w,h,st,ex,Arc2D.OPEN);
r = ar1.getBounds2D().getBounds();
for (int x=0; x < r.width; x++)
for (int y=0; y < r.height; y++){if (ar1.intersects(r.x+x,r.y+y,1,1))
// this point is on the arc !!!
From a guy named Noah. I'm not too up on my Math so it'll probably take me a bit to figure this one out. Hopefully it's an easy explanation, i haven't looked up the method calls just yet. But anyway, enjoy!
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks incredibly inefficient to me. It looks through every point in the rectangle that bounds the arc to see if it is part of the arc.
If the arc is part of a circle (as opposed to an ellipse/oval), then if the center of the circle is at cx, cy, and a radius of r, the points on the arc will be:
x = r * Math.cos(theta) + cx;
y = r * Math.sin(theta) + cy;
Where theta is the angle. You could just do a for loop to go through the values of theta you want.
reply
    Bookmark Topic Watch Topic
  • New Topic