return the normal at the right-side of the curve (when increasing t)
(p0, p1, p2, p3 Point, t, d float64)
| 591 | |
| 592 | // return the normal at the right-side of the curve (when increasing t) |
| 593 | func cubicBezierNormal(p0, p1, p2, p3 Point, t, d float64) Point { |
| 594 | // TODO: remove and use cubicBezierDeriv + Rot90CW? |
| 595 | if t == 0.0 { |
| 596 | n := p1.Sub(p0) |
| 597 | if n.X == 0 && n.Y == 0 { |
| 598 | n = p2.Sub(p0) |
| 599 | } |
| 600 | if n.X == 0 && n.Y == 0 { |
| 601 | n = p3.Sub(p0) |
| 602 | } |
| 603 | if n.X == 0 && n.Y == 0 { |
| 604 | return Point{} |
| 605 | } |
| 606 | return n.Rot90CW().Norm(d) |
| 607 | } else if t == 1.0 { |
| 608 | n := p3.Sub(p2) |
| 609 | if n.X == 0 && n.Y == 0 { |
| 610 | n = p3.Sub(p1) |
| 611 | } |
| 612 | if n.X == 0 && n.Y == 0 { |
| 613 | n = p3.Sub(p0) |
| 614 | } |
| 615 | if n.X == 0 && n.Y == 0 { |
| 616 | return Point{} |
| 617 | } |
| 618 | return n.Rot90CW().Norm(d) |
| 619 | } |
| 620 | panic("not implemented") // not needed |
| 621 | } |
| 622 | |
| 623 | // cubicBezierLength calculates the length of the Bézier, taking care of inflection points. It uses Gauss-Legendre (n=5) and has an error of ~1% or less (empirical). |
| 624 | func cubicBezierLength(p0, p1, p2, p3 Point) float64 { |