Daniel
Sapoundjiev on
Bounding box of cubic bezier curve Split cubic bezier curve into 2 partsCreated: 31 October 2018 Last updated: 31.10.2018 Background
Basics![]()
Line segment equations Bounding box borderThe bounding box border can be formed by the end points of the cubic bezier curve or by inner point. Calculations
To have vertical or horizontal slope P and Q should be equal Code
function getBezierSegment(ap1, ap2, ap3, ap4: TPoint2D64; at: Double; out oCtrlPt2: TPoint2D64): TPoint2D64; var x, y, t1, t2, t1_, t2_, v1x, v1y, v2x, v2y, a1, a2: Double; function getValueX(at1: Double): Double; begin Result := (1-at1)*(1-at1)*(1-at1)*ap1.X + 3*(1-at1)*(1-at1)*at1*ap2.X + 3*(1-at1)*at1*at1*ap3.X + at1*at1*at1*ap4.X; end; function getValueY(at1: Double): Double; begin Result := (1-at1)*(1-at1)*(1-at1)*ap1.Y + 3*(1-at1)*(1-at1)*at1*ap2.Y + 3*(1-at1)*at1*at1*ap3.Y + at1*at1*at1*ap4.Y; end; begin x := getValueX(at); y := getValueY(at); t1 := 0.6; t2 := 0.4; t1_ := t1 * at; t2_ := t2 * at; v1x := getValueX(t1_); v1y := getValueY(t1_); v2x := getValueX(t2_); v2y := getValueY(t2_); a1 := (125*v1X - 8*ap1.X - 27*X)/90; a2 := (125*v2X - 27*ap1.X - 8*X)/30; v1x := a2 - 2 * a1; Result.X := v1x; v2x := 5/3*a1 - 2/3*v1x; oCtrlPt2.X := v2x; a1 := (125*v1Y - 8*ap1.Y - 27*Y)/90; a2 := (125*v2Y - 27*ap1.Y - 8*Y)/30; v1y := a2 - 2 * a1; Result.Y := v1y; v2y := 5/3*a1 - 2/3*v1y; oCtrlPt2.Y := v2y; end; function getBezierSegment2(ap1, ap2, ap3, ap4: TPoint2D64; at: Double; out oCtrlPt2: TPoint2D64): TPoint2D64; var x, y, t1, t2, t1_, t2_, v1x, v1y, v2x, v2y, a1, a2: Double; function getValueX(at1: Double): Double; begin Result := (1-at1)*(1-at1)*(1-at1)*ap1.X + 3*(1-at1)*(1-at1)*at1*ap2.X + 3*(1-at1)*at1*at1*ap3.X + at1*at1*at1*ap4.X; end; function getValueY(at1: Double): Double; begin Result := (1-at1)*(1-at1)*(1-at1)*ap1.Y + 3*(1-at1)*(1-at1)*at1*ap2.Y + 3*(1-at1)*at1*at1*ap3.Y + at1*at1*at1*ap4.Y; end; begin x := getValueX(at); y := getValueY(at); t1 := 0.6; t2 := 0.4; t1_ := (1-at) * t1 + at; t2_ := (1-at) * t2 + at; v1x := getValueX(t1_); v1y := getValueY(t1_); v2x := getValueX(t2_); v2y := getValueY(t2_); a1 := (125*v1X - 8*X - 27*ap4.X)/90; a2 := (125*v2X - 27*X - 8*ap4.X)/30; v1x := a2 - 2 * a1; Result.X := v1x; v2x := 5/3*a1 - 2/3*v1x; oCtrlPt2.X := v2x; a1 := (125*v1Y - 8*Y - 27*ap4.Y)/90; a2 := (125*v2Y - 27*Y - 8*ap4.Y)/30; v1y := a2 - 2 * a1; Result.Y := v1y; v2y := 5/3*a1 - 2/3*v1y; oCtrlPt2.Y := v2y; end;Back to main menu |