[tsp_getdistance]

Description

Link: [tsp_getdistance]
Author: Jason Huck
Category: Math
Version: 8.x
License:
Posted: Jan. 22, 2006
Updated: Jan. 22, 2006
More by this author...
This tag calculates the distance in miles, "as the crow flies", between two sets of coordinates. Used in combination with [tsp_getcosts] and [tsp_gettour], can be used to generate a "next-closest tour" to solve basic TSP problems.

Parameters

-startLat decimal, required Latitude of starting point.
-startLong decimal, required Longitude of starting point.
-endLat decimal, required Latitude of ending point.
-endLong decimal, required Longitude of ending point.

Sample Usage

// test data	
var('cities') = array(
	'Location A' = array(-82.521102,37.484227),
	'Location B' = array(-84.622564,37.059857),
	'Location C' = array(-84.622668,37.059893),
	'Location D' = array(-82.642757,38.480449),
	'Location E' = array(-84.600683,37.031884),
	'Location F' = array(-85.062656,36.982708),
	'Location G' = array(-84.623724,37.055167),
	'Location H' = array(-84.622564,37.059857),
	'Location I' = array(-84.072400,37.107600),
	'Location J' = array(-84.335426,36.841322)	
);

// distance example
'Distance between ' + $cities->get(1)->first + ' and ' + $cities->get(10)->first + ': ';

tsp_getdistance(
	-startLat=$cities->get(1)->second->get(2),
	-startLong=$cities->get(1)->second->get(1),
	-endLat=$cities->get(10)->second->get(2),
	-endLong=$cities->get(10)->second->get(1),
);

' miles<br><br>\n';
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
define_tag(
	'getdistance',
	-namespace='tsp_',
	-priority='replace',
	-required='startLat',
	-type='decimal',
	-required='startLong',
	-type='decimal',
	-required='endLat',
	-type='decimal',
	-required='endLong',
	-type='decimal',
	-description='Calculates distance in miles between two sets of coordinates.'
);	
	local('out') = math_sqrt(
		69.1 * (
			#endLat - #startLat
		) * 69.1 * (
			#endLat - #startLat
		) + 53 * (
			#endLong - #startLong
		) * 53 * (
			#endLong - #startLong
		)
	);
	
	return(#out);	
/define_tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular