C Christian75 Member Nov 13, 2021 #1 Hi, When I use this code in BANano: B4X: Copy Angle = ATan2D((y2 - y1), (x2 - x1)) That will be converted to: JavaScript: Copy __1fb=(Math.atan2((_y2-_y1)*(180/Math.PI)),(_x2-_x1)) It should be: JavaScript: Copy __1fb=(Math.atan2((_y2-_y1),(_x2-_x1))*(180/Math.PI)) Please look at where the parentheses is located in the generated code. Math.atan2 only includes the (y2-y1) and not the (x2-x1)! So in this case if (y2-y1) is zero then the Angel will be equal to (x2-x1) which is not correct. The angel in this case should be 0. Edit: ATan2 is also converted wrong! JavaScript: Copy __1fb=(Math.atan2((_y2-_y1)),(_x2-_x1)) Best regards Christian Last edited: Nov 13, 2021
Hi, When I use this code in BANano: B4X: Copy Angle = ATan2D((y2 - y1), (x2 - x1)) That will be converted to: JavaScript: Copy __1fb=(Math.atan2((_y2-_y1)*(180/Math.PI)),(_x2-_x1)) It should be: JavaScript: Copy __1fb=(Math.atan2((_y2-_y1),(_x2-_x1))*(180/Math.PI)) Please look at where the parentheses is located in the generated code. Math.atan2 only includes the (y2-y1) and not the (x2-x1)! So in this case if (y2-y1) is zero then the Angel will be equal to (x2-x1) which is not correct. The angel in this case should be 0. Edit: ATan2 is also converted wrong! JavaScript: Copy __1fb=(Math.atan2((_y2-_y1)),(_x2-_x1)) Best regards Christian
Solution C C Christian75 Nov 14, 2021 Found a way around this problem: B4X: Copy Dim y_diff As Double = (y2 - y1) Dim x_diff As Double = (x2 - x1) Angle = ATan2D(y_diff, x_diff) Then it works ok
Found a way around this problem: B4X: Copy Dim y_diff As Double = (y2 - y1) Dim x_diff As Double = (x2 - x1) Angle = ATan2D(y_diff, x_diff) Then it works ok
C Christian75 Member Nov 14, 2021 #2 Found a way around this problem: B4X: Copy Dim y_diff As Double = (y2 - y1) Dim x_diff As Double = (x2 - x1) Angle = ATan2D(y_diff, x_diff) Then it works ok Upvote 0 Solution
Found a way around this problem: B4X: Copy Dim y_diff As Double = (y2 - y1) Dim x_diff As Double = (x2 - x1) Angle = ATan2D(y_diff, x_diff) Then it works ok
E emexes Expert Licensed User Longtime User Nov 14, 2021 #3 Christian75 said: Found a way around this problem: Click to expand... What happens in the generated code if you put both call styles together, eg: Code: Copy TestAngle1 = ATan2D((y2 - y1), (x2 - x1)) Dim y_diff As Double = (y2 - y1) Dim x_diff As Double = (x2 - x1) TestAngle2 = ATan2D(y_diff, x_diff) I don't understand why one way would work but not the other. Or why the problem hasn't been picked up previously. Although now that you can rotate panels via Android just by specifying the angle, perhaps the function doesn't get the workout that it used to. Upvote 0
Christian75 said: Found a way around this problem: Click to expand... What happens in the generated code if you put both call styles together, eg: Code: Copy TestAngle1 = ATan2D((y2 - y1), (x2 - x1)) Dim y_diff As Double = (y2 - y1) Dim x_diff As Double = (x2 - x1) TestAngle2 = ATan2D(y_diff, x_diff) I don't understand why one way would work but not the other. Or why the problem hasn't been picked up previously. Although now that you can rotate panels via Android just by specifying the angle, perhaps the function doesn't get the workout that it used to.
alwaysbusy Expert Licensed User Longtime User Nov 14, 2021 #4 I did use the JavaScript formulas from somewhere, but I never really has a use for it so they may be wrong. If they are actually wrong, they will be corrected in the next version. At first sight, it looks that it may have something to do with the terms being in Degrees/Radials. Can you elaborate just a bit more beofre I make the change, as I thought I got the same values in B4J as in BANano? Alwaysbusy Upvote 0
I did use the JavaScript formulas from somewhere, but I never really has a use for it so they may be wrong. If they are actually wrong, they will be corrected in the next version. At first sight, it looks that it may have something to do with the terms being in Degrees/Radials. Can you elaborate just a bit more beofre I make the change, as I thought I got the same values in B4J as in BANano? Alwaysbusy
E emexes Expert Licensed User Longtime User Nov 14, 2021 #5 alwaysbusy said: I did use the JavaScript formulas from somewhere ... Can you elaborate just a bit more before I make the change Click to expand... I think I am misunderstanding the problem. I thought you were looking at the Java (not JavaScript) output from B4J, and that it was compiling differently (as in: correctly/incorrectly) when you used interim variables x_diff and y_diff. Upvote 0
alwaysbusy said: I did use the JavaScript formulas from somewhere ... Can you elaborate just a bit more before I make the change Click to expand... I think I am misunderstanding the problem. I thought you were looking at the Java (not JavaScript) output from B4J, and that it was compiling differently (as in: correctly/incorrectly) when you used interim variables x_diff and y_diff.
C Christian75 Member Nov 15, 2021 #6 Hi, I looked at the Javascript output in the console for a browser. I did use the ATan2D((y2 - y1), (x2 - x1)) in my B4J project where it works fine but now when I'm trying to convert to BANano then the parentheses gets messed up and leaving only the y2-y1 within the atan2 converted Javascript. But I had some similar issues on other places in function calls with not only pure variables but then it has been missing parenthesis or extra parenthesis which results in a non working page. This time it is the correct amount of parenthesis but on wrong places and gives a function that is not working as it should. And @alwaysbusy it is not due to Radians/Degrees as you can see in my first post. If I use ATan2 I get the same result as ATan2D. It has something to do with the parentheses within the function call it self. Now I did a test also without the parenthesis and then it also works! B4j: B4X: Copy Angle = ATan2D(y2 - y1, x2 - x1) Generated Javascript: JavaScript: Copy __1fb=(Math.atan2(_y2-_y1,_x2-_x1)*(180/Math.PI)) I guess that when doing a function call it is best to only use interim values or at least without parenthesis in BANano to avoid problems. Keep on the good work! Best regards Christian Upvote 0
Hi, I looked at the Javascript output in the console for a browser. I did use the ATan2D((y2 - y1), (x2 - x1)) in my B4J project where it works fine but now when I'm trying to convert to BANano then the parentheses gets messed up and leaving only the y2-y1 within the atan2 converted Javascript. But I had some similar issues on other places in function calls with not only pure variables but then it has been missing parenthesis or extra parenthesis which results in a non working page. This time it is the correct amount of parenthesis but on wrong places and gives a function that is not working as it should. And @alwaysbusy it is not due to Radians/Degrees as you can see in my first post. If I use ATan2 I get the same result as ATan2D. It has something to do with the parentheses within the function call it self. Now I did a test also without the parenthesis and then it also works! B4j: B4X: Copy Angle = ATan2D(y2 - y1, x2 - x1) Generated Javascript: JavaScript: Copy __1fb=(Math.atan2(_y2-_y1,_x2-_x1)*(180/Math.PI)) I guess that when doing a function call it is best to only use interim values or at least without parenthesis in BANano to avoid problems. Keep on the good work! Best regards Christian