# Rotation Transform

• ### Question

• Trying to make a function to calculate the degrees of rotation after you transform rotation.

If in rotation, 360 degrees is the same as 0 degrees then:

360 + 1 should = 1 degree

1 - 60 should = 300 degrees

360 + 361 should = 1 degree

0 - 1 should be 359(not negative 359)

0 - 20 should be 340

etc...

Should never return a negative result

0... ...357 358 359 0 1 2 3 4... ...359 0 1 2 3

Would also prefer the answer to be compatible with double precision

Heres my failcode:

```    Public Function IncrementRotation(ByVal CurrentRotation As Double, ByVal Increment As Double) As Double
'Dim result As Double = CurrentRotation + Increment
Dim result As Integer
Select Case Increment
Case Is > 0
'Increasing the rotation
Select Case CurrentRotation + Increment
Case Is > 359
'Result Will Be Greater Than 359
Do
CurrentRotation = CurrentRotation - 359
Loop Until CurrentRotation + Increment < 359
Return CurrentRotation + Increment
Case Is < 360
'Result Will Be Less Than 360
Return CurrentRotation + Increment
End Select
Case Is < 0
'Decreasing the rotation
Select Case CurrentRotation + Increment
Case Is > 0
'Result will be greater than 1
Return CurrentRotation + Increment
Case Is < 0
'Result will be less than 1
Dim AdjustFactor As Double = Math.Abs(CurrentRotation + Increment)
End Select
End Select
Return result
End Function```

Thanks for any help =)

If you want something you've never had, you need to do something you've never done. If you believe something to be true, then one day you will be called upon to demonstrate that truth.

Wednesday, February 8, 2012 9:54 AM

• Hi,

try this:

return (360 + currentrotation + increment) mod 360

Regards, Nico

Wednesday, February 8, 2012 10:10 AM

### All replies

• Hi,

try this:

return (360 + currentrotation + increment) mod 360

Regards, Nico

Wednesday, February 8, 2012 10:10 AM
• Worked Like a charm =) Ty

I was thinking of the mod function... just this whole rotation thing has been twisting me for a while tyvm, now i can go to sleep

If you want something you've never had, you need to do something you've never done. If you believe something to be true, then one day you will be called upon to demonstrate that truth.

Wednesday, February 8, 2012 10:16 AM