Board index FlightGear Development Nasal

How to do asin in Nasal ?  Topic is solved

Nasal is the scripting language of FlightGear.

How to do asin in Nasal ?

Postby mhab » Wed Jun 18, 2014 8:32 pm

Hello

It seems there is no asin() function available in Nasal.
Also there is no atan() function and only atan2().

Can somebody point me to how I do a asin() in Nasal ?

Thanks
Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: How to do asin in Nasal ?

Postby Necolatis » Wed Jun 18, 2014 10:01 pm

atan(x) = sin(x)/cos(x)
asin(x) = Atan(X / Sqrt(-X * X + 1))
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: How to do asin in Nasal ?

Postby mhab » Wed Jun 18, 2014 10:07 pm

Thanks

but there is no atan(), so how to do it with atan2() ?

Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: How to do asin in Nasal ?  

Postby Gijs » Wed Jun 18, 2014 10:07 pm

asin and acos are built-in functions; no need to define them yourself. If you're using 2.12 as your profile says, it might be a bit different, but for 3.0 I know it's supposed to work. Do note that you need to use the math. prefix, like: math.asin() and math.acos(). See https://gitorious.org/fg/simgear/commit ... 40e42bc534 for the corresponding commit.
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9544
Joined: Tue Jul 03, 2007 3:55 pm
Location: Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: How to do asin in Nasal ?

Postby Necolatis » Wed Jun 18, 2014 10:43 pm

mhab wrote in Wed Jun 18, 2014 10:07 pm:but there is no atan(), so how to do it with atan2() ?


Why not use the formula I described above, not sure how to do it with atan2, but with sin and cos is simple.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: How to do asin in Nasal ?

Postby mhab » Wed Jun 18, 2014 11:12 pm

Hello Gijs

Thanks for reminding me to update my profile.

I tried to update the wiki page http://wiki.flightgear.org/Nasal_library_functions and add some missing functions.which seem to be available.

So please someone with deeper knowledge check the math.xxxx functions described now in the Wiki.

Thanks
Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: How to do asin in Nasal ?

Postby radi » Thu Jun 19, 2014 6:32 am

Necolatis wrote in Wed Jun 18, 2014 10:01 pm:atan(x) = sin(x)/cos(x)

Why not use the formula I described above, not sure how to do it with atan2, but with sin and cos is simple.


Because it is wrong? What you gave is the definition of tan, not atan.

sin(x) / cos(x) = tan(x).

As for atan, depending on what you want to achive, atan2 might actually be more useful. Anyway, from the definition [1] of atan2

atan2(y, x) = atan(y / x) for x > 0

follows

atan(y) = atan2(y, 1)

[1] http://en.wikipedia.org/wiki/Atan2#Definition_and_computation
OSM buildings for LOWI, EDDC
Custom scenery for VHXX YMML
Edit .stg via the FG Object Placement Tool
radi
 
Posts: 659
Joined: Mon Aug 25, 2008 5:24 pm
Location: YMML, EDDC

Re: How to do asin in Nasal ?

Postby Necolatis » Thu Jun 19, 2014 6:38 am

oops. I better shut up now. Sorry.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: How to do asin in Nasal ?

Postby mhab » Thu Jun 19, 2014 12:09 pm

Hello

Just one more comment from the Nasal users' point of view:

To implement a Nasal extension without documenting it is almost like it's not there.
On the level of a Nasal user it cannot be expected to check C-source code in order to find out what is available in Nasal.

So please keep in mind, if something shall be useful for the community it needs to be documented.

Thanks
Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: How to do asin in Nasal ?

Postby Johan G » Thu Jun 19, 2014 10:45 pm

mhab wrote in Thu Jun 19, 2014 12:09 pm:To implement a Nasal extension without documenting it is almost like it's not there.

In addition lack of documentation might also lead to duplicate work, like it nearly did in this case. :roll: :wink:
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: How to do asin in Nasal ?

Postby mhab » Fri Jun 20, 2014 1:30 pm

Thanks Johan G

Rest assured it DID cause useless effort ...
I usually post a problem only after I failed for several hours.

Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: How to do asin in Nasal ?

Postby Hooray » Sun Jun 22, 2014 10:41 am

mhab wrote in Thu Jun 19, 2014 12:09 pm:To implement a Nasal extension without documenting it is almost like it's not there.
On the level of a Nasal user it cannot be expected to check C-source code in order to find out what is available in Nasal.

So please keep in mind, if something shall be useful for the community it needs to be documented.


Those are not FlightGear specific extension functions, they are part of the standard Nasal library.
See the section titled "Math Library" at: http://plausible.org/nasal/lib.html
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: How to do asin in Nasal ?

Postby mhab » Sun Jun 22, 2014 6:01 pm

Hello

The functions described at http://plausible.org/nasal/lib.html were documented in FG wiki when I started.
There is no mention there of things like asin, acos, etc. which were added not so long ago.
See simgear/nasal/mathlib.c (https://gitorious.org/fg/simgear/source/ad83e70cf5983c7b307847aa2cb92c40e42bc534:simgear/nasal/mathlib.c)
It was changed by James Turner 9 months ago.

Whichever part this is, I was not able to find that asin exists :(
Therefore - in an effort of community thinking - I documented it and allowed myself to emphasize the uselessness of undocumented extensions.

Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10


Return to Nasal

Who is online

Users browsing this forum: No registered users and 4 guests