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.

DarkBASIC Discussion / sin and cosine help

Author
Message
Francesco
21
Years of Service
User Offline
Joined: 11th Apr 2004
Location: Milan, Italy
Posted: 23rd May 2004 22:03
What do the sin and cosine commands actually do...I mean, I know they are very useful because I saw them in lots of advanced codes, and that they have something to do with trigonometry(is that an English word? If not sorry ), but I really don't understand them.
Please help!

Non si inalberi mica con me, sa!
Lei è venuto qui, lei ha il tombino intasato!
Siamo uno spurgo serio, noi!
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 23rd May 2004 22:10
This image will explain ye:



The angle value is the input value. Sin 90 returns 1.00 for example.

Cos and Sin are useful for moving objects, bouncing objects, and many other things.

Quote: "
UPDATED

Amd 2800+ 1024mb pc3200 A7N8X - Deluxe Ati Radeon 9800PRO 256mb
"
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 23rd May 2004 22:36 Edited at: 23rd May 2004 22:49
btw, I will make an example, stay tuned for something special

<edit>

Here it is, ala ferrywheel



Quote: "
UPDATED

Amd 2800+ 1024mb pc3200 A7N8X - Deluxe Ati Radeon 9800PRO 256mb
"
Francesco
21
Years of Service
User Offline
Joined: 11th Apr 2004
Location: Milan, Italy
Posted: 23rd May 2004 23:28
Thanks for the image and for the programme. Think I'll work on those(unless you're willing to give more information ).
Thanks

Non si inalberi mica con me, sa!
Lei è venuto qui, lei ha il tombino intasato!
Siamo uno spurgo serio, noi!
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 23rd May 2004 23:32
I would love explaining the example, but I've got exams tomorrow

Quote: "
UPDATED

Amd 2800+ 1024mb pc3200 A7N8X - Deluxe Ati Radeon 9800PRO 256mb
"
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th May 2004 04:02 Edited at: 24th May 2004 04:14
Most likely, you've used those functions before and didn't even know it. newXvalue and newZvalue.




Suppose you have a character at (x,z) and rotated by 37 degrees. (most likely rotated on its y-axis) And each step the character takes it moves 10 units.

x = newxvalue(x, 37, 10)
z = newzvalue(z, 37, 10)

what "cos(angle)*distance" does is it gets the real distance for the character to move on the x-axis. You only want the character to move 10 units. So if the character moves 10 units up and 10 units to the right, it would have actually moved 14.14 units from its previous place.(using pythagora thearom) So what these functions do, newxvalue newzvalue, is that they return the correct distance to move on each axis based on an angle of rotation.

So at 0 degrees, you move 10units on X, and 0 on Z. If rotated at 37 degrees, you move 7.98 on X and 6.0 on Z. If you plug those numbers in for A and B using pythagorean thearom, you should get 10 for the hypotneuse. This would probably make more sense if I could show you a picture, but I got nowhere to upload one to.

So sine and cosine are important for projecting proper distance, but also are used in rotations, such as rotating an object around an arbitrary point. I'll do a quick example of that as well.



"eureka" - Archimedes
Francesco
21
Years of Service
User Offline
Joined: 11th Apr 2004
Location: Milan, Italy
Posted: 24th May 2004 18:32
Thanks to Phaelax and to Emperor Baal. Think I've got it now!
Ps:
Quote: "but I've got exams tomorrow "

sorry if I made you waste your time helping me! Hope yoour exams go well!
Cheers
Francesco

Non si inalberi mica con me, sa!
Lei è venuto qui, lei ha il tombino intasato!
Siamo uno spurgo serio, noi!
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th May 2004 03:17
I added a slightly better visual. It'll draw a triangle, and show the X and Y values of the point that is rotating. As you can see, as X increases, the Y decreases in order to keep the overall distance from the center at 50. And if X decreases, then Y increases.



"eureka" - Archimedes

Login to post a reply

Server time is: 2025-05-24 00:20:58
Your offset time is: 2025-05-24 00:20:58