October 8, 201213 yr 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?
October 8, 201213 yr Try = Case ( x ; Atan ( y / x ) + Case ( x < 0 ; Pi ; Atan ( y / x ) > Pi ; -2 * Pi ) ; Sign ( y ) * Pi / 2 )
October 8, 201213 yr 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
October 9, 201213 yr Excel has the two parameters reversed: http://en.wikipedia.org/wiki/Atan2#Variations
January 13, 201511 yr Hi Ziphius, I have the same problem, how you solve this? What formula are you using? Can you guide me?
February 24, 201511 yr 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.
February 24, 201511 yr 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