Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Mathematics..

Author
Message
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 19th Apr 2003 22:41
I've played around with coding in the past a bit, but I've never been able to understand the math side. Could someone please tell me what a good use for the following commands are? and why they would use them over other commands?

SQRT()
ABS()
INT()
EXP()
COS()
SIN()
TAN()
ACOS()
ASIN()
ATAN()
ATANFULL()
HCOS()
HSIN()
HTAN()

I know thats a lot, even if you have a usefull newbie reference that would help.

matt rochon
21
Years of Service
User Offline
Joined: 15th Mar 2003
Location: Canada
Posted: 19th Apr 2003 22:45
i can explain a couple of them

sqrt() returns the square root of a value
if you need to find the length of one side of a square and all you have is the area of it(for example)

abs() returns the positive equivalent of a number
very useful in 3d to manipulet objects in space (ex: abs(-1) = 1)

int() returns an integer of a floating point number

exp() multiplies a number by itself

...thats where it gets to trig and im not very good at trig so ill leave it there
Tone Eternal
21
Years of Service
User Offline
Joined: 19th Apr 2003
Location: United States
Posted: 19th Apr 2003 22:48
hmm i dunno trig either .. lol. so square root helps to find the length of a line. but what does the length mean? like if it is 30.. is it 30 pixels? or what? and absolute retusn positive.. so abs(5)= = -5?

int() does that turn a x.x to a x?

and exp is understandable.. but the rest of these I dunno about .. please help!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Apr 2003 23:46 Edited at: 19th Apr 2003 23:47
Quote: "but what does the length mean? like if it is 30.. is it 30 pixels? "

It's 30 whatevers...it's just a number, you can take this number from a variable, position, size...anything!

Quote: "and absolute return positive.. so abs(5)= = -5?"

No The positive of 5 is...5!

Quote: "int() does that turn a x.x to a x?"

Yes, but to make it clearer, INT(x.y)= x

Thanks in advance.
All the Best,
StevieVee
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 20th Apr 2003 00:54
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:



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:



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.
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 20th Apr 2003 04:39
with sin or cos you can plot curves or use both and make circle movement

Puffy
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United States
Posted: 24th Apr 2003 07:52
SOH CAH TOA... triangles remember...finding the angle... or the length of a side...

(for people who don't remember geometry or algebra2/trig)

Sine = Opposite/Hypotenuse
Cosine = Adjacent/Hypotenuse
Tanget = Opposite/Adjacent

If you need to know what Tan/Cos/Sin-1 are I'm sure everyone might remember =P *assuming everyone has had up through Alg2/Trig*

RIGHT TRIGANLES ONLY!!!

Opposite = The side opposite the angle you want to find....
Adjacent = The side on the angle...
Hypotenuse = Longest side....

AMD Athlon XP 2100+ OC to 3Ghz/1.5gigs ram/128mb ti4200/120gigs hd/19" monitor/Sound Blaster Audigy Platinum EX/3072kbs Sat Con... I joined in!
Stevo
22
Years of Service
User Offline
Joined: 4th Oct 2002
Location:
Posted: 27th Apr 2003 08:20
This is a site i found on google which is alright

http://school.discovery.com/homeworkhelp/webmath/geometry.html[href][/href]

Stevo
22
Years of Service
User Offline
Joined: 4th Oct 2002
Location:
Posted: 27th Apr 2003 08:23 Edited at: 27th Apr 2003 08:24
This is a site i found on google which is

www.alrightschool.discovery.com/homeworkhelp/webmath/geomet[href]ry.html

trying to get link to work properly

sorry

indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 27th Apr 2003 08:39
[ h r e f ] h t t p : / / w w w . a l r i g h t s c h o o l . d i s c o v e r y . c o m / h o m e w o r k h e l p / w e b m a t h / g e o m e t r y . h t m l [ / h r e f ]



remove spaces to see usage

Login to post a reply

Server time is: 2024-11-24 12:57:29
Your offset time is: 2024-11-24 12:57:29