We have the first three sorted, but now for the rest (as far as I understand).
exp(x) will return
e to the power x, where
e is the natrual number (about 2.71), such that d/dx(
e^x)=
e^x. If you don't understand that A-level maths, you probably don't need to use this. I can't think of any situations where I'd need to use this, other than some calculator or something.
sin(x) will return sine of x, where x is an angle between 0 and 360 degrees. The value returned is between 1 and -1, and gives a continuous sine wave starting and ending at 0. To see the wave, use this code:
for i=0 to 360
dot i,200-(sin(i)*50)
next i
suspend for key
The values are multiplied by 50 so you can see them (a range of 3 pixels isn't easy to spot) and subtracted from 200 so you can see them on screen and they appear the right way up (y is inverted on a computer screen).
cos(x) returns a similar wave to sin(x), but offset by 90 degrees. It starts and ends at 1. To see the wave, just replace sin with cos in the above code.
Sin and cos are often used together when calculating circular movement, that's what I primarily use them for. If you have an origin, a radius and an angle, you can find the x and y coordinates of a point using sin and cos. (In my case the angle is measured from East, but DB's built in object angles are slightly different, from North I think.) The x position is the origin plus (radius * cos(a)), and the y position is the origin plus (radius * sin(a)). An example of this would be circular camera movement:
sync on
sync rate 30
hide mouse
autocam off
make matrix 1,1000,1000,5,5
x#=500
z#=500
r#=500
do
a#=wrapvalue(a#+mousemovex())
position camera x#+(r#*cos(a#)),200,z#+(r#*sin(a#))
point camera x#,0,z#
sync
loop
Another use for sin and cos, and also tan is finding angles.
tan(x) will return the tangent of x where x is an angle between 0 and 360 degrees. Exceptions are when x = 90, or 90 plus any multiple of 180 (x = 180a + 90), then tan(x) should produce an infinite value and crash the program (there may be inbuilt error checking, I don't know). y=tan(x) is a strange graph, so tan is used mostly for angles.
You have a
right angled triangle. (It
must be right angled for this to work) You know one of the angles is a right angle, so call that one C (angles in capitals, sides in lower case). The side c is the opposite side to angle C, that is if C is the right angle, c will be the longest side (called the hypotenuse). You can name the other angles A and B and the other sides a and b using the same rule (opposite sides to angles). This is just to make it easier to explain. If you don't know trig, you may want to draw this out before you read the rest.
Now, you want to work out one of the side lengths. If you know the other two side lengths, then you can use pythagoras's rule, a^2 + b^2 = c^2, for this you could use the sqrt(x) function above. However, if you only knew one side length, but knew an angle as well, you could use sin, cos or tan to work it out. There are three formulae:
sin(x)=
opposite/
hypotenuse
cos(x)=
adjacent/
hypotenuse
tan(x)=
opposite/
adjacent
or SOHCAHTOA as it is sometimes abbreviated to. I'll use some examples. (At this point you may notice that tan(x) = sin(x) / cos(x))
You need to find length a, but you only have length c and angle A. a is the opposite side to angle A, so you need an equation with opposite in. c is the hypotenuse, so you need an equation with hypotenuse in. You can use the top equation, sin(x)=opp/hyp, or sin(A)=a/c. You are trying to find a, so a bit of rearranging gives a=c*s(A), and since you have values for c and A, you can work this equation out to give a value.
Now you need to find length c, but you only have length b and angle A. Side b is adjacent to angle A, it is the side next to it which isn't the hypotenuse. c is the hypotenuse. Therefore you need to use an equation with adjacent and hypotenuse in, which is the second one, cos(x)=adj/hyp, or cos(A)=b/c. Rearranging it gives b=c*cos(A), and you can put values in to find b.
One last one, you need to find length a, but you only have side b and angle B. You don't have the hypotenuse (c) so you have to use the third equation, tan(x)=opp/adj. The angle is B, so the opposite is b, and the adjacent is a, so tan(B)=b/a. You want to find a, so rearranging gives a=b/tan(B), and you can work this out.
Now you have the equations, what if you have side lengths, but want to work out angles from them? Given the values for sin, cos, or tan, you can work out the angle x from them using asin, acos and atan. From the last example, say you knew a and b, but wanted to work out B? The equation given is tan(B)=b/a, so you would put b/a into the expression atan(b/a), which returns the value of the angle B in degrees. Now there is a slight problem with this. If you look at the graphs, you can see they are not one-one, that is if you take a value on the y axis, there are two x values which will give this y value. I think DB returns the angle closest to zero for any given sin or cos value. To get round this, you can use atanfull(), which when wrapvalued, returns an angle in the full 360 degree range. The atanfull() function is more user friendly than the others, as it allows you to input side lengths instead of making you work out the division yourself.
hsin(x) returns the hyperbolic sine of x, which is something like 0.5(
e^x +
e^-x).
hcos(x) returns the hyperbolic cosine of x, which is something like 0.5(
e^x -
e^-x).
htan(x) returns the hyperbolic tangent of x, which is hsin(x)/hcos(x). I've only just learned about these in A-level maths, and I can't think of uses, except I think the graph of hcos(x) is how a heavy chain fixed between two points will natrually come to rest, or something. I don't use them myself.
Hope that helped
.
Once I was but the learner,
now, I am the Master.