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 / Trying to write an ArcTan function...

Author
Message
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 15th Apr 2006 03:27
Ok... First up, I never really understood what ArcTan does... However, its a function I need for something of interest.



This is a recursive function (a continued fraction) that represents inverse tan (ArcTan).



Thats some code I've tried to represent the ArcTan function. I know this will be slow - its more of a means to an end rather than a highly tuned piece of code.

Can anyone see why that wont work? I've run it through my brain a few times and it SHOULD represent the fraction.

One area where I think I MIGHT be going wrong is the last itteration (ie, the one which doesn't call the function again). What happens on the last line of the equation if every line calls itself?

Anyone got any idea's here?

Cheers!

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Apr 2006 03:42
Two mistakes:
1. You were trying to get an arctan of an angle. You can't. You should get an arctan of an tangent of an angle.
2. The formula you are using returns its result in radians. You needed to convert to degrees.

Try this:


I've hidden the recursion away a little too

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 15th Apr 2006 03:47
Cheers Ian! Are you sure thats correct? When I go to Calc (in windows) and I set it to do an inverse tan of 15, I get a result of about 86.186, not the 15 that function(s) returning.

Any idea's?

re faze
20
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 15th Apr 2006 04:26
Quote: "ATAN

This command will return the tangent in degrees between 0 and 360. The value can be a real or integer
number. The return value should be a real number.

Syntax

Return Float=ATAN(Value)
"


Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 15th Apr 2006 04:53
Wait a sec... Is ATAN and ARCTAN the same damn thing?!

Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 15th Apr 2006 07:48 Edited at: 15th Apr 2006 07:49
Yes...

You take the tangent of an angle...and you take the arctangent, or atan, of the ratio between the opposite and adjacent sides of a triangle.

Xander Moser - Bolt Software - Firewall
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 15th Apr 2006 12:51
atan is short for arc tan as far as I knew. If you want the hyperbolic trig functions then writing a plugin will be your best bet for speed.


Join the BlackOut Forum Today
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 15th Apr 2006 15:00

Login to post a reply

Server time is: 2025-05-15 18:55:12
Your offset time is: 2025-05-15 18:55:12