graphics non-percise measuring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drsmooth
    New Member
    • Oct 2007
    • 112

    graphics non-percise measuring

    i am using graphics in a jframe to make a little game im working on...my problem is, i'm new to the application of physics to java...my question is, how do you calculate lets say a force acting on a ball at an angle?

    i set up a program the way i thought to do it, i used the force and times it by the sin of the angle and come up with the xComponent and move the ball that far in the xdirection and use cos and determine the movement in the y direction.

    heres the catch,
    for some force/angle combos, they yComponent will come out as 0.3457467851 or whatever, when i use g.drawOval() i have to cast them to integers so i lose alot of percision.

    how could something like this be avoided? ive spent some time looking around google and havent had any real luck in finding a solution...

    any help would be greatly appreciated.
    thanks in advance,
    ken
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Normally, depending on how you define your angle, the y component is the sine
    of the angle and the x component is the cosine of the angle. Both multiplied
    by the speed or 'force' of the thing you're shooting away.

    A value of +- 0.3 just indicates a change of location of less than one pixel; that
    isn't very much and inevitable.

    kind regards,

    Jos

    Comment

    • drsmooth
      New Member
      • Oct 2007
      • 112

      #3
      ok , im going to try to apply that into my program. i had only a small test set up to see if i could do it, and thats where it seemed like it mattered.

      thanks,
      ken

      Comment

      • drsmooth
        New Member
        • Oct 2007
        • 112

        #4
        hah...i found the problem! a stupid math mistake, i forgot the fact that Math.sin() uses radians...ARGH! !

        thanks for your help,
        ken

        Comment

        Working...