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.

Author
Message
lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 24th Aug 2003 19:09
Just wondered what the difference was between theese two commands cos it says the exact same thing about both in the dbp manual?

spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 24th Aug 2003 19:16
Run enclosed snippet and hopefully all will be clear. Surely you have learnt about sine and cosine in school!

The programmer formerly known as sonic
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 24th Aug 2003 19:24
do this

for i=1 to 360
dot i,200-(sin(i)*100)
next i
ink rgb(255,0,0),0
for i=1 to 360
dot i,200-(cos(i)*100)
next i
ink rgb(0,255,0),0
for i=1 to 360
dot 200-(sin(i)*100),200-(cos(i)*100)
next i
repeat
until spacekey()

the result from the first bit (sine) is in white, the result from cos is in red, and useing both of them at the same time gives you the green circle, you can use the values to create cyclic motion or get something to go around in a circle or arc, by useing just 0 to 90 in the circle you have a curve that goes through 90 degrees, lots of use for sin and cos, check your maths books and learn em well.

Mentor.
Andy Igoe
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 24th Aug 2003 19:25
In short

Both functions return a floating point number between 0 and 1.

The value is curved to provide a smooth gradient.

They are 90 degrees offset from each other.

Pneumatic Dryll
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 24th Aug 2003 19:31 Edited at: 24th Aug 2003 19:32
Sine, Cosine and tangent are used to work out the length of sides of argiht-angled triangles.



To find out the length of a side, follow following steps:

- Name each side either hypoteneuse, adjacent or opposite (see diagram)

- Then choose two sides to work with : one side which has your unknown in (X in diagram), and one side which has a known length.

- Depending on the sides you chose, choose a function:

Quote: "Sin(ang) = Opp / Hyp)
Cos(ang) = Adj / Hyp)
Tan(ang) = Opp / Adj)"


- Construct an equation. I'll be using the one from the diagram:

Quote: "sin 30 = 3 / X"


re-arrange:

Quote: "X = 3 sin 30"


which gives X the ength of 1.5cm. ehic, erm, doesn't work. Well the maths was corect but I think a triangle with 30 can't have a bottom side that long but hey it's an example.

Hmm I hope I got that right

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 24th Aug 2003 19:32
D'oh two people posted while I was typing that

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 24th Aug 2003 19:42
I had better things to do at school than go to class , that's why i did not learn it, i think i unerstand sin and cos but what i meant is what is the actual difference between them both cos i have seen some code that used sin and cos why not just use sin twice or cos twice?

Thanx

David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 24th Aug 2003 19:48
Think of it this way: if you used newxvalue nad newzvalue in some code, why not use newxavlue both times? Because it would return the wrong value.

sin 10 is 0.17364817766693034885171662676931
cos 10 is 0.98480775301220805936674302458952

they're just different.

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 24th Aug 2003 19:56
you frequently want things that run 90 degrees out of phase like they do in the sin/cos drawn circle, you COULD do it with sin but thats gonna make your life more difficult, you would have to add 90 to the angle for the second sin and wrap it round when the angle was at 270 (cos 270+90=360), so that would make the code more complicated, and how would you do this in all in sin?

for l=1 to 360 step 5
for i=1 to 360
dot 300-((sin(i)*30)+(cos(l)*100)),200-((cos(i)*30)+(sin(l)*50))
next i
sync
next l
repeat
until spacekey()

its easier to use sin and cos with the same angle values.

Mentor.
lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 24th Aug 2003 21:21
Ah i see it's like left and right they are just different.

Thanx

Guyon
23
Years of Service
User Offline
Joined: 6th Jun 2003
Location: United States
Posted: 25th Aug 2003 07:22
Though you may use atanfull the most. It does all the math for you and especially useful for a shooing game
Dave J
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 25th Aug 2003 16:50
And don't forget:

SOH CAH TOA

"Computers are useless they can only give you answers."
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 25th Aug 2003 17:14
Quote: "SOH CAH TOA"


Oh yeah - forgot that sohcahtoa - what a great phrase.

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 25th Aug 2003 21:22
?

David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 25th Aug 2003 21:41 Edited at: 25th Aug 2003 21:41
Sin = Opp / Hyp Cos = Adj / Hyp Tan = Opp / Adj

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 25th Aug 2003 23:03
erm k!

Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 26th Aug 2003 00:31
If you don't understand it, you really should learn it. It's fundimental for anything vector based. If you don't understand it, you don't know what you're missing. I'm not taking the piss either. Knowing a little bit about SOH CAH TOA and general trigonometry is the basis for all movement of 3D objects. Anything from sliding car/object physics to moving objects in directions they're not facing in, to calculating angles based on directional speeds, to working out distances, to writing your own sliding collision etc etc etc. All of that needs trigonometry, and in all honesty, it's fairly simple to learn and understand, and a key tool in making cool games.

Insiiiiiiiiiiiiiiiiiiiiiiiide!
lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 26th Aug 2003 00:56 Edited at: 26th Aug 2003 00:59
know anywhere that they have a dark basic tutorial on this or is there anyone willing to show me?, cos what you just said fallout is exactly what i want to do, i have been scratching my head trying to figure out moving in a direction that i am not facing using variables but it just seems impossible.

Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 26th Aug 2003 01:52
I don't know actually. There will be a million sources on the internet to help you, but to find one that's nice and complete might be tricky. The basic premise is the triangle and how you can find angles of the triangle from the lengths of the sides, and vice versa.

