Skip to main content
added 310 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117

Using gdir's data to test BSplineDer[]

BSplineDer[Pts, w, {5, U}][160]
f = BSplineFunction[Pts, SplineDegree -> p, SplineKnots -> U, SplineWeights -> w]
Needs["NumericalCalculus`"]
ND[f[u], u, 160]

enter image description here


Using gdir's data to test BSplineDer[]

BSplineDer[Pts, w, {5, U}][160]
f = BSplineFunction[Pts, SplineDegree -> p, SplineKnots -> U, SplineWeights -> w]
Needs["NumericalCalculus`"]
ND[f[u], u, 160]

enter image description here

added 23 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117

###The definition of B-Spline curve

$$\bf{C}(u)=\sum _{i=0}^n N_{i,p}(u) \bf{P}_i \text{ }\qquad (0\leq u\leq 1)$$$$\vec{C}(u)=\sum _{i=0}^n N_{i,p}(u) \vec{P}_i \text{ }\qquad (0\leq u\leq 1)$$

where, $\bf{P}_i$$\vec{P}_i$ is the control point, and the $N_ {i, p} (u)$ are the $p$-th - degree B-spline basis functions defineddefined on the non-periodic  (and non-uniform) knot vector $U$.

$$U=\{\underbrace {0,\cdots ,0}_{p+1},u_{p+1},\cdots u_{m-p-1},\underbrace {1,\cdots,1}_{p+1}\}$$

For the non-rational B-spline curve of degree $p$, its derivative is a $p-1$ degree non-rational curve. where, the new control points and knot vector are $Q_i$ and $U'$, respectively. $$\bf Q_i=p \frac{\bf P_{i+1}-\bf P_i}{u_{i+p+1}-u_{i+1}}$$$$\vec Q_i=p \frac{\vec P_{i+1}-\vec P_i}{u_{i+p+1}-u_{i+1}}$$

$$U'=\{\underbrace {0,\cdots ,0}_{p},u_{p+1},\cdots u_{m-p-1},\underbrace {1,\cdots,1}_{p}\}$$

I think the built-in f = BSplineFunction[2D/3D-points];points vector]; f' just returns a non-rational curve.

However, for the rational B-spline curve: $$\bf{C}^w(u)=\frac{\sum_{i=0}^n N_{i,p}(u)w_i\bf{P}_i}{\sum_{i=0}^n N_{i,p}(u)w_i}=\frac{\vec{A}(u)}{w(u)}$$$$\vec{C}^w(u)=\frac{\sum_{i=0}^n N_{i,p}(u)w_i\vec{P}_i}{\sum_{i=0}^n N_{i,p}(u)w_i}=\frac{\vec{A}(u)}{w(u)}$$

where, $\vec P_i=\{x_i, y_i\}$(2D curve) or $\vec P_i=\{x_i, y_i,z_i\}$(3D curve). Then

$$\left[{C^w}(u)\right]'=\left[\frac{\bf A(u)}{w(u)}\right]'=\frac{\bf A'(u)w(u)-\bf A(u)w'(u)}{w^2(u)}$$$$\left[\vec{C}^w(u)\right]'=\left[\frac{\vec A(u)}{w(u)}\right]'=\frac{\vec A'(u)w(u)-\vec A(u)w'(u)}{w^2(u)}$$


The derivative of built-in BSplineFunction[] for curve case is right when the weights is vector that contains same value. Namely, the curve is non-rational.

Here, ptsW = wi {xi, yi, zi}

BSplineDer[pts_, wgts_, {deg_, knots_}][u_?NumericQ] :=
 Module[{ptsW, A, w, Au, wu, AuDer, wuDer},
  ptsW = pts wgts;
  A = BSplineFunction[ptsW, SplineDegree -> deg, SplineKnots -> knots];
  w = BSplineFunction[wgts, SplineDegree -> deg, SplineKnots -> knots];
 (*calculate the A(u) and w(u)*)
  Au = A[u];
  wu = w[u];
  (*calculate the derivative of A(u) and w(u)*)
  AuDer = A'[u];
  wuDer = w'[u];
  (*using the NURBS curve derivative formula*)
  (wu AuDer - wuDer Au)/wu^2
]

###TEST

pts = {{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}};
wgts = {1, 2, 3, 4, 5};
knots = {0, 0, 0, 0, 0.5, 1, 1, 1, 1};
f = BSplineFunction[pts, SplineDegree -> 3, SplineWeights -> {1, 2, 3, 4, 5}]

Show[
 {ParametricPlot[f[t], {t, 0, 1}],
  Graphics[
   {Red, Dashed, Arrowheads[0.03], 
    Table[Arrow[{f[t], f[t] + BSplineDer[pts, wgts, {3, knots}][t]/7}], {t, 0, 1, 0.1}]}],
  ListPlot[f /@ Range[0, 1, 0.1],
   PlotStyle -> Directive[Black, PointSize[Medium]]]},
 PlotRange -> All, Axes -> False
]

enter image description here

###The definition of B-Spline curve

$$\bf{C}(u)=\sum _{i=0}^n N_{i,p}(u) \bf{P}_i \text{ }\qquad (0\leq u\leq 1)$$

where, $\bf{P}_i$ is the control point, and the $N_ {i, p} (u)$ are the $p$-th - degree B-spline basis functions defined on the non-periodic  (and non-uniform) knot vector $U$.

$$U=\{\underbrace {0,\cdots ,0}_{p+1},u_{p+1},\cdots u_{m-p-1},\underbrace {1,\cdots,1}_{p+1}\}$$

For the non-rational B-spline curve of degree $p$, its derivative is a $p-1$ degree non-rational curve. where, the new control points and knot vector are $Q_i$ and $U'$, respectively. $$\bf Q_i=p \frac{\bf P_{i+1}-\bf P_i}{u_{i+p+1}-u_{i+1}}$$

$$U'=\{\underbrace {0,\cdots ,0}_{p},u_{p+1},\cdots u_{m-p-1},\underbrace {1,\cdots,1}_{p}\}$$

I think the built-in f = BSplineFunction[2D-points]; f' just returns a non-rational curve.

However, for the rational B-spline curve: $$\bf{C}^w(u)=\frac{\sum_{i=0}^n N_{i,p}(u)w_i\bf{P}_i}{\sum_{i=0}^n N_{i,p}(u)w_i}=\frac{\vec{A}(u)}{w(u)}$$

where, $\vec P_i=\{x_i, y_i\}$(2D curve) or $\vec P_i=\{x_i, y_i,z_i\}$(3D curve). Then

$$\left[{C^w}(u)\right]'=\left[\frac{\bf A(u)}{w(u)}\right]'=\frac{\bf A'(u)w(u)-\bf A(u)w'(u)}{w^2(u)}$$


The derivative of built-in BSplineFunction[] for curve case is right when the weights is vector that contains same value. Namely, the curve is non-rational.

Here, ptsW = wi {xi, yi, zi}

BSplineDer[pts_, wgts_, {deg_, knots_}][u_?NumericQ] :=
 Module[{ptsW, A, w, Au, wu, AuDer, wuDer},
  ptsW = pts wgts;
  A = BSplineFunction[ptsW, SplineDegree -> deg, SplineKnots -> knots];
  w = BSplineFunction[wgts, SplineDegree -> deg, SplineKnots -> knots];
 (*calculate the A(u) and w(u)*)
  Au = A[u];
  wu = w[u];
  (*calculate the derivative of A(u) and w(u)*)
  AuDer = A'[u];
  wuDer = w'[u];
  (*using the NURBS curve derivative formula*)
  (wu AuDer - wuDer Au)/wu^2
]

###TEST

pts = {{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}};
wgts = {1, 2, 3, 4, 5};
knots = {0, 0, 0, 0, 0.5, 1, 1, 1, 1};
f = BSplineFunction[pts, SplineDegree -> 3, SplineWeights -> {1, 2, 3, 4, 5}]

Show[
 {ParametricPlot[f[t], {t, 0, 1}],
  Graphics[
   {Red, Dashed, Arrowheads[0.03], 
    Table[Arrow[{f[t], f[t] + BSplineDer[pts, wgts, {3, knots}][t]/7}], {t, 0, 1, 0.1}]}],
  ListPlot[f /@ Range[0, 1, 0.1],
   PlotStyle -> Directive[Black, PointSize[Medium]]]},
 PlotRange -> All, Axes -> False
]

enter image description here

###The definition of B-Spline curve

$$\vec{C}(u)=\sum _{i=0}^n N_{i,p}(u) \vec{P}_i \text{ }\qquad (0\leq u\leq 1)$$

where, $\vec{P}_i$ is the control point, and the $N_ {i, p} (u)$ are the $p$-th - degree B-spline basis functions defined on the non-periodic(and non-uniform) knot vector $U$.

$$U=\{\underbrace {0,\cdots ,0}_{p+1},u_{p+1},\cdots u_{m-p-1},\underbrace {1,\cdots,1}_{p+1}\}$$

For the non-rational B-spline curve of degree $p$, its derivative is a $p-1$ degree non-rational curve. where, the new control points and knot vector are $Q_i$ and $U'$, respectively. $$\vec Q_i=p \frac{\vec P_{i+1}-\vec P_i}{u_{i+p+1}-u_{i+1}}$$

