Stupid trig related question

Monkey Forums/Monkey Programming/Stupid trig related question

silentshark(Posted 2012) [#1]
Hi all,

Just trying to calculate the angular velocity for something I'm playing around with. I can get this working fine in C, but I'm getting strange values returned from my Monkey equivalent. What am I missing?

Here's the C code
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535

double calcAngleMoveX(int angle) {
    return (double) cos(angle * PI / 180);
}

double calcAngleMoveY(int angle) {
    return (double) sin(angle * PI / 180);
}

main()
{
int i;

for (i=0; i<360; i+=45)
    {
	printf("angle %d calcAngleMoveX is %f calcAngleMoveY is %f\n",i,calcAngleMoveX(i), calcAngleMoveY(i)); 
    }
}


..and here are my Monkey equivalent functions, but the numbers returned are nothing like the ones from my C program!

		Function calcanglemovex:Float(angle:Int)
			Return Cos(angle*PI/180)			
		End Function

		Function calcanglemovey:Float(angle:Int)
			Return Sin(angle*PI/180)
		End Function



Rus(Posted 2012) [#2]
If you're working in radians you can try Cosr() and Sinr() instead of Cos() and Sin().


silentshark(Posted 2012) [#3]
yeah, I suspect I've cocked up somewhere between degrees and radians. Thanks for the pointer..


NoOdle(Posted 2012) [#4]
Yea as Rus has said, Sinr takes radians, Sin takes degrees. Stick an r after your Monkey functions and you should be good.


silentshark(Posted 2012) [#5]
Cheers guys.. Duh!


Jesse(Posted 2012) [#6]
I believe that if you remove the Pi/180 from the monkey functions using Sin and Cos you should be ok.