Skip to content

Instantly share code, notes, and snippets.

@alo9507
Created June 30, 2019 14:26
Show Gist options
  • Save alo9507/188e504229cf8f8ecde6c171d43bc469 to your computer and use it in GitHub Desktop.
Save alo9507/188e504229cf8f8ecde6c171d43bc469 to your computer and use it in GitHub Desktop.
get cardinal from yaw
enum CardinalDirection: String {
case North = "North"
case South = "South"
case East = "East"
case West = "West"
case InBetween = "InBetween"
}
func getCardinalDirectionFromYaw(yaw: Double, accuracy: QuaternionAccuracy) {
let cardinalDirection: CardinalDirection
switch yaw {
case -45 ..< 45:
cardinalDirection = CardinalDirection.North
case 45 ..< 135:
cardinalDirection = CardinalDirection.East
case 135 ..< 180:
cardinalDirection = CardinalDirection.South
case -180 ..< -135:
cardinalDirection = CardinalDirection.South
case -135 ..< -45:
cardinalDirection = CardinalDirection.West
default:
cardinalDirection = CardinalDirection.InBetween
}
cardinalHeading.text = "Cardinal Heading: \(cardinalDirection.rawValue)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment