Lasso Soft Inc. > Home

[math_bearing]

Linkmath_bearing
AuthorJason Huck
CategoryMath
Version8.5.x
LicensePublic Domain
Posted24 May 2007
Updated24 May 2007
More by this author...

Description

Returns a general compass bearing (i.e. NNW) given degrees. Requires [math_roundto].

Sample Usage

math_bearing(149);

-> SSE

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.

define_tag(
	'bearing',
	-namespace='math_',
	-req='d', -copy,
	-priority='replace',
	-description='Returns a general compass bearing (i.e. NNW) given degrees.'
);
	// convert to decimal
	local('d') = decimal(#d)->setformat( -precision=1)&;

	// degrees between points	
	local('i') = (360.0/16.0);

	// restrict to valid degrees
	fail_if(
		(#d > 360 || #d < -360), -1,
		'[math_bearing] requires a value between -360 and 360 degrees.'
	);

	// convert negative degrees
	#d < 0 ? #d = 360 + #d;

	// catch due north
	#d == 0 || #d == 360 ? return('N');

	// compass points
	local('pts') = treemap(
		0.0		=	'N',
		22.5		=	'NNE',
		45.0		=	'NE',
		67.5		=	'ENE',
		90.0		=	'E',
		112.5	=	'ESE',
		135.0	=	'SE',
		157.5	=	'SSE',
		180.0	=	'S',
		202.5	=	'SSW',
		225.0	=	'SW',
		247.5	=	'WSW',
		270.0	=	'W',
		292.5	=	'WNW',
		315.0	=	'NW',
		337.5	=	'NNW',
		360.0	=	'N'
	);

	// round to nearest point and look up
	local('b') = #pts->find(math_roundto(#d,#i));

	return(#b);
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft