Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created February 24, 2023 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odrobnik/01b2d0d65b2cb48abf0804d33d975b95 to your computer and use it in GitHub Desktop.
Save odrobnik/01b2d0d65b2cb48abf0804d33d975b95 to your computer and use it in GitHub Desktop.
func unitSquareIntersectionPoint(_ angle: Angle) -> UnitPoint {
let normalizedDegree = angle.degrees.truncatingRemainder(dividingBy: 360)
let degreeProportion = (normalizedDegree / 90).truncatingRemainder(dividingBy: 4)
switch degreeProportion {
case 0: return UnitPoint(x: 1.0, y: 1.0)
case 1: return UnitPoint(x: 1.0, y: 1.0 - (normalizedDegree - 270) / 90)
case 2: return UnitPoint(x: 1.0 - (normalizedDegree - 180) / 90, y: 0.0)
case 3: return UnitPoint(x: 0.0, y: (normalizedDegree - 90) / 90)
default: return .zero
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment