Created
February 24, 2023 15:26
-
-
Save odrobnik/01b2d0d65b2cb48abf0804d33d975b95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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