Debian Codegraph @

vendor/github.com/xyproto/gfx/bezier.go

raw
1 package gfx
2
3 import "math"
4
5 // CubicBezierCurve returns a slice of vectors representing a cubic bezier curve
6 func CubicBezierCurve(p0, p1, p2, p3 Vec, inc float64) []Vec {
7 if inc <= 0 {
8 return nil
9 }
10
11 var curve []Vec
12
13 for u := 0.0; u <= 1.0; u += inc {
14 n := 1 - u
15 a := math.Pow(n, 3)
16 b := math.Pow(n, 2)
17 c := math.Pow(u, 2)
18 d := math.Pow(u, 3)
19 ub := 3 * u * b
20 cn := 3 * c * n
21
22 curve = append(curve, V(
23 a*p0.X+ub*p1.X+cn*p2.X+d*p3.X,
24 a*p0.Y+ub*p1.Y+cn*p2.Y+d*p3.Y,
25 ))
26 }
27
28 return curve
29 }