Re: Math.cos() problems
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 05 Dec 2007 19:30:22 -0800
Brandon McCombs wrote:
Hello,
I'm trying to do something simple but Java turns it into a federal case. All I want to do is draw a couple circles on a Graphics2D canvas with one movable and attracted to the 2nd one which is stationary. Basically I'm just trying to get basic functionality working that simulates gravitational attraction between the spheres.
I had everything working concerning the movement calculations (force, acceleration, velocity) up to the point of performing the calculation that would generate each new pixel positions for the circle that I am allowing to move. I ran into problems because I had to determine the angle between the moving circle and the stationary one and use the angle in the equations x = rCos(angle) and y = rSin(angle) so I could determine how much the movable circle should move.
The problem is that I have no clue how Java is calculating the cosine and xine of the angle I calculate (even calculating the angle is a chore which may be confusing the problem even further). With respect to what screen location are the trig functions being evaluated? (0,0) on the drawing canvas? Does it matter? I thought it did especially since my angle is based on the location of one of my circles and it isn't at 0,0 on the canvas. Where am I going wrong? This is frustrating. If you need more info let me know.
thanks
Could it be that you are getting messed up because they y axis is upside down? Add pi to your angle before calculating.
--
Knute Johnson
email s/nospam/knute/
.
- Follow-Ups:
- Re: Math.cos() problems
- From: Brandon McCombs
- Re: Math.cos() problems
- References:
- Math.cos() problems
- From: Brandon McCombs
- Math.cos() problems
- Prev by Date: Re: how to use javamail to handle a mail of mime type application/vnd.ms-excel
- Next by Date: Re: The text editor "discussions"
- Previous by thread: Math.cos() problems
- Next by thread: Re: Math.cos() problems
- Index(es):
Relevant Pages
|