aspose file tools*
The moose likes Applets and the fly likes arcs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "arcs" Watch "arcs" New topic
Author

arcs

Chant Dhames
Greenhorn

Joined: Jun 22, 2002
Posts: 8
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.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Chant Dhames
Greenhorn

Joined: Jun 22, 2002
Posts: 8
thx. updated.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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

Joined: Jun 22, 2002
Posts: 8
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!
David G Risner
Ranch Hand

Joined: May 02, 2002
Posts: 30
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.


David G. Risner<br />Software Engineer<br />California State University, Los Angeles
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: arcs