Code: Select all
double RadToDeg ( double Value ) {
return Value*(180/3.14);
}
double PointDirection ( double X1, double Y1, double X2, double Y2 ) {
return RadToDeg ( atan2 ( Y2-Y1, X2-X1 ) );
}
// returns the x and y coordinates for a rotation and a distance.
double LengthDir_X (double x, double dist, double dir) { /
return x+cos(dir*3.14/180)*dist;
}
double LengthDir_Y (double y, double dist, double dir) {
return y+sin(dir*3.14/180)*dist;
}
I have to thank the guys at the U3d (forum.ultimate3d.org) community for most of the math though.
I just put it into a function. (u3d is a 3d engine for an interprited language called gamemaker language.)
This is how to use it.
Code: Select all
//PointDirection(x1,y1,x2,y2);
PointDirection(0,0,0,10); //returns 180
//LengthDir_X(X,Distance,Rotation);
LengthDir_X(0,4,70);//1.37
//LengthDir_Y(Y,Distance,Rotation);
LengthDir_Y(0,4,70);//3.75