Ziphius Posted October 8, 2012 Posted October 8, 2012 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?
comment Posted October 8, 2012 Posted October 8, 2012 Try = Case ( x ; Atan ( y / x ) + Case ( x < 0 ; Pi ; Atan ( y / x ) > Pi ; -2 * Pi ) ; Sign ( y ) * Pi / 2 ) 2
Ziphius Posted October 8, 2012 Author Posted October 8, 2012 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
comment Posted October 9, 2012 Posted October 9, 2012 Excel has the two parameters reversed: http://en.wikipedia.org/wiki/Atan2#Variations 1
Ziphius Posted October 9, 2012 Author Posted October 9, 2012 Ahh, thank you, all is working well now.
LenLen Posted January 13, 2015 Posted January 13, 2015 Hi Ziphius, I have the same problem, how you solve this? What formula are you using? Can you guide me?
Ziphius Posted February 24, 2015 Author Posted February 24, 2015 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.
comment Posted February 24, 2015 Posted February 24, 2015 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 ...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now