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
Related
Can somebody explain why multiplying by 100 here gives a less accurate result but multiplying by 10 twice gives a more accurate result?
± % sc
Loading development environment (Rails 3.0.1)
>> 129.95 * 100
12994.999999999998
>> 129.95*10
1299.5
>> 129.95*10*10
12995.0
If you do the calculations by hand in double-precision binary, which is limited to 53 significant bits, you'll see what's going on:
129.95 = 1.0000001111100110011001100110011001100110011001100110 x 2^7
129.95*100 = 1.1001011000010111111111111111111111111111111111111111011 x 2^13
This is 56 significant bits long, so rounded to 53 bits it's
1.1001011000010111111111111111111111111111111111111111 x 2^13, which equals
12994.999999999998181010596454143524169921875
Now 129.95*10 = 1.01000100110111111111111111111111111111111111111111111 x 2^10
This is 54 significant bits long, so rounded to 53 bits it's 1.01000100111 x 2^10 = 1299.5
Now 1299.5 * 10 = 1.1001011000011 x 2^13 = 12995.
First off: you are looking at the string representation of the result, not the actual result itself. If you really want to compare the two results, you should format both results explicitly, using String#% and you should format both results the same way.
Secondly, that's just how binary floating point numbers work. They are inexact, they are finite and they are binary. All three mean that you get rounding errors, which generally look totally random, unless you happen to have memorized the entirety of IEEE754 and can recite it backwards in your sleep.
There is no floating point number exactly equal to 129.95. So your language uses a value which is close to it instead. When that value is multiplied by 100, the result is close to 12995, but it just so happens to not equal 12995. (It is also not exactly equal to 100 times the original value it used in place of 129.95.) So your interpreter prints a decimal number which is close to (but not equal to) the value of 129.95 * 100 and which shows you that it is not exactly 12995. It also just so happens that the result 129.95 * 10 is exactly equal to 1299.5. This is mostly luck.
Bottom line is, never expect equality out of any floating point arithmetic, only "closeness".
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.
I'm implementing line charts of primefaces(3.0) , I'm trying to change the value of X-scale
The values which I'm using are minX="0" maxX="38" , since primefaces linecharts is using jqplot , I added this script
<script>
$(function(){
widget_category.plot.axes.xaxis._tickInterval = 1;
widget_category.plot.axes.xaxis.numberTicks = 38;
});
</script>
But still the coordinates is coming in decimals.
I would like to mention that for Y scale, the values I used are minY="40" maxY="110" with style="height:1005px;" , As i figured out for a scale value , which can be 10 if height is defined as 1005px i.e. 5 * 14 = 70 which means Y scale is of 5 intervals , with 14 values and the line height is 1005 as 5*14*14 = 980 + 25 (which is top-margin added) 1005.
Though the same is not working out for X-Scale.
Any help would be helpful.
The arithmetic in your Y values are all multiplication operations on whole numbers, which will always result in a whole number. These whole numbers correlate perfectly to pixels.
Your X range however involves a multiplication of 1.0 and 38, one being an integer value and the other being determined as a float or double number. When performing a multiplication operation where one number is a float then the result value will always be a float, and standard floating point artithmetic rules will apply. This is why the coordinates are coming in decimals which don't equate perfectly to pixels.
When using Javascript you need to be careful of these kinds of pitfalls because it is not a strongly typed language like Java and it will not point things like this out to you.
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....
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