Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Translating Angle into Xf and Yf?
#1
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
ptcl.y = ptcl.y + yf
Which works fine..
BUT
I'm making a particle engine, and i want to be able to specify by angle, instead of xf, yf:
Code:
angle = 167
ptcl.x = ptcl.x + Formula(angle)
ptcl.y = ptcl.y + Formula(angle)

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..?
Reply
#2
Code:
xf = magnitude * COS(angle)
yf = magnitude * SIN(angle)
Magnitude is how far along that angle it moved, angle is in radians.
Reply
#3
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)
Y = r * Cos(T)

--
l0wrd, probably stalking you.
Reply
#4
Tot get the angle use:

Code:
a! = atan2(yd,xd)

Assuming you use FB.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#5
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"
.......
A = 90 'angle A in degrees
SineOfA = SIN(A*d2r)
By using the multiplier d2r and similar, you save a lot of writing and avoid a few errors.

You can also define a function, such as:
Code:
DEF FNsinD (A) = sin(A * 3.141593/189)
A = 90 'angle expressed in degrees
PRINT FNsinD(A) 'this will print the sine of 90 degrees, which = 1.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#6
Already knew that, but thanks anyways Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)