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 / Sin, cos, tan

Author
Message
zeeenza
18
Years of Service
User Offline
Joined: 2nd Jul 2006
Location:
Posted: 8th Sep 2007 08:44
How do you use sin, cos, tan, etc. in DarkBasic? I don't know how to use trigonometry functions in programming. Mathematically I do, but I don't understand how to use it for games, since it deals with angles in a right triangle. Yes, I've searched but didn't find anything that made sense to me.

Thanks

Windows Vista Home Premium :: Intel Core 2 Duo - 2.2Ghz :: 2GB System RAM :: nVidia GeForce 8600M GS - 511MB VRAM
culmor30
17
Years of Service
User Offline
Joined: 16th Jun 2007
Location: In my head.
Posted: 8th Sep 2007 08:55
You use the sin(), cos(), and tan() commands.

Example:


That'll obviously give you the sine, cosine, and tangent of the number 50. Dunno what else you're asking, but I assume you want the commands.
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 8th Sep 2007 11:19
You can use it for movement
http://forum.thegamecreators.com/?m=forum_view&t=113128&b=1&p=0

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 8th Sep 2007 14:13 Edited at: 9th Sep 2007 16:02
One very useful way of using them (apart from just movement, which is useful) is to offset things.

Here's an example of how to always keep an object to the left of another:


"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
culmor30
17
Years of Service
User Offline
Joined: 16th Jun 2007
Location: In my head.
Posted: 9th Sep 2007 04:37
But... you could just add an offset limb?
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 9th Sep 2007 16:03
Yah you could, but it's just an example really. I prefer to do it that way anyway. Not sure why

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Dr Schnitzengruber
17
Years of Service
User Offline
Joined: 19th Jul 2007
Location: C:/Projects/failed/ schnitzengruber
Posted: 9th Sep 2007 16:29
Be prepared for a long explanation:

In a circle placed at {0,0} with a radius of one, the sine value describes the y position(output) of any point on the circumference at a angle(input). The cosine value describes the x position(output) at the angle(input). So you could draw a circle like:




The tangent is sine divide by cosine where both there inputs are the input. There is very little use for tangent beacuse it would cause divide by zero errors at a input of 90 and it creates a very strange waveform.

The best use for sin/cos/tan is to draw curves and circle and create smooth waveforms( such as a musical tone).

an imaginary number is a number multiplied by i, where i is the square root of negative one.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 9th Sep 2007 17:07
Actually if you put tan(90) into DB you get -22877332, heh.

But yeah, really the best use I think is for things involving circles and triangles.

Here's something that you can use for movement (just like the move object command), but of course, this way can be molded to do slightly different things, like not moving in the way it faces:


"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Dr Schnitzengruber
17
Years of Service
User Offline
Joined: 19th Jul 2007
Location: C:/Projects/failed/ schnitzengruber
Posted: 10th Sep 2007 02:19
Quote: "Actually if you put tan(90) into DB you get -22877332, heh."


It is a error in DBPro where the compiler tries to get 0 or the lowest number it can.

click to get to the discussion

an imaginary number is a number multiplied by i, where i is the square root of negative one.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Sep 2007 02:51
I wouldn't think it's an error. From what I heard the values for sin(), cos() and tan() are all inserted in, and then float values are worked out from them. I think they must have just put in the smallest integer they could (though I would have thought they would have put the biggest). I might be wrong though.

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Sep 2007 18:01
Odd

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
culmor30
17
Years of Service
User Offline
Joined: 16th Jun 2007
Location: In my head.
Posted: 11th Sep 2007 02:21 Edited at: 11th Sep 2007 02:22
I get 82183016.



(Funny thing is I have no idea what any of this means, being in 10th grade Geometry )
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 11th Sep 2007 15:01
Take a sneak peek at the trig book you will be using next year, and look at the graphical representation of the tangent function. It looks plus or minus infinity at 90°. So one would expect an error, such as a division by zero error when using the tangent function with an argument that evaluates to 90°, especially because tan is equivalent to sin/cos, and the cos at 90° is zero. So DBP is returning a very large value instead of an error for some reason, probably because the 90 is not being regarded at exactly 90 but something like 89.99999.
culmor30
17
Years of Service
User Offline
Joined: 16th Jun 2007
Location: In my head.
Posted: 12th Sep 2007 04:50
Divide by zero at your own risk.

Aaannd... I can't look at next year's trig book, because next year is Algebra II, then precalculus... then I don't know.
H4ck1d
18
Years of Service
User Offline
Joined: 27th Dec 2005
Location: Yes
Posted: 12th Sep 2007 05:28
Quote: "8.2183e+007"

Quote: "I get 82183016"


They're basically the same thing . One's only slightly more accurate.

Anyways, I've been kind of confused reading these posts... has your question been answered, or are you still looking for an answer? If so, could you clarify your question a little more?

Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 12th Sep 2007 08:55 Edited at: 12th Sep 2007 08:57
yeah its a parsing error or something.
floats cant be stored exactly as a number, so its treated like that.

edit: my previous example didnt work
look up 'float' on the forums.

zeeenza
18
Years of Service
User Offline
Joined: 2nd Jul 2006
Location:
Posted: 14th Sep 2007 05:20
I kinda get it...But I don't understand how people use them to move objects. As for offsetting things, isn't that pretty much the same thing as newxvalue, newyvalue, and newzvalue?

Windows Vista Home Premium :: Intel Core 2 Duo - 2.2Ghz :: 2GB System RAM :: nVidia GeForce 8600M GS - 511MB VRAM
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Sep 2007 18:44
Yes, it's exactly the same. That's because under the hood, those 3 functions are using combinations of sin/cos to produce the same results.

Here's code comparing the newxvalue function to the sin-based version of it:


Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code

Login to post a reply

Server time is: 2024-09-27 05:11:58
Your offset time is: 2024-09-27 05:11:58