Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 5 of 5

Thread: Revilations

  1. #1
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160

    Revilations

    Well at least to me. I was working on a function to calculate the distance between two waypoints(defined by longitude and latitude) and in working in building a function found a couple of things.

    1. LUA has a math.pi function built into it to define the value of pi.

    2. don't try to declare a variable as a local variable twice in the same block. LUA doesn't like it. I ended up with a function where I included an if statement to figure out if the difference between two longitude measurements was greater or less than 0 and had two local declarations one in the true and false for the same variable. AMS/LUA doesn't like it. Stay away from it

    Just thought I would share. Here is the function that figures distance and angle between two points on a geodisic sphere.

    Code:
    -- returns two values, one the distance betwen the two points and the angle between the two.
    -- latitude and longitude need to be defined as radians not degrees.
    function DistAngle(nlat1, nlon1, nlat2, nlon2)
    	local distance = 2 * Math.Asin(Math.Sqrt((Math.Sin((nlat1 - nlat2)/2))^2 + Math.Cos(nlat1)*Math.Cos(nlat2)*(Math.Sin((nlon1 -nlon2)/2))^2));
    	if Math.Sin(nlon2 - nlon1) < 0 then
    		angle = Math.Acos((Math.Sin(nlat2)-Math.Sin(nlat1) * Math.Cos(distance))/(Math.Sin(distance)*Math.Cos(nlat1)));
    	else
    		angle = 2 * pi - Math.Acos((Math.Sin(nlat2) - Math.Sin(nlat1) * Math.Cos(distance))/(Math.Sin(distance)* Math.Cos(nlat1)))
    	end	
    	return distance *180*60/pi, Math.Deg(angle)
    end
    Tigg

    BTW don't ask me about the math because I found the calulations on the web . . . somewhere.
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  2. #2
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Cool post!

    Corey Milner
    Creative Director, Indigo Rose Software

  3. #3
    Join Date
    Jun 2001
    Location
    California
    Posts
    2,014
    He did this during lunch breaks no less!

  4. #4
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Thanks. BTW this is what AMS did not like. Debug is a good thing

    Code:
    function DistAngle(nlat1, nlon1, nlat2, nlon2)
    	local distance = 2 * Math.Asin(Math.Sqrt((Math.Sin((nlat1 - nlat2)/2))^2 + Math.Cos(nlat1)*Math.Cos(nlat2)*(Math.Sin((nlon1 -nlon2)/2))^2));
    	if Math.Sin(nlon2 - nlon1) < 0 then
    		local angle = Math.Acos((Math.Sin(nlat2)-Math.Sin(nlat1) * Math.Cos(distance))/(Math.Sin(distance)*Math.Cos(nlat1)));
    	else
    		local angle = 2 * pi - Math.Acos((Math.Sin(nlat2) - Math.Sin(nlat1) * Math.Cos(distance))/(Math.Sin(distance)* Math.Cos(nlat1)))
    	end	
    	return distance *180*60/pi, Math.Deg(angle)
    end
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  5. #5
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    He did this during lunch breaks no less!
    I can easily picture Tigg carving the model for this function in his mashed potatoes like Dreyfuss in Close Encounters.

    I wonder if this calculation is technically considered to be bipolar?

    Corey Milner
    Creative Director, Indigo Rose Software

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts