Translating Angle into Xf and Yf? - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: Translating Angle into Xf and Yf? (/thread-5571.html) |
Translating Angle into Xf and Yf? - Z!re - 01-06-2005 Let's say I have an angle, and want to translate that into what I should add to a particles x and y The way I used to do is: Code: ptcl.x = ptcl.x + xf BUT I'm making a particle engine, and i want to be able to specify by angle, instead of xf, yf: Code: angle = 167 Like: 0º, would become: xf = 0, yf = -2 45º, would become: xf = 1, yf = -1 90º, would become: xf = 2, yf = 0 270º, would become: xf = -2, yf = 0 etc, you get it (angles, and resulting xf, yf are just examples, doesent matter where 0º is) Anyone know how to translate angle->(xf, yf).. and (xf, yf)->angle..? Translating Angle into Xf and Yf? - Sterling Christensen - 01-06-2005 Code: xf = magnitude * COS(angle) Translating Angle into Xf and Yf? - l0wrd - 01-07-2005 Sterling is right. Those are the fomula, let me break it down for you. In the two formula below R is the distance of the point from the origin (called radius, just like for a circle) and T is the angle (called theta) counter-clockwise from 0 on the x-axis. Code: X = r * Sin(T) -- l0wrd, probably stalking you. Translating Angle into Xf and Yf? - relsoft - 01-07-2005 Tot get the angle use: Code: a! = atan2(yd,xd) Assuming you use FB. Translating Angle into Xf and Yf? - Ralph - 01-30-2005 Finally, since BASIC, QuickBASIC and VB trig uses angles in radians, use somthing like this: Code: d2r = 3.141593/180 'where d2r means "degrees to radians multiplier" You can also define a function, such as: Code: DEF FNsinD (A) = sin(A * 3.141593/189) Translating Angle into Xf and Yf? - Z!re - 01-30-2005 Already knew that, but thanks anyways |