Skip to content

Instantly share code, notes, and snippets.

@alo9507
Created June 29, 2019 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alo9507/8875090cd3de0c1dcc6a49b7512ac90e to your computer and use it in GitHub Desktop.
Save alo9507/8875090cd3de0c1dcc6a49b7512ac90e to your computer and use it in GitHub Desktop.
getCardinalDirectionFromYaw
enum CardinalDirection: String {
case North = "North"
case South = "South"
case East = "East"
case West = "West"
case InBetween = "InBetween"
}
enum RotationDirection {
case Clockwise
case Counterclockwise
}
func getCardinalDirectionFromYaw(yaw: Double, accuracy: Double) {
let cardinalDirection: CardinalDirection
let OFFSET: Double = 23.5
if (accuracy >= 1.91) {
let rotationDirection: RotationDirection = yaw < 0 ? RotationDirection.Counterclockwise : RotationDirection.Clockwise
switch yaw {
case 360-OFFSET..<OFFSET:
cardinalDirection = CardinalDirection.North
case 90-OFFSET..<90+OFFSET:
cardinalDirection = CardinalDirection.East
case 180-OFFSET..<180+OFFSET:
cardinalDirection = CardinalDirection.South
case 270-OFFSET..<270+OFFSET:
cardinalDirection = CardinalDirection.West
default:
cardinalDirection = CardinalDirection.InBetween
}
headingValue.text = cardinalDirection.rawValue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment