Page 1 of 1

Using the Azimuth Elevation script

Posted: 04.04.2010, 05:55
by fungun
I downloaded the script from the ML and tried it out.
Now I am assuming that it works like you are standing on earth at the beginning of the script, correct?
So if I do the "enter-star name-enter-c" I should get it's RA, which i think is right. I typed in GAM Hya then "c" to center it
and it gave me a RA of 13h 18m 55.2s, looked it up on wikipedia and it said 13h 18m 55.3s, so I assume the script is right.
But the script gives a DEC of -23.17, where as wikipedia gives -23h 10m 18s.
So how do convert that -23.17 that the script gives to what Wikipedia gives?

Thanks,
Tim

Re: Using the Azimuth Elevation script

Posted: 04.04.2010, 08:04
by Vincent
You need a function to converts the hour decimal value to hour, min, sec:

Code: Select all

hourToHourMinSec = function(hour)
     local    a = math.abs(hour);
     local    h = math.floor(a);
     local    r = (a - h) * 60;
     local    m = math.floor(r);
     local    s = (r - m) * 60;
     return string.format("%0.0fh %02.0fm %2.0fs", h, m, s);
end

value_hms = hourToHourMinSec(value_hour)

Re: Using the Azimuth Elevation script

Posted: 04.04.2010, 08:20
by fungun
Thanks you, but what do I do with this function? or where do I put it?

Tim

Re: Using the Azimuth Elevation script

Posted: 04.04.2010, 15:59
by Vincent
You can paste the hourToHourMinSec() function just below the deg2hms() function.

Then, change the following line (at the end of the script):

Code: Select all

local radec_string = string.format("RA: %2ih %2im %2.1fs  Dec: %3.2f°", h, m, s, dec)

into:

Code: Select all

local radec_string = string.format("RA: %2ih %2im %2.1fs  Dec: %s", h, m, s, hourToHourMinSec(dec))


That should do it.

Re: Using the Azimuth Elevation script

Posted: 04.04.2010, 19:06
by fungun
Well I must have messed it up :(
Get this error now (see pic)
Also attached the script with the changes I made that you gave me.
Thank you for your help,
Tim

Re: Using the Azimuth Elevation script

Posted: 04.04.2010, 22:30
by VikingTechJPL
Hi Tim,

I have seen pics of many of your Star Trek add-ons, and they are awesome. I hope to see many more to come.

Regarding the Declination issue, here are a few notes for Vincent that may help.


Hi Vincent,

1) Since it's a Declination we're talking about, it should be given in ?, arc-minutes and arc-seconds, rather than in hours, minutes and seconds. I found this Wikipedia link to confiirm that they expressed it correctly. http://en.wikipedia.org/wiki/Gamma_Hydrae If it's expressed differently in another link, it's probably a mis-type.
2) Shouldn't you use math.abs() first when a Declination is negative? Lua's math.floor() function returns the integer "less than" a value given, so—since this Declination (-23.17) is negative—it runs into problems because math.floor( -23.17 ) should return -24. I always "save" the negative sign as a boolean, then use math.abs( ) before the conversion, then add the sign back to the degrees.

Here's my function that converts Decimal Degrees to Degrees, ArcMinutes and Arc-Seconds. The logic is essentially the same as in your code, except for the missing math.abs( ) function.

Code: Select all

function DecimalDegreesToDMS ( DecimalDegrees )
   local Deg, DecimalMin, Min, Sec
   local DegreesNegative
   if DecimalDegrees < 0 then
      DegreesNegative = true
   else
      DegreesNegative = false
   end
   Deg = math.floor (math.abs ( DecimalDegrees ) )
   DecimalMin =  math.abs ( DecimalDegrees ) - Deg
   Min = math.floor ( ( DecimalMin ) * 60 )
   Sec = ( ( DecimalMin * 60 ) - Min ) * 60
   if DegreesNegative then Deg = -Deg end
   return Deg, Min, Sec
end    -- of DecimalDegreesToDMS ( )


Hope it helps.

--Gary

Re: Using the Azimuth Elevation script

Posted: 04.04.2010, 23:18
by fungun
Thank you :)
Now just to make sure I get this right .
I take this code-

Code: Select all

function DecimalDegreesToDMS ( DecimalDegrees )
   local Deg, DecimalMin, Min, Sec
   local DegreesNegative
   if DecimalDegrees < 0 then
      DegreesNegative = true
   else
      DegreesNegative = false
   end
   Deg = math.floor (math.abs ( DecimalDegrees ) )
   DecimalMin =  math.abs ( DecimalDegrees ) - Deg
   Min = math.floor ( ( DecimalMin ) * 60 )
   Sec = ( ( DecimalMin * 60 ) - Min ) * 60
   if DegreesNegative then Deg = -Deg end
   return Deg, Min, Sec
end    -- of DecimalDegreesToDMS ( )


And put in place of this code-

Code: Select all

function deg2hms(deg)
  deg_p_hour = 360/24
  deg_p_minute = 360 / (24*60)
  deg_p_second = 360 / (24*60*60)
  hours = math.floor(deg / deg_p_hour)
  deg = deg - deg_p_hour * hours
  minutes = math.floor(deg / deg_p_minute )
  deg = deg - deg_p_minute * minutes
  seconds = deg / deg_p_second
  return hours, minutes, math.floor(10*seconds)/10
end

hourToHourMinSec = function(hour)
     local    h = math.floor(hour);
     local    r = (hour - h) * 60;
     local    m = math.floor(r);
     local    s = (r - m) * 60;
     return string.format("%0.0fh %02.0fm %2.0fs", h, m, s);
end

value_hms = hourToHourMinSec(value_hour)


Thank you for help guys,
Tim

Re: Using the Azimuth Elevation script

Posted: 05.04.2010, 09:20
by Vincent
fungun wrote:Well I must have messed it up :(
Get this error now (see pic)
You need to remove the following line from your code:

Code: Select all

value_hms = hourToHourMinSec(value_hour)
This line was simply given as an example of how to call the hourToHourMinSec function.


VikingTechJPL wrote:1) Since it's a Declination we're talking about, it should be given in ?, arc-minutes and arc-seconds, rather than in hours, minutes and seconds.
Yes, sure. Tim should actually do the maths to convert the hour, min, sec wikipedia values into deg, arc-min, arc-sec.
I provided the hourToHourMinSec() function because he was asking for it, though.


VikingTechJPL wrote:2) Shouldn't you use math.abs() first when a Declination is negative? Lua's math.floor() function returns the integer "less than" a value given, so—since this Declination (-23.17) is negative—it runs into problems because math.floor( -23.17 ) should return -24. I always "save" the negative sign as a boolean, then use math.abs( ) before the conversion, then add the sign back to the degrees.
Right! I took the code from the degTohms function and removed math.abs(deg / 15).
Then, I just forgot to add back math.abs(). Thanks! This is fixed now.

Re: Using the Azimuth Elevation script

Posted: 05.04.2010, 12:46
by fungun
Vincent, thank you.
It works perfect now :D

Tim