#### Archived

This topic is now archived and is closed to further replies.

# confusing cos and sin

## Recommended Posts

i see a lot of ppl using cos function for their x value i mean pos.x = cos(theta) pos.z= sin(theta) how come? i use sin for pos.x and cos for pos.z very confusing

##### Share on other sites
The variation is most likely explained by a difference in orientation of your coordinate systems relative to each other (which results in a different axis that the distance is being calculated from)

Timkin

##### Share on other sites
If you use a standard unit circle, which has radius of 1 and has its center at the origin, then any point on the perimeter of that circle is described as (cos a, sin a), with "a" being the angle between the positive X axis. In other words, x = cos a and y = sin a. This is how it is commonly taught in Calculus.

Things start to change a bit when you have 3 dimensions and a z-axis.

-Kirk

##### Share on other sites
pos.x = cos(theta)
pos.z = sin(theta)
and
pos.x = sin(theta)
pos.z = cos(theta)
will both give you a full circle if theta goes from 0 to 2*PI

the difference is the starting point of the circle, and the direction of rotation

for:
pos.x = cos(theta)
pos.z = sin(theta)
cos(0)=1 so you will start at x=1, y=0
this will draw in a counter-clockwise direction

for:
pos.x = sin(theta)
pos.z = cos(theta)
sin(0)=0 so you will start at x=0, y=1
this will draw in a clockwise direction

the standard is
pos.x = cos(theta)
pos.z = sin(theta)
as kirkd has stated, and i recomend you use that

but it also depends on where you are taking the angle from
the standard is from the x-axis and round counter-clockwise

if this is all too confusing, goto a maths page and search for "sin", "cos", and "unit circle"

redwyre /vivid
keep it real

##### Share on other sites
its all about what you want "0" to mean directionwise and which way of rotation increases your angle. both cos and sin are just numerical functions that take a floating point number and spit out a number between -1.0 and 1.0

cos a will spit out 1 , 0 , -1 , 0 for 2*k*pi+0, 2*k*pi+pi/2, 2*k*pi+pi, 2*k*pi+3*pi/2 (k is any integer value). for these same values, sin a will spit out 0 , 1 , 0 , -1.

so, assuming we have a coordinate system where y increases to the north(top of the screen) and x increases to the east(the right of the screen):

x=cos(a)
y=sin(a)
will give you (1,0); (0,1); (-1,0); (0,-1), so it starts with 0 being due east, and then rotates counterclockwise as a increases.

x=sin(a)
y=cos(a)
will give you (0,1); (1,0); (0,-1); (-1,0), so it starts with 0 being due north, then rotates clockwise as a increases. if you replace the y with a z, then 0 means "forwards", increasing a will "turn right", and decreasing a will "turn left"

• ### Forum Statistics

• Total Topics
628389
• Total Posts
2982410

• 10
• 9
• 19
• 24
• 11