0

I am trying to rotate a box in java using a rotation matrix.

(I am using the LWJGL and Slick 2D libraries)

my code to rotate 1 point around the center point is this:

point1X = (float) (centerX * Math.cos(rotation) - centerY * Math.sin(rotation));
point1Y = (float) (centerX * Math.sin(rotation) + centerY * Math.cos(rotation));

Right now I just update the rotation every update like so:

rotation += delta * 0.001;

This works great except the rotation number does not seem to correspond to a degree from 0˚ to 360˚

Is there a formula or something that will translate the rotation number to a readable degree and vice versa?

Harrison
  • 688
  • 7
  • 15
  • 1
    I am not a java expert, but I would expect `sin` and `cos` functions to expect inputs in radians. If you want degrees, use `sin(rotation/PI*180)` – j_kubik Aug 17 '13 at 18:14

1 Answers1

2

Normally, trig functions expect their arguments to be in radians, not degrees.

2*pi radians = 360 degrees.

John R. Strohm
  • 7,547
  • 2
  • 28
  • 33
  • 1
    @Harrison You might prefer using `Math.toRadians(angdeg)` and `Math.toDegrees(angrad)` in your code, though. – sgbj Aug 17 '13 at 18:39