$$U'=\{\underbrace {0,\cdots ,0}_{p},u_{p+1},\cdots u_{m-p-1},\underbrace {1,\cdots,1}_{p}\}$$

I think the built-in f = BSplineFunction[2D/3D-points vector]; f' just returns a non-rational curve.

However, for the rational B-spline curve: $$\vec{C}^w(u)=\frac{\sum_{i=0}^n N_{i,p}(u)w_i\vec{P}_i}{\sum_{i=0}^n N_{i,p}(u)w_i}=\frac{\vec{A}(u)}{w(u)}$$

where, $\vec P_i=\{x_i, y_i\}$(2D curve) or $\vec P_i=\{x_i, y_i,z_i\}$(3D curve). Then

$$\left[\vec{C}^w(u)\right]'=\left[\frac{\vec A(u)}{w(u)}\right]'=\frac{\vec A'(u)w(u)-\vec A(u)w'(u)}{w^2(u)}$$


The derivative of built-in BSplineFunction[] for curve case is right when the weights is vector that contains same value. Namely, the curve is non-rational.

Here, ptsW = wi {xi, yi, zi}

BSplineDer[pts_, wgts_, {deg_, knots_}][u_?NumericQ] :=
 Module[{ptsW, A, w, Au, wu, AuDer, wuDer},
  ptsW = pts wgts;
  A = BSplineFunction[ptsW, SplineDegree -> deg, SplineKnots -> knots];
  w = BSplineFunction[wgts, SplineDegree -> deg, SplineKnots -> knots];
 (*calculate the A(u) and w(u)*)
  Au = A[u];
  wu = w[u];
  (*calculate the derivative of A(u) and w(u)*)
  AuDer = A'[u];
  wuDer = w'[u];
  (*using the NURBS curve derivative formula*)
  (wu AuDer - wuDer Au)/wu^2
]

###TEST

pts = {{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}};
wgts = {1, 2, 3, 4, 5};
knots = {0, 0, 0, 0, 0.5, 1, 1, 1, 1};
f = BSplineFunction[pts, SplineDegree -> 3, SplineWeights -> {1, 2, 3, 4, 5}]

Show[
 {ParametricPlot[f[t], {t, 0, 1}],
  Graphics[
   {Red, Dashed, Arrowheads[0.03], 
    Table[Arrow[{f[t], f[t] + BSplineDer[pts, wgts, {3, knots}][t]/7}], {t, 0, 1, 0.1}]}],
  ListPlot[f /@ Range[0, 1, 0.1],
   PlotStyle -> Directive[Black, PointSize[Medium]]]},
 PlotRange -> All, Axes -> False
]

enter image description here

added 11 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117

$$\vec{C}(u)=\sum _{i=0}^n N_{i,p}(u) \vec{P}_i \text{ }\qquad (0\leq u\leq 1)$$$$\bf{C}(u)=\sum _{i=0}^n N_{i,p}(u) \bf{P}_i \text{ }\qquad (0\leq u\leq 1)$$

where, $P_i$$\bf{P}_i$ is the control point, and the $N_ {i, p} (u)$ are the pth $p$-th - degree B-spline basis functions defined on the non-periodic (and non-uniform) knot vector $U$.

For the non-rational B-spline curve of degree $p$, its derivative is a $p-1$ degree non-rational curve. where, the new control points and knot vector are $Q_i$ and $U'$, respectively. $$Q_i=p \frac{P_{i+1}-P_i}{u_{i+p+1}-u_{i+1}}$$$$\bf Q_i=p \frac{\bf P_{i+1}-\bf P_i}{u_{i+p+1}-u_{i+1}}$$

However, for the rational B-spline curve: $$\vec{C}^w(u)=\frac{\sum_{i=0}^n N_{i,p}(u)w_i\vec{P}_i}{\sum_{i=0}^n N_{i,p}(u)w_i}=\frac{\vec{A}(u)}{w(u)}$$$$\bf{C}^w(u)=\frac{\sum_{i=0}^n N_{i,p}(u)w_i\bf{P}_i}{\sum_{i=0}^n N_{i,p}(u)w_i}=\frac{\vec{A}(u)}{w(u)}$$

$$\left[{C^w}(u)\right]'=\left[\frac{\vec A(u)}{w(u)}\right]'=\frac{\vec A'(u)w(u)-\vec A(u)w'(u)}{w^2(u)}$$$$\left[{C^w}(u)\right]'=\left[\frac{\bf A(u)}{w(u)}\right]'=\frac{\bf A'(u)w(u)-\bf A(u)w'(u)}{w^2(u)}$$

