Mr. Klaus Straka 0 Report post Posted June 9, 2016 Hi, i am working on a feature that actually draw some helical curves and circles. Therefor i frequently have to calulate an angle in the x-y-plane. Ok, thats easy. To get the right actual angle in the range of 0-360 degrees it wrote a function function quadrantCorrection(FPoint startp, FDouble phi):FDouble if (AND(startp.getY()>=0,startp.getX()<0)) // 2th. Q. phi = 180-phi elseif (AND(startp.getY()>=0,startp.getX()>=0)) // 1st Q. phi = phi elseif (AND(startp.getY()<0,startp.getX()>=0)) // 4nd. Q. echo("Q4, phi " + phi) phi = 360-phi echo("Q4, phiCorr " + phi) elseif (AND(startp.getY()<0,startp.getX()<0)) // 3rd. Q. phi = 180+phi endif return(phi) endfunction I use this function for a great number of times and it seems to work fine. However in the attached project in the feature definition "MixerBasemesh" at line 340 it fails for whatever reason.Below some debug output is given, the x and y coordinate show that the point is located in 4th quadrant. The function above detects this correctly (indicated by the debug output "Q4, phi 7.44226") but it does not compensate (phi=360-phi) the angle as shown by "Q4, phiCorr 7.44226". phiE: 7.44226 x: 19.9307 y: -2.60349 Q4, phi 7.44226 Q4, phiCorr 7.44226 phiECorr: 7.44226 phi: -37.5577 phi: -37.5577 ----- This is a somwhat strange behaviour, i have no idea what i am doing wrong. Any comments on this.I use V4.1.0 on Ubuntu. Thank you for your help an best regards, Klaus Share this post Link to post Share on other sites
Mr. Arne Bergmann 27 Report post Posted June 9, 2016 Hi Klaus, Please try to change the code of the function to the following: function quadrantCorrection(FPoint startp, FDouble phi):FDouble if (AND(startp.getY()>=0,startp.getX()<0)) // 2th. Q. phi = 180-#phi elseif (AND(startp.getY()>=0,startp.getX()>=0)) // 1st Q. phi = phi elseif (AND(startp.getY()<0,startp.getX()>=0)) // 4nd. Q. echo("Q4, phi " + phi) phi = 360-#phi echo("Q4, phiCorr " + phi) elseif (AND(startp.getY()<0,startp.getX()<0)) // 3rd. Q. phi = 180+#phi endif return(phi) endfunction It works for me like that. Apparently, there is a problem when trying to assign an expression to an argument inside a function that includes the argument itself. To be honest, I am not quite sure at the moment, why that is the case, but the '#' (detach) helps here. As an addition: Note that your function does not really need to return anything, since it just returns the argument. As opposed to other places, even basic types are passed to functions as references. So, when calling the function above like this: double d() point p() // .... initialize.... quadrantCorrection(p, d) the variable d might have a different value after the call (except if the 1st Q case occurred). If you want to make sure that this does not happen, introduce a temporary variable (which, by the way, also takes away the need to use the detach): function quadrantCorrection(FPoint startp, FDouble phi):FDouble double result(phi) if (AND(startp.getY()>=0,startp.getX()<0)) // 2th. Q. result= 180-result elseif (AND(startp.getY()>=0,startp.getX()>=0)) // 1st Q. result = result elseif (AND(startp.getY()<0,startp.getX()>=0)) // 4nd. Q. echo("Q4, phi " + result) result= 360-result echo("Q4, phiCorr " + result) elseif (AND(startp.getY()<0,startp.getX()<0)) // 3rd. Q. phi = 180+result endif return(result) endfunction I hope this helps. Cheers,Arne Share this post Link to post Share on other sites
Mr. Arne Bergmann 27 Report post Posted June 9, 2016 Oh, please let me add the following link: https://www.caeses.com/forum/index.php?/blog/3/entry-5-a-christmas-present-effective-fpl/The document that is attached there includes some more information on references and functions. Ok, I'm done with the shameless advertisement of my own blog ;) Share this post Link to post Share on other sites
Mr. Klaus Straka 0 Report post Posted June 9, 2016 Hi Arne, thanks for your quick reply. I will try your approach. Cheers,Klaus Share this post Link to post Share on other sites