Page 1 of 1

Collection of usefull Trig. expressions.

Posted: Sat May 17, 2008 1:10 pm
by jph_wacheski
I am collecting some usefull trig. implementations here. (Mostly so I can find them easily!) I suppose many ppl know this stuff, however some of us had wandering minds in highshool,. . or just could not then imagine an use for it! They should be using game dev. to teach math.
I will post the ones I come across and can explain a use for, so far I got;

Code: Select all

 // find a Point using Direction and Distance from a Given Point
find_x=given_x+(sin(-1*direction*2*PI)*distance);
find_y=given_y+(cos(-1*direction*2*PI)*distance);
also very common and usefull;

Code: Select all

 // set X and Y Componets of Velocity using Direction and Speed
set_velocity_x=speed*sin(-1*direction*2*PI);
set_velocity_y=speed*cos(-1*direction*2*PI);
this one I just hacked out,. not sure this is the best way but it is working for me,.

Code: Select all

// set an objects velocity based on a mouse pointer position (shots in a top down game) currentModel.rotation.Z=atan2((currentModel.position.y-mouse_pointer.position.y),
(currentModel.position.x-mouse_pointer.position.x))+PI/2;
  
currentModel.velocity.x=11*sin(-1*currentModel.rotation.Z);
currentModel.velocity.y=11*cos(-1*currentModel.rotation.Z);

peace

Posted: Sat Oct 24, 2009 10:20 pm
by diki
since it was not immediately obvious to me, i guess i should chip this in for other newbies:

Code: Select all

// get a direction or an angle from a position
rotation = atan2( positionX, positionY )/( -2 * PI );