Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ATAN2 function from Excel not working in FM

Featured Replies

I have copied the following formula from excel into my calculation field:

DEGREES(ATAN2(COS(RADIANS(S2)),COS(RADIANS(U2))*SIN(RADIANS(S2)))

Since FM doesn't recognize the function "ATAN2", I added a custom function as follows:

Let ( [

a =

If ( x > 0 ; Atan( y / x ) ;

If ( x < 0 ; Pi - Atan( -y / x ) ;

Pi / 2 * Sign ( y ) ) );

result = Mod( a; 2 * Pi)

];

result

)

based on the following source: http://www.briandunning.com/cf/502 but unfortunately the function doesn't seem to be working properly, or at least the same way as it does in excel.

Can anyone provide the custom function script equivalent to the "ATAN2" function in excel?

Try =

Case (

x ; Atan ( y / x ) + Case ( x < 0 ; Pi ; Atan ( y / x ) > Pi ; -2 * Pi )  ;

Sign ( y ) * Pi / 2

)

  • Author

Seems to work for single positive digits but the actual y and x values I need to process are:

ATAN2(0.72,-0.63)

Excel gives me: -0.72

but FM gives me 2.29

Excel has the two parameters reversed:

http://en.wikipedia.org/wiki/Atan2#Variations

  • Author

Ahh, thank you, all is working well now.

  • 2 years later...
Hi Ziphius, I have the same problem, how you solve this? What formula are you using? Can you guide me?
  • 1 month later...
  • Author

1. You need Filemaker Pro Advanced to add custom functions.

2. File>Manage>Custom Functions

3. New

4. Add "ATAN2" in Function Name field

5. Function parameters type "y", click the plus sign, then type "x", click the plus sign

6. Copy and paste this code into the "New Function" box:

 

Let ( [

a = 
Case ( x > 0 ; Atan( y / x ) ;
x < 0 ; If ( y ≥ 0 ; Pi + Atan ( y / x) ; -Pi + Atan ( y / x)) ;
x = 0 ; If ( y > 0 ; Pi / 2 ; If ( y < 0 ; -Pi / 2 ; 0) )) ;
result =a
];
result
)

 

Source for this code is http://www.briandunning.com/cf/502but make sure you scroll to the discussion box where he modifies the original code shown above. Worked for me.

6. Copy and paste this code into the "New Function" box:

 

Let ( [

a = 

Case ( x > 0 ; Atan( y / x ) ;

x < 0 ; If ( y ≥ 0 ; Pi + Atan ( y / x) ; -Pi + Atan ( y / x)) ;

x = 0 ; If ( y > 0 ; Pi / 2 ; If ( y < 0 ; -Pi / 2 ; 0) )) ;

result =a

];

result

)

 

 

If you scroll back to post #2 of this thread ...

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.