Skip to content

Instantly share code, notes, and snippets.

@robb

robb/golf.swift Secret

Created February 22, 2023 16:10
Show Gist options
  • Save robb/c125a8283cb9ed6725def210404920a2 to your computer and use it in GitHub Desktop.
Save robb/c125a8283cb9ed6725def210404920a2 to your computer and use it in GitHub Desktop.
import SwiftUI
func unitSquareIntersectionPoint(_ angle: Angle) -> UnitPoint {
let u = sin(angle.radians + .pi / 2)
let v = cos(angle.radians + .pi / 2)
let uSign = abs(u) / u
let vSign = abs(v) / v
if u * u >= v * v {
return UnitPoint(
x: 0.5 + 0.5 * uSign,
y: 0.5 + 0.5 * uSign * (v / u)
)
} else {
return UnitPoint(
x: 0.5 + 0.5 * vSign * (u / v),
y: 0.5 + 0.5 * vSign
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment