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 Professional Discussion / Tangent, arc-tangent, arc-sine, arc-cosine and other math...

Author
Message
Starshyne Emir
2
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 20th Oct 2018 21:30
Probably I should have paid more attention to my math classes, but, well, I didn't.
I learned in this forum how to use SIN() and COS() to make orbits and angular stuff, but...

Can some kind spirit around here teach me what these functions can be used for?

TAN(), ATAN(), HTAN(), ACOS(), HCOS(), et cetera.

If possible, give me simple examples of where can I use them and why would I need these functions. There are lots of stuff I want to do involving math, but without the correct understanding of the potential of such functions, I am still stuck .

Thanks for the patience.
[size=+2]Forever and one[/size]
Mage
12
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 21st Oct 2018 03:41
I’m doing this on my phone and don’t have access to docs.

TAN is just like SIN or COS. The wave form isn’t a squiggly line but instead a repeating curve that shoots to infinity both up and down. The relationship is (remembering way back) an angle fans out to a right angled triangle. Divide the side lengths in different patterns to get SIN/COS/TAN values for an angle. Opposite / Hypotenuse = SIN. Adjacent / Hypotenuse = COS. If I recall correctly Opposite / Adjacent = TAN.

ASIN/ACOS/ATAN are just the reverse operations of SIN/COS/TAN. The most useful is ATAN. So if you have the some of the side lengths then you can calculate to get the angle.

ATAN is particularly useful because it helps you calculate what angle you need to point one object at another. You need the triangle sides Opposite and Adjacent and those are merely the difference in x and z values. You divide the z difference by the x difference. You might need some simple math to correct for which quadrant the angle is in.

TANH I and the rest I can’t say since I never used them and I don’t have the docs. I suspect it has something to do with getting the hypotenuse maybe by supplying an angle and one of the sides depending on which command. If that’s correct then it’s a clever way to calculate distance which makes sense in DBP. Best guess.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Starshyne Emir
2
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 21st Oct 2018 06:11 Edited at: 21st Oct 2018 08:38
Thanks.
Well, you told me many things I already knew, but one thing in special was quite like a BOOM in my head: arctangent can help pointing one object to another.

I went straight to DBPro and started traying and experimenting until I FOUND SOMETHING EVEN BETTER: ATANFULL(!

This is great because doesn't need any calculation. It returns the correct angle and you just need to rotate the sprite or object with the angle it returned.

I made this in a hurry.

This code requires Matrix1Utils to be compiled.

What it does: it create 2 spaceships. With arrow keys you control spaceship 1, and spaceship 2 (using ATANFULL and a timer) tries to follow it. I added a timer to ensure the following pattern isn't impossible to avoid (without it, the ship 2, after some time, simply catches spaceship 1 and overlaps it.

IMPORTANT:there are a lot of functions unused in this demo, please ignore them - or make them a try,if you please - but the goal of this snippet is just to demonstrate that what you said was very useful.

[size=+2]Forever and one[/size]

Login to post a reply

Server time is: 2019-03-19 02:21:56
Your offset time is: 2019-03-19 02:21:56