Hmm .. hopefully someone will be able to throw up a good source. Otherwise, if you do a google search for info on trigonometry, make sure you look at the diagrams and try to visualise how they would apply to DB. If you can visualise how they'd apply to the 3D world, you can use what they teach you about the angles and stuff, use the formulas and apply it to movement and things.

Its hard to explain. You do need some sorta tutorial, or book, or website. Hopefully someone will be able to throw up a few links.

Insiiiiiiiiiiiiiiiiiiiiiiiide!
lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 26th Aug 2003 01:56
ah i seem to have found something about it in the beginners guide to dark basic so i will read this but it says they are higher math commands so i'm sure i will still need help.

lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 26th Aug 2003 06:26
no the book was useless and did not go into any detail at all.

Thade
22
Years of Service
User Offline
Joined: 20th Aug 2003
Location:
Posted: 26th Aug 2003 06:57
And what do want to learn tomorrow?
Cross Product Vector3 ?
lcfcfan
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location: North East, UK
Posted: 26th Aug 2003 07:49
maybe

Dave J
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 26th Aug 2003 16:53
Fallout is right, Trig is one of the most practically used topics in Mathematics and is right up there with Measurement. I know basic Trig is essential for Physics and that's a major part of games, I'm surprised you didn't learn it in school as it's brought up year after year in Math class and Physics (if you take it).

"Computers are useless they can only give you answers."
M00NSHiNE
22
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 26th Aug 2003 17:53
Damn trig did my head in. I could do it, but then I still struggled with it. In fact Im unsure where its used in games - and I got an A for maths! What the hell am I like?

I hated maths in school - but I was blessed with the worst maths teacher ever - she skipped through everything quickly and expected you to understand like >click< that.

"It's amazin' what you can do with a computer and access to t'internet"
Dave J
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 27th Aug 2003 11:03
Yeah, you really need to have studied Physics to see where it all comes into place and why it's nescessary. Trig can be used to find out what exact forces act on an object and after some more math you can work out the final velocity and direction it will head in.

I just noticed no one really covered the Unit Circle properly so here goes, here's a diagram I quickly made in PSP to explain the difference between Sine, Cosine and Tangent:



Okay, so the unit circle is where the functions really come from, it has a radius of 1 and so when put on the cartesian plane you can see the points as 1 always being the highest and -1 always being the lowest. For this reason Sin and Cos will never actually give a value greater or less then 1 and -1 respectively. Tan is the exception because it isn't constrained by the size of the unit circle.

If we take an angle, say 30°, and draw the triangle so it meets the edge of the circle we can work out the values of Sin and Cos, if we draw it beyond the circle and so it meets with an invisible line perpendicular to the X axis we can work out the Tangent. The difference between Cos and Sin are the fact that from the edge of the circle, the value of Sin will go directly left until it meets the Y axis where as Cos will go directly down until it meets the X axis, you can then check where it intercepts and this is the value the calculator will give you.

So as you can see in the example, Sin30° = 0.5 (exactly halfway between the center and the edge of the circle) and Cos30° = 0.866 (closer to the edge of the circle). Tan is the exception because the line will continue past the edge of the circle until it meets the dotted line, it then bounces back left until it hits the Y axis and we get the value. Now imagine we use an angle of something like 70°, the line would continue up and way past the top of the circle so the resultant value will equal 2.747 (greater then 1).

So what are they good for? Well now from one straight line and the angle it makes with the horizontal, we can work out the end height of the line and the end length of the line. Hope this helps somewhat.

"Computers are useless they can only give you answers."
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 27th Aug 2003 14:48 Edited at: 27th Aug 2003 15:24
Why do I have the feeling that just went straight over most peoples heads in this forum?

Ok, here's one use of trig. The simple sliding car program. I'll knock one up. Ok, check the source button.

You couldnt make a convincing car physics engine with this, but it's a good practical demonstration of trig. The cars speed is modelled in two variables (x and z speed), and is totally independant from the direction the car is facing. Using trig, this program gets the direction the car is facing and then works out what x and z speeds should be added to the cars current X and Z speed. It's a simple use of trig, using the processes described above by Exeat, as if working out the side of a triangle.

... so all that stuff you did in school kiddies, where they made us work out the sides of triangles and stuff .... HERE'S A PRACTICAL EXAMPLE OF IT FINALLY BEING USEFUL!!! hehe.

Insiiiiiiiiiiiiiiiiiiiiiiiide!
Dave J
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 28th Aug 2003 13:55
Eek, I didn't think I could get much simpler, okay maybe this will help:

Sine = Triangle Height
Cosine = Triangle Width

lol, nice example Fallout, I couldn't think of a way to have a simple demo using Trig without making it too complicated.

"Computers are useless they can only give you answers."
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 28th Aug 2003 14:48
Quote: "know anywhere that they have a dark basic tutorial on this or is there anyone willing to show me?, cos what you just said fallout is exactly what i want to do, i have been scratching my head trying to figure out moving in a direction that i am not facing using variables but it just seems impossible."


You may want to check out rgt's faq board - I wrote a small tutorial on using sin/cos in games (note: not a tutorial on trig).

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.

Login to post a reply

Server time is: 2026-07-23 00:17:35
Your offset time is: 2026-07-23 00:17:35