Last active
August 23, 2021 17:57
-
-
Save codelynx/4f6a97080709ecd2206c0bf5c128d16e to your computer and use it in GitHub Desktop.
casteljau function where t = 0...1
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 casteljau<T: FloatingPoint>(_ v0: T, _ v1: T, _ t: T) -> T { | |
| return v0 + (v1 - v0) * t | |
| } | |
| func casteljau<T: FloatingPoint>(_ v0: T, _ v1: T, _ v2: T, _ t: T) -> T { | |
| let q0 = v0 + (v1 - v0) * t | |
| let q1 = v1 + (v2 - v1) * t | |
| return q0 + (q1 - q0) * t | |
| } | |
| func casteljau<T: FloatingPoint>(_ v0: T, _ v1: T, _ v2: T, _ v3: T, _ t: T) -> T { | |
| let q0 = v0 + (v1 - v0) * t | |
| let q1 = v1 + (v2 - v1) * t | |
| let q2 = v2 + (v3 - v2) * t | |
| let r0 = q0 + (q1 - q0) * t | |
| let r1 = q1 + (q2 - q1) * t | |
| return r0 + (r1 - r0) * t | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment