R rboeck Well-Known Member Licensed User Longtime User Dec 30, 2015 #1 Hi, currently i try to convert this java code: Code: static double tile2lat(int y, int z) { double n = Math.PI - (2.0 * Math.PI * y) / Math.pow(2.0, z); return Math.toDegrees(Math.atan(Math.sinh(n))); } to Code: Sub tile2lat(y As Int,z As Int) Dim n As Double =cPI-(2.0*cPI*y) / Power(2.0,z) Return ToDegrees(ATan(ASin(n))) End Sub What is the b4x function for java Math.toDegrees and is the rest of my conversion ok?
Hi, currently i try to convert this java code: Code: static double tile2lat(int y, int z) { double n = Math.PI - (2.0 * Math.PI * y) / Math.pow(2.0, z); return Math.toDegrees(Math.atan(Math.sinh(n))); } to Code: Sub tile2lat(y As Int,z As Int) Dim n As Double =cPI-(2.0*cPI*y) / Power(2.0,z) Return ToDegrees(ATan(ASin(n))) End Sub What is the b4x function for java Math.toDegrees and is the rest of my conversion ok?
wonder Expert Licensed User Longtime User Dec 30, 2015 #2 Try this: Code: Sub Process_Globals ... 'Declare these constants as global variables Dim DEG_TO_RADIANS = 0.017453292519943295769236907684886127134428718885417 As Double Dim RAD_TO_DEGREES = 57.29577951308232087679815481410517033240547246656432 As Double ... End Sub Sub toDegrees(radians As Double) As Double Return radians * RAD_TO_DEGREES End Sub Sub toRadians(degrees As Double) As Double Return degrees * DEG_TO_RADIANS End Sub Upvote 0
Try this: Code: Sub Process_Globals ... 'Declare these constants as global variables Dim DEG_TO_RADIANS = 0.017453292519943295769236907684886127134428718885417 As Double Dim RAD_TO_DEGREES = 57.29577951308232087679815481410517033240547246656432 As Double ... End Sub Sub toDegrees(radians As Double) As Double Return radians * RAD_TO_DEGREES End Sub Sub toRadians(degrees As Double) As Double Return degrees * DEG_TO_RADIANS End Sub
klaus Expert Licensed User Longtime User Dec 30, 2015 #3 Try this: Code: Sub tile2lat(y As Int,z As Int) Dim n As Double = cPI-(2.0 * cPI * y) / Power(2.0, z) Return ATanD(ASin(n)) End Sub Upvote 0
Try this: Code: Sub tile2lat(y As Int,z As Int) Dim n As Double = cPI-(2.0 * cPI * y) / Power(2.0, z) Return ATanD(ASin(n)) End Sub
R Roycefer Well-Known Member Licensed User Longtime User Dec 30, 2015 #4 There is a mistake in your code. The Java code doesn't call Math.asin(n) (the arc-sine or inverse sine). It calls Math.sinh(n) (the hyperbolic sine). There's no built-in B4X function that performs the hyperbolic sine but you can easily build your own by appealing to the definition of the hyperbolic sine: https://en.wikipedia.org/wiki/Hyperbolic_function or using JavaObject to access Java's built-in hyperbolic sine function (you'll want to create-static a java.lang.Math object). Upvote 0
There is a mistake in your code. The Java code doesn't call Math.asin(n) (the arc-sine or inverse sine). It calls Math.sinh(n) (the hyperbolic sine). There's no built-in B4X function that performs the hyperbolic sine but you can easily build your own by appealing to the definition of the hyperbolic sine: https://en.wikipedia.org/wiki/Hyperbolic_function or using JavaObject to access Java's built-in hyperbolic sine function (you'll want to create-static a java.lang.Math object).
R rboeck Well-Known Member Licensed User Longtime User Dec 31, 2015 #5 Thanks for all helpers... my mathematical and english knowledge in combination is not good enough to unterstand the meaning of hyberbolic, asin etc. Maybe i can better explain what i want to do: i want to use this page: mapire.eu on android. In the past this page used simple long and lat values inside the url, so that i could use my own position to search the position on the page. Now the changed to another coodinate system, now they are using openstreetmap instead of google maps and the coordinates are gone and the url is in this way: http://mapire.eu/de/map/secondsurve...33983821,1811421.0637459855,6214901.335736876 Maybe its easy for someone to calculate this values from the former values: lat: 47.89 long:14.76 zoom=9 Thanks for your interest and helping! Upvote 0
Thanks for all helpers... my mathematical and english knowledge in combination is not good enough to unterstand the meaning of hyberbolic, asin etc. Maybe i can better explain what i want to do: i want to use this page: mapire.eu on android. In the past this page used simple long and lat values inside the url, so that i could use my own position to search the position on the page. Now the changed to another coodinate system, now they are using openstreetmap instead of google maps and the coordinates are gone and the url is in this way: http://mapire.eu/de/map/secondsurve...33983821,1811421.0637459855,6214901.335736876 Maybe its easy for someone to calculate this values from the former values: lat: 47.89 long:14.76 zoom=9 Thanks for your interest and helping!
klaus Expert Licensed User Longtime User Dec 31, 2015 #6 From this: Try this: Code: Sub tile2lat(y As Int, z As Int) Dim n As Double = cPI-(2.0 * cPI * y) / Power(2.0, z) Return ATanD((Power(cE, n) - Power(cE, -n)) / 2) End Sub Last edited: Jan 1, 2016 Upvote 0
From this: Try this: Code: Sub tile2lat(y As Int, z As Int) Dim n As Double = cPI-(2.0 * cPI * y) / Power(2.0, z) Return ATanD((Power(cE, n) - Power(cE, -n)) / 2) End Sub
R Roycefer Well-Known Member Licensed User Longtime User Dec 31, 2015 #7 You should enclose those two Power() calls in parentheses as, due to the order of operations, you are only dividing the latter Power() call by 2. Code: Return ATanD((Power(cE, n) - Power(cE, -n)) / 2) Upvote 0
You should enclose those two Power() calls in parentheses as, due to the order of operations, you are only dividing the latter Power() call by 2. Code: Return ATanD((Power(cE, n) - Power(cE, -n)) / 2)
klaus Expert Licensed User Longtime User Jan 1, 2016 #8 You are right ! Thank you, I amended post #6. Upvote 0