Latitude and Longitude conversion - ruby-on-rails

I need to convert a latitude in ddmm.mmmmm (minutes in 4 decimal places) to ddmm.mmmmmm (minutes in 5 decimal places) format. Is there any good formula to convert this ?

I got the answer
We need to follow these steps for this conversion
1. Convert value in ddmm.mmmm format to dd.ddddddd by using the following formula
dd.ddddddd = dd + ( mm.mmmm / 60 )
convert back
ddmm.mmmmm = concat(dd, (.dddddd * 60))
Example:
To convert 3323.8733 from ddmm.mmmm format
convert to degrees (dd.dddd) format
33 + (23.8733 / 60 ) = 33.397888333333334
convert back to ddmm.mmmmm format
multiply decimal part by 60 i.e 0.397888333333334 * 60 => 23.87330000000004
append with degree
3323.87330000000004
As we need ddmm.mmmmm we can round of 5 decimal places i.e 3323.87330

Sans other information I would recommend following mkk's advice.
If you want to convert "ddmm.mmmmm" (4 decimal places) to "ddmm.mmmmm" (5 decimal places), you should probably just add a zero to the end.
Other methods may appear to give a more satisfactory result by placing a non-zero value in the fifth decimal place. But they cannot add more information than was present in the original number. There is, however, the potential to lose information through loss of significance in mathematical calculations.

Related

Why multiply two double in dart result in very strange number

Can anyone explain why the result is 252.99999999999997 and not 253? What should be used instead to get 253?
double x = 2.11;
double y = 0.42;
print(((x + y) * 100)); // print 252.99999999999997
I am basically trying to convert a currency value with 2 decimal (ie £2.11) into pence/cent (ie 211p)
Thanks
In short: Because many fractional double values are not precise, and adding imprecise values can give even more imprecise results. That's an inherent property of IEEE-754 floating point numbers, which is what Dart (and most other languages and the CPUs running them) are working with.
Neither of the rational numbers 2.11 and 0.42 are precisely representable as a double value. When you write 2.11 as source code, the meaning of that is the actual double values that is closest to the mathematical number 2.11.
The value of 2.11 is precisely 2.109999999999999875655021241982467472553253173828125.
The value of 0.42 is precisely 0.419999999999999984456877655247808434069156646728515625.
As you can see, both are slightly smaller than the value you intended.
Then you add those two values, which gives the precise double result 2.529999999999999804600747665972448885440826416015625. This loses a few of the last digits of the 0.42 to rounding, and since both were already smaller than 2.11 and 0.42, the result is now even more smaller than 2.53.
Finally you multiply that by 100, which gives the precise result 252.999999999999971578290569595992565155029296875.
This is different from the double value 253.0.
The double.toString method doesn't return a string of the exact value, but it does return different strings for different values, and since the value is different from 253.0, it must return a different string. It then returns a string of the shortest number which is still closer to the result than to the next adjacent double value, and that is the string you see.

Lua random number to the 8th decimal place

How do I get a random number in Lua to the eighth decimal?
Example : 0.00000001
I have tried the following and several variations of this but can not get the format i need.
math.randomseed( os.time() )
x = math.random(10000000,20000000) * 0.00000001
print(x)
i would like to put in say 200 and get this 0.00000200
Just grab a random number from 0-9, and slide it down 6 places. You can use format specifiers to create the string representation of the number that you desire. For floats we use %f, and indicate how many decimal places we want to have with an intermediate .n, where n is a number.
math.randomseed(os.time())
-- random(9) to exclude 0
print(('%.8f'):format(math.random(0, 9) * 1e-6))
--> '0.00000400'
string.format("%.8f",math.random())
to help anyone else. my question should have been worded a bit better. i wanted to be able to get random numbers and get it to the 8th decimal place.
but i wanted to be able to have those numbers from 1-10,000 so he is updated how i wanted it and the help of Oka got me to this
math.randomseed(os.time())
lowest = 1
highest = 7000
rand=('%.8f'):format(math.random(lowest, highest) / 100000000)
print(rand)
Hope this helps someone else or if it can be cleaned up please let me know

How to Convert Decimal coordinates to structured Coordinates in Delphi?

Hey there guys im working on a project for school and in the project it requires the user the enter decimal coordinates and convert it into structured format, ie:
17.428333° --> 17° 25' 42"
Does anyone possibly know how to do this? Also the program should be able to do it the opposite way; enter structured coordinates 17° 25' 42" and covert to decimal coordinates 17.4283333.
I have got the basic maths used for the converting. To convert from structured coordinates to decimal coordinates you can use the following :
17+25/60+42/3600
and to covert from decimal to structured takes first value 17 as the degrees then to work out the minutes
17.4285-17=0.4285*60=25.71
gets rid of the decimal or rounds the decimal to get the minutes, then to work out the seconds
25.71-25=0.71*60=42.6
either rounds the decimal or gets rid of the decimal for seconds.
Let's assume you start with a coord in a floating point variable x. Calculate degrees, minutes and seconds like this:
Degrees := Trunc(x);
x := (x - Degrees)*60;
Minutes := Trunc(x);
x := (x - Minutes)*60
Seconds := Round(x);
The opposite direction is simpler. The expression you need is:
Degrees + Minutes/60 + Seconds/3600

Small numbers in Objective C 2.0

I created a calculator class that does basic +,-, %, * and sin, cos, tan, sqrt and other math functions.
I have all the variables of type double, everything is working fine for big numbers, so I can calculate numbers like 1.35E122, but the problem is with extremely small numbers. For example if I do calculation 1/98556321 I get 0 where I would like to get something 1.01464E-8.
Should I rewrite my code so that I only manipulate NSDecimalNumber's and if so, what do I do with sin and cos math functions that accept only double and long double values.
1/98556321
This division gives you 0 because integer division is performed here - the result is an integer part of division. The following line should give you floating point result:
1/(double)98556321
integer/integer is always an integer
So either you convert the upper or the lower number to decimal
(double)1/98556321
or
1/(double)98556321
Which explicitely convert the number to double.
Happy coding....

How do I convert coordinates to google friendly coordinates

I need to do this..
<coordinates_east>6'01.4</coordinates_east>
<coordinates_north>45'05.5</coordinates_north>
I need to convert to this google friendly format in Ruby!...please note that these are not the real converted numbers just an example of the format I think I need!
<coordinates_east>45.46998</coordinates_east>
<coordinates_north>6.90764</coordinates_north>
How?
your input coordinates seem to be in wrong notation. it should probably be
<coordinates_north>45°05.5'</coordinates_north>
<coordinates_east>6°01.4'</coordinates_east>
(degrees° arcminutes'), or
<coordinates_north>45°05'5"</coordinates_north>
<coordinates_east>6°01'4"</coordinates_east>
(degrees° arcminutes' arcseconds")
once you figured out the correct input notation, you can use Parsing latitude and longitude with Ruby for converting them to decimal degrees. if your input notation is degrees° arcminutes', you have to modify it slightly. also pay attention to negative coordinates.
if you only want to use it with google maps, you don't actually need to convert it, because google maps understands arcminutes/-seconds notation.
my coordinates were space separated ("deg min sec") and I wrote this little lambda to handle them:
#to_decimal = lambda do |str|
deg, min, sec = str.split(" ").map(&:to_f)
if deg >= 0
output = deg + (min / 60.0) + (sec / 3600.0)
elsif deg < #HARD EARNED KNOWLEDGE HERE
output = deg - (min / 60.0) - (sec / 3600.0)
end
raise "something is wrong" if output.abs > 180
output
end

Resources