Skip to content

Instantly share code, notes, and snippets.

@robb

robb/golf.swift Secret

Created February 22, 2023 16:10
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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