Last active
March 30, 2022 07:58
-
-
Save vyppN/fd0787f8c0163d5fe498a2d31210f183 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 tanx(_ 𝜽: CGFloat) -> CGFloat { | |
| return tan(𝜽 * CGFloat.pi / 180) | |
| } | |
| public func calculatePoints(for angle: CGFloat) { | |
| var ang = (-angle).truncatingRemainder(dividingBy: 360) | |
| if ang < 0 { ang = 360 + ang } | |
| let n: CGFloat = 0.5 | |
| switch ang { | |
| case 0...45, 315...360: | |
| let a = CGPoint(x: 0, y: n * tanx(ang) + n) | |
| let b = CGPoint(x: 1, y: n * tanx(-ang) + n) | |
| startPoint = a | |
| endPoint = b | |
| case 45...135: | |
| let a = CGPoint(x: n * tanx(ang - 90) + n, y: 1) | |
| let b = CGPoint(x: n * tanx(-ang - 90) + n, y: 0) | |
| startPoint = a | |
| endPoint = b | |
| case 135...225: | |
| let a = CGPoint(x: 1, y: n * tanx(-ang) + n) | |
| let b = CGPoint(x: 0, y: n * tanx(ang) + n) | |
| startPoint = a | |
| endPoint = b | |
| case 225...315: | |
| let a = CGPoint(x: n * tanx(-ang - 90) + n, y: 0) | |
| let b = CGPoint(x: n * tanx(ang - 90) + n, y: 1) | |
| startPoint = a | |
| endPoint = b | |
| default: | |
| let a = CGPoint(x: 0, y: n) | |
| let b = CGPoint(x: 1, y: n) | |
| startPoint = a | |
| endPoint = b | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment