18.02.2013, 05:06
If you're an avid sa-mp scripter, you may have seen this piece of code before
Up until now, I really had no idea what this code even did, but seeing it applied in mathematics and then seeing applied in sa-mp gives rise to one question.
Look at the diagram below.

(Source: http://en.wikipedia.org/wiki/File:Unit_circle.svg)
t would represent a player's facing angle relative to the x-axis, and the point on the circle would be the point we are trying to solve for.
I know for a fact that the x coordinate is equal to the cos t, and the y coordinate is equal to sin t.
The player's position will not always be at 0, 0 so it's evident that we need to append these values to the player's current position, giving us this
x + cos t
y + sin t
but that produces an error in game and spawns the object to the right of the player (excuse the image sizes)

if we switch the code to be
x + sin t
y + cos t
we get the correct output

Why is that? By the definition of the unit circle, the first example should be correct.
I haven't found any reliable information as to why the initial code (at the top of the post) works, so if you have any knowledge as to why it does, please contribute.
pawn Code:
x += (Distance * floatsin(-r, degrees));
y += (Distance * floatcos(-r, degrees));
Look at the diagram below.

(Source: http://en.wikipedia.org/wiki/File:Unit_circle.svg)
t would represent a player's facing angle relative to the x-axis, and the point on the circle would be the point we are trying to solve for.
I know for a fact that the x coordinate is equal to the cos t, and the y coordinate is equal to sin t.
The player's position will not always be at 0, 0 so it's evident that we need to append these values to the player's current position, giving us this
x + cos t
y + sin t
but that produces an error in game and spawns the object to the right of the player (excuse the image sizes)

if we switch the code to be
x + sin t
y + cos t
we get the correct output

Why is that? By the definition of the unit circle, the first example should be correct.
I haven't found any reliable information as to why the initial code (at the top of the post) works, so if you have any knowledge as to why it does, please contribute.