View Single Post
  #4 (permalink)  
Old 07-06-2009, 7:34 PM
MattP MattP is offline
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 855
Reputation: 499
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

There was an order of operation issue with your compassPoint calculation.

degrees Mod 360 will give you the degress on the compass you're looking for. (750.0 is really 30.0 etc.)

If you're looking to give an option for 32, 16, 8, 4 points you should be able multiply your point number by 32/number of points to get the correct value out of the Enum. Haven't tested it exhaustively but it worked with several values using 4 and 8 points.

Code:
Public Enum CardinalPoints
	N
	NbE
	NNE
	NEbN
	NE
	NEbE
	ENE
	EbN
	E
	EbS
	ESE
	SEbE
	SE
	SEbS
	SSE
	SbE
	S
	SbW
	SSW
	SWbS
	SW
	SWbW
	WSW
	WbS
	W
	WbN
	WNW
	NWbW
	NW
	NWbN
	NNW
	NbW
End Enum
Code:
Public Class Helper
	Public Function DegreesToCardinalMark(ByVal degrees As Double, ByVal numCardinalPoints As Integer) As String

		degrees = degrees Mod 360
		Dim compassPoint As Integer = CInt(Math.Truncate((degrees / 360) * numCardinalPoints + 0.5) * 32 / numCardinalPoints) Mod 32
		Return CardinalPoints.GetName(GetType(CardinalPoints), compassPoint).ToString()

	End Function
End Class
Code:
Public Class Form1

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Dim a As New Helper
		MessageBox.Show(a.DegreesToCardinalMark(750.0, 8))

	End Sub
End Class
Reply With Quote