BSplineDer[pts_, wgts_, {deg_, knots_}][u_?NumericQ] :=
 Module[{ptsW, A, w, Au, wu, AuDer, wuDer},
  ptsW = pts wgts;
  (*calculate the A(u) and w(u)*)
  A = BSplineFunction[ptsW, SplineDegree -> deg, SplineKnots -> knots];
  w = BSplineFunction[wgts, SplineDegree -> deg, SplineKnots -> knots];
 (*calculate the A(u) and w(u)*)
  Au = A[u];
  wu = w[u];
  (*calculate the derivative of A(u) and w(u)*)
  AuDer = A'[u];
  wuDer = w'[u];
  (*using the NURBS curve derivative formula*)
  (wu AuDer - wuDer Au)/wu^2
]

$$\vec{C}(u)=\sum _{i=0}^n N_{i,p}(u) \vec{P}_i \text{ }\qquad (0\leq u\leq 1)$$

where, $P_i$ is the control point, the $N_ {i, p} (u)$ are the pth - degree B-spline basis functions defined on the non-periodic (and non-uniform) knot vector

For the non-rational B-spline curve of degree $p$, its derivative is a $p-1$ degree non-rational curve. where, the new control points and knot vector are $Q_i$ and $U'$, respectively. $$Q_i=p \frac{P_{i+1}-P_i}{u_{i+p+1}-u_{i+1}}$$

However, for the rational B-spline curve: $$\vec{C}^w(u)=\frac{\sum_{i=0}^n N_{i,p}(u)w_i\vec{P}_i}{\sum_{i=0}^n N_{i,p}(u)w_i}=\frac{\vec{A}(u)}{w(u)}$$

$$\left[{C^w}(u)\right]'=\left[\frac{\vec A(u)}{w(u)}\right]'=\frac{\vec A'(u)w(u)-\vec A(u)w'(u)}{w^2(u)}$$

BSplineDer[pts_, wgts_, {deg_, knots_}][u_?NumericQ] :=
 Module[{ptsW, A, w, Au, wu, AuDer, wuDer},
  ptsW = pts wgts;
  (*calculate the A(u) and w(u)*)
  A = BSplineFunction[ptsW, SplineDegree -> deg, SplineKnots -> knots];
  w = BSplineFunction[wgts, SplineDegree -> deg, SplineKnots -> knots];
  Au = A[u];
  wu = w[u];
  (*calculate the derivative of A(u) and w(u)*)
  AuDer = A'[u];
  wuDer = w'[u];
  (*using the NURBS curve derivative formula*)
  (wu AuDer - wuDer Au)/wu^2
]

$$\bf{C}(u)=\sum _{i=0}^n N_{i,p}(u) \bf{P}_i \text{ }\qquad (0\leq u\leq 1)$$

where, $\bf{P}_i$ is the control point, and the $N_ {i, p} (u)$ are the $p$-th - degree B-spline basis functions defined on the non-periodic (and non-uniform) knot vector $U$.

For the non-rational B-spline curve of degree $p$, its derivative is a $p-1$ degree non-rational curve. where, the new control points and knot vector are $Q_i$ and $U'$, respectively. $$\bf Q_i=p \frac{\bf P_{i+1}-\bf P_i}{u_{i+p+1}-u_{i+1}}$$

However, for the rational B-spline curve: $$\bf{C}^w(u)=\frac{\sum_{i=0}^n N_{i,p}(u)w_i\bf{P}_i}{\sum_{i=0}^n N_{i,p}(u)w_i}=\frac{\vec{A}(u)}{w(u)}$$

$$\left[{C^w}(u)\right]'=\left[\frac{\bf A(u)}{w(u)}\right]'=\frac{\bf A'(u)w(u)-\bf A(u)w'(u)}{w^2(u)}$$

BSplineDer[pts_, wgts_, {deg_, knots_}][u_?NumericQ] :=
 Module[{ptsW, A, w, Au, wu, AuDer, wuDer},
  ptsW = pts wgts;
  A = BSplineFunction[ptsW, SplineDegree -> deg, SplineKnots -> knots];
  w = BSplineFunction[wgts, SplineDegree -> deg, SplineKnots -> knots];
 (*calculate the A(u) and w(u)*)
  Au = A[u];
  wu = w[u];
  (*calculate the derivative of A(u) and w(u)*)
  AuDer = A'[u];
  wuDer = w'[u];
  (*using the NURBS curve derivative formula*)
  (wu AuDer - wuDer Au)/wu^2
]
added 535 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117
Loading
deleted 332 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117
Loading
added 1764 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117
Loading
added 18 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117
Loading
added 18 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117
Loading
added 13 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117
Loading
added 4 characters in body
Source Link
Loading
added 165 characters in body
Source Link
xyz
  • 655
  • 4
  • 38
  • 117
Loading
Source Link
xyz
  • 655
  • 4
  • 38
  • 117
Loading