Code archives/Miscellaneous/RotaryDirection

This code has been declared by its author to be Public Domain code.

Download source code

RotaryDirection by Skully2002
Returns the quickest direction to move in 360 degrees to arrive at the destination angle from the source angle

Smooth# is a curvevalue for smoothing the movement

a value of 1 for smooth would return the shortest "distance" between the angles.. a value of 2 would return 1/2 the distance...
Function rotarydir#(Asource#,Adest#,smooth#)
	If Asource#>Adest#
		Diff1#=Asource-Adest
		diff2#=(360.0-Asource)+Adest
		If diff2<diff1
			dir#=diff2/smooth
		Else
			dir#=diff1/smooth*-1
		EndIf
	Else
		If Asource#<Adest#
			diff1=Adest-Asource
			diff2=(360.0-Adest)+Asource
			If diff2<diff1
				dir#=diff2/smooth*-1
			Else
				dir#=diff1/smooth
			EndIf
		Else
			dir=0
		EndIf
	EndIf
	Return dir
End Function	

Comments

None.

Code Archives Forum