Sin,Cos,Tan,ASin,ACos,ATan,ATan2

Blitz3D Forums/Blitz3D Programming/Sin,Cos,Tan,ASin,ACos,ATan,ATan2

Jerome Squalor(Posted 2007) [#1]
Can someone give me a quick explanation of what values the Sin,Cos,Tan,ASin,ACos,ATan,ATan2 return.


Barnabius(Posted 2007) [#2]
These are just the first three of myriad links describing what you want to know. It beats me why don't people try to find answers for themselves first, before asking for help...

http://www.rism.com/Trig/values.htm

http://en.wikipedia.org/wiki/Trigonometric_function

http://www.intmath.com/Trigonometric-functions/Trig-functions-intro.php


Subirenihil(Posted 2007) [#3]
Since you are unaware of what these mean, I can see you have not taken trigonometry. Therefore, here is a crash course in trig.

        /|
    H /  |
    /   _| O
x /    | |
     A
This is a right triangle, as evidenced by the square in the lower-right corner. Here are the full names for all the sides:

A - Adjacent
O - Opposite
H - Hypotenuse

If you know angle x and the length of one of the sides, you can find the length of the other two sides. The trig function are:

{Sine} Sin(x) = O/H
{Cosine} Cos(x) = A/H
{Tangent} Tan(x) = A/O
{Arcsine} Asin(O/H) = x
{Arccosine} Acos(A/H) = x
{Arctangent} Atan(O/A) = x

ATan2 is a special variant on ATan. Instead of directly giving it (O/A) you give it the coordinates of a point and it returns the angle from point (0,0) to that point.

The functions are particularly useful if you want to move something distance p at angle p. To do so;

x=x+p*Cos(q)
y=y+p*Sin(q)

Notice how A in the triangle is parallel to the x axis and O is parallel to the y axis? This means that the movement functions work like this:

x=x+p*(A/H)
y=y+p*(O/H)

We multiply by p because that defines p as the hypotenuse and removes it from the equation.
x=x+p*(A/p) which simplifies to: x=x+A

Tangent is not used as much, so I'm not going to fill up more space explaining its uses. (it is useful somethimes)

ATan and especially ATan2 are useful for thing like homing missiles. (tx,ty) is the coordinates of the target, (mx,my) is the coordinates of the missile. p is the angle at which the missile wants to point:

p=ATan2((tx-mx),(ty-my))

The subtraction makes the target's coordinates relative to the missile's.

Hope I haven't confused you.


Jerome Squalor(Posted 2007) [#4]
Thanks Subirenihil.

By the way I have tried to understand these commands by myself before.


boomboom(Posted 2007) [#5]
Sin is quite useful for doing animated movement or size a bit more naturally. If you run this code (b3d or b+) then you will see it puts in a bit of 'ease' at the min and max ends.



if you look at this graph you can kinda see whats going on:



The values at the top and bottom of the curves are quite 'squashed' so theres not as much change between them as opposed to in the middle, where its alot steeper. If you watch the movement of the first circle, you can see the y movement levels off at the top and bottom like the graph.

The Amp is just a multiplier for the value, as sin only brings back a max of 1 or a min of -1 (which doesn't move very much to see the circles). The freq slows it down, as I am using milliseconds for the time value, which is abit too fast.

Of course this can be used for anything, such as putting a bit of scale animation on to 3D objects like powerups or pickups.


Jerome Squalor(Posted 2007) [#6]
What can the Tan command be used for?


Subirenihil(Posted 2007) [#7]
If you know the angle and one of the sides not the hypotenuse, then you can find the other:

O=Tan(angle)*A
A=Tan(angle)*O

On a circle, if you have 2 rays radiating outward from the center of the circle and you have a line tangent to the circle at the intersection of one of the rays and the circle, then the distance between that intersection and the intersection of the line and the other ray is:

DiameterOfCircle*Tan(AngleBetweenRays)

I don't remember exactly how, but you can calculate pi by using Tan().

That's about how much I know about Tan() and its uses, search the internet for "Tangent", "trig", "trigonometry" for more information.

Another use for Sin is if you are dealing with any triangle, does not have to be a right triangle. If you know the length of one of the sides and two of the angles (actually, if you know 2 angles then you know the third) or if you know the lengths of two of the sides and the angle in between them then you can find the other sides and/or angles.
        c
       /\
   A /    \ B
   /        \
 /            \
b       C      a

Sin(a)/A=Sin(b)/B=Sin(c)/C


slenkar(Posted 2007) [#8]
could sin be used to smoothly move an object from one set of co-ordinates to another?


syntax(Posted 2007) [#9]
sin is often times used to create a ripple effect in a high polygon plain.

I suppose it could be used to make it do a smooth curve but for me, that would be to much work. I would just set up a recording method that would record everything you did and move it your self from one position to another, set each position as a frame in an animation and let it run its animation.

anywho since this is a trig topic, yeah, all i know to do with it at the moment is add custom interactive water with it.