B-splines Curves and Surfaces expressed analytically

© 2004 Robert Ipanaqué Chero
Peruvian Applied& Computational Mathematical Society (Member),Perú
E-mail:robertchero@hotmail.com

BsplinesCurvesSurfaces.m

Incorporated commands:

Uniform
Open
Bsplines
Curve
Bsplines3D
Surface
PiecewiseForm

B-splines 2D

f = Bsplines[1, Array[x, 2]]

PiecewiseForm[f]

f = Bsplines[2, Array[x, 3]]

PiecewiseForm[f]

f = Bsplines[2, Array[x, 3, 4]]

PiecewiseForm[f]

f = Bsplines[3, {0, 0, 0, 1}]

f // PiecewiseForm

Plot[f, {t, -1, 2}, PlotRange -> All]

f = Bsplines[u, 3, {0, 0, 0, 1}]

f // PiecewiseForm

Plot[f, {u, -1, 2}, PlotRange -> All]

Bsplines[0.5, 3, {0, 0, 0, 1}]

k = 3;
kv = 
      Partition[{0, 1, 1, 3, 4, 6, 6, 
          6}, {k + 1}, {1}]
n = Length[kv];

ff = Bsplines[k, #] & /@ kv

PiecewiseForm[#] & /@ ff

Plot[
ff // Evaluate, {t, 0, 6}, 
      PlotStyle -> 
        Table[Hue[i/n], {i, n}]
]

k = 6;
kv = Partition[Open[k, k], {k + 1}, {1}]
n = Length[kv];

ff = Bsplines[k, #] & /@ kv

PiecewiseForm[#] & /@ ff

Plot[
ff // Evaluate, {t, 0, 1}, 
      PlotStyle -> 
        Table[Hue[i/n], {i, n}]
]

B-splines Curves

pts = {1, 2, 1, 5, 3};
f = Curve[pts, Knots -> {0, 0, 0, 1, 2, 3, 3, 3}]

{f} // PiecewiseForm

cc = Plot[f // Evaluate]

pts = {{1, 1}, {2, 3}, {3, 1}, {5, 4}, {7, 
            2}};
f = Curve[pts, Knots -> {0, 0, 0, 1, 2, 3, 3, 3}]

{f} // PiecewiseForm

cc = ParametricPlot[f // Evaluate]

Show[
Graphics[{RGBColor[1,  0,  0], 
          Line[pts]}], 
cc, PlotRange -> All, 
      Axes -> True
]

Show[
Graphics[{{RGBColor[1,  0,  0], 
            Line[pts]}, {RGBColor[0, 0, 1], PointSize[0.015], 
            Point /@ pts}}], 
cc, PlotRange -> All, 
      Axes -> True
]

pts = {{1, 1}, {2, 3}, {3, 1}, {5, 4}, {7, 
            2}};
f = 
      Curve[Robert, pts, Knots -> {0, 0, 0, 1, 2, 3, 3, 3}]

{f} // PiecewiseForm

cc = ParametricPlot[f // Evaluate]

pts = {{1, 1}, {2, 3}, {3, 1}, {5, 4}, {7, 
            2}};
Curve[1.3, pts, Knots -> {0, 0, 0, 1, 2, 3, 3, 3}]

pts = {{1, 1, 2}, {2, 3, -1}, {3, 1, 2}, {5, 4, -2}, {7, 2, 
            3}};
f = Curve[pts]

{f} // PiecewiseForm

cc = ParametricPlot3D[f // Evaluate]

Show[
Graphics3D[{RGBColor[1,  0,  0], 
          Line[pts]}], 
cc, 
      Axes -> True
]

pts = {{1, 1, 1, -1}, {2, 3, 2, 1}, {3, 1, -1, 4}, {5, 4, 2, 
            1}, {7, 2, 1, 4}};
f = Curve[pts, Knots -> {0, 0, 0, 1, 2, 3, 3, 3}]

{f} // PiecewiseForm

Giraffe

Back

p1 = {{1.9, 15.5}, {1.9, 15.5}, {2.3, 15}, {2.8, 14}, {3.4, 13}, {4, 
            12.55}, {5, 12}, 
{5.5, 11.4}, {5.6, 11.2}, {6, 
            11}, {6.8, 10.8}, {7.1, 10.6}, {7.3, 10.5}, {8.1, 
            9.6}, 
{8.15, 8}, {7.55, 6.2}, {7.2, 
            4.6}, {7.05, 3.7}, {6.9, 3.45}, {6.9, 3.45}};
f1 = Curve[p1, Knots -> Uniform];
Back = ParametricPlot[f1 // Evaluate]

Legs

p2 = {{7.05, 3.7}, {7.05, 3.7}, {7.1, 3.2}, {6.95, 2.9}, {6.65, 
            1.6}, {6.5, 1}, {6.3, 0.8}, 
{6.4, 0.3}, {6.4, 
            0.3}, {6.15, 0.35}, {5.65, 0.3}, {5.65, 0.3}, {5.8, 0.8}, {6.05, 
            1.05}, 
{6.1, 1.5}, {6.2, 1.8}, {6.35, 
            2.7}, {6.6, 3.5}, {6.6, 3.5}};
f2 = Curve[p2, Knots -> Uniform];
Leg1 = ParametricPlot[f2 // Evaluate]

p3 = {{5.3, 8}, {5.3, 8}, {5.2, 7.2}, {5.2, 5}, {5.1, 4.1}, {5, 
            4}, {5, 4}, {5.05, 3.6}, {5, 2.3}, {5.15, 1.5}, {5, 0.65}, {5.05, 
            0.4}, {5.05, 0.4}, {4.4, 0.2}, {4.25, 0.3}, {4.25, 0.3}, {4.35, 
            0.7}, {4.6, 1}, {4.65, 1.6}, {4.55, 2}, {4.5, 3}, {4.55, 
            4}, {4.55, 4}, {4.4, 4.55}, {4.3, 5.8}, {4.25, 6.5}, {4.1, 
            7.2}, {4, 8.5}, {4, 8.5}};
f3 = Curve[p3, Knots -> Uniform];
Leg2 = ParametricPlot[f3 // Evaluate]

p4 = {{3.75, 7.35}, {3.75, 7.35}, {3.8, 7}, {3.6, 6}, {3.4, 
            5}, {3.22, 4.05}, 
{3.1, 3.95}, {3.1, 
            3.95}, {3.15, 3.85}, {3, 2.75}, {2.65, 1.5}, {2.5, 
            1.3}, 
{2.5, 1.3}, {2.4, 1.1}, {2.3, 
            0.9}, {2.1, 0.8}, {1.7, 0.9}, {1.7, 0.9}, {1.8, 
            1.2}, 
{2.15, 1.4}, {2.15, 1.4}, {2.65, 
            3.7}, {2.75, 4}, {2.75, 4}, {2.65, 4.5}, {2.75, 
            6}, 
{2.5, 7}, {2.65, 8.6}, {2.65, 
            8.6}};
f4 = Curve[p4, Knots -> Uniform];
Leg3 = ParametricPlot[f4 // Evaluate]

p5 = {{7.5, 5.8}, {7.5, 5.8}, {7.7, 5.1}, {7.8, 4.85}, {7.7, 
            4.5}, {7.45, 3.25}, 
{7.55, 2.5}, {7.65, 
            2}, {7.65, 1.8}, {7.35, 1.25}, {7.25, 1}, {7.25, 1}, {7, 
            1}, 
{6.7, 0.9}, {6.7, 0.9}, {6.8, 
            1.45}, {7.15, 1.8}, {7.05, 2.5}, {7.1, 3.9}, {7.1, 
            3.9}};
f5 = Curve[p5, Knots -> Uniform];
Leg4 = ParametricPlot[f5 // Evaluate]

Thighs

p6 = {{6.6, 3.5}, {6.6, 3.5}, {6.5, 4}, {6.55, 5}, {6.6, 5.65}, {6.5, 
            7.8}, {7.05, 9.05}, 
{7.05, 9.05}};
f6 = Curve[p6, Knots -> Uniform];
Thigh1 = ParametricPlot[f6 // Evaluate]

p7 = {{5.5, 7.25}, {5.5, 7.25}, {6, 6.4}, {6.55, 5.67}, {6.55, 
            5.67}};
f7 = Curve[p7, Knots -> Uniform];
Thigh2 = ParametricPlot[f7 // Evaluate]

Belly

p8 = {{6.61, 7.8}, {6.61, 7.8}, {6, 7.4}, {5.2, 7.2}, {5.2, 
            7.2}};
f8 = Curve[p8, Knots -> Uniform];
Belly = ParametricPlot[f8 // Evaluate]

Chest

p9 = {{4.11, 7.2}, {4.11, 7.2}, {3.75, 7.34}, {3.5, 7.65}, {3.5, 
            7.65}};
f9 = Curve[p9, Knots -> Uniform];
Chest1 = ParametricPlot[f9 // Evaluate]

p10 = {{3.05, 7.8}, {3.05, 7.8}, {2.64, 8.54}, {2.5, 9.6}, {2.8, 
            10.8}, {2.8, 10.8}};
f10 = Curve[p10, Knots -> Uniform];
Chest2 = ParametricPlot[f10 // Evaluate]

Neck

p11 = {{3.15, 9.7}, {3.15, 9.7}, {3, 10.1}, {2.8, 10.8}, {2.6, 
            11.8}, {2, 13}, 
{1.5, 14}, {0.6, 15.7}, {0.6, 
            15.7}};
f11 = Curve[p11, Knots -> Uniform];
Neck = ParametricPlot[f11 // Evaluate]

Tail

p12 = {{8, 7.5}, {8, 7.5}, {8.2, 5.5}, {8.05, 4.35}, {7.9, 
            4.25}, {7.8, 4.35}, {7.8, 5.1}, 
{7.7, 
            6.55}, {7.7, 6.55}};
f12 = Curve[p12, Knots -> Uniform];
tail = ParametricPlot[f12 // Evaluate]

Head

p13 = {{0.25, 16.85}, {0.25, 16.85}, {-0.05, 17}, {-0.3, 
            17.6}, {-0.3, 17.6}, 
{0.25, 17.65}, {0.5, 
            17.2}, {0.5, 17.2}, {0.8, 17.5}, {0.7, 17.9}, {1, 
            17.9}, 
{0.97, 17.5}, {1.1, 17.25}, {1.35, 
            17.3}, {1.2, 17.9}, {1.5, 17.85}, {1.55, 
            17.5}, 
{1.7, 17.15}, {1.7, 17.15}, {2.05, 
            17.4}, {2.6, 17.45}, {2.6, 17.45}, {2.3, 
            16.9}, 
{1.98, 16.75}, {1.98, 16.75}, {1.96, 
            16.6}, {1.96, 16.6}};
f13 = Curve[p13, Knots -> Uniform];
head1 = ParametricPlot[f13 // Evaluate]

p14 = {{1.9, 16.5}, {1.9, 16.5}, {1.8, 16.25}, {1.75, 16}, {1.8, 
            15.8}, {1.95, 15.5}, 
{1.8, 15.15}, {1.4, 
            15.2}, {1.1, 15.55}, {0.6, 15.7}, {0.2, 16}, {0.3, 
            16.5}, 
{0.25, 16.85}, {0.4, 17}, {0.4, 
            17}};
f14 = Curve[p14, Knots -> Uniform];
Jaw = ParametricPlot[f14 // Evaluate]

Nose

p15 = {{1.68, 15.71}, {1.68, 15.71}, {1.6, 15.73}, {1.6, 
            15.75}, {1.65, 15.8}, 
{1.85, 15.75}, {1.7, 
            15.71}, {1.5, 15.69}, {1.3, 15.71}, {1.15, 
            15.75}, 
{1.35, 15.8}, {1.4, 15.75}, {1.4, 
            15.73}, {1.32, 15.71}, {1.32, 15.71}};
f15 = Curve[p15, Knots -> Uniform];
nose = ParametricPlot[f15 // Evaluate]

Eyes

p16 = {{1.96, 16.59}, {1.96, 16.59}, {1.945, 16.65}, {1.9, 
            16.695}, {1.81, 16.72}, 
{1.72, 16.68}, {1.75, 
            16.54}, {1.85, 16.48}, {1.96, 16.52}, {1.96, 
            16.59}, 
{1.96, 16.59}};
f16 = Curve[p16, Knots -> Uniform];
Eye1 = ParametricPlot[f16 // Evaluate]

p17 = {{0.3, 16.5}, {0.3, 16.5}, {0.3, 16.55}, {0.31, 16.61}, {0.39, 
            16.7}, 
{0.49, 16.73}, {0.52, 16.63}, {0.5, 
            16.56}, {0.41, 16.48}, {0.32, 16.46}, 
{0.3, 
            16.5}, {0.3, 16.5}};
f17 = Curve[p17, Knots -> Uniform];
Eye2 = ParametricPlot[f17 // Evaluate]

Giraffe

Show[Back, Leg1, Leg2, Leg3, Leg4, Thigh1, Thigh2, Belly, Chest1,  
      Chest2, Neck, tail, head1, Jaw, nose, Eye1, Eye2, 
      AspectRatio -> (18/8), Axes -> False]

B-splines 3D

f = Bsplines3D[3, 3, {0, 1, 2, 3}, {0, 1, 2, 3}]

f // PiecewiseForm

Plot3D[f, {u, 0, 3}, {v, 0, 3}, PlotRange -> All]

f = 
      Bsplines3D[{θ, ϕ}, 3, 
        3, {0, 1, 2, 3}, {0, 1, 2, 3}]

f // PiecewiseForm

Plot3D[f, {θ, 0, 3}, {ϕ, 0, 3}, 
      PlotRange -> All]

Bsplines3D[{1.5, 2.3}, 3, 3, {0, 1, 2, 3}, {0, 1, 2, 3}]

f = Bsplines3D[3, 3, {0, 0, 1, 2}, {0, 0, 1, 2}]

f // PiecewiseForm

Plot3D[f, {u, 0, 3}, {v, 0, 2}, PlotRange -> All]

k1 = 3;
kv1 = 
      Partition[{0, 1, 1, 3, 4, 6, 6, 
          6}, {k1 + 1}, {1}]
n = Length[kv1];
k2 = 3;
kv2 = 
      Partition[{0, 1, 2, 3, 4, 5, 6, 
          7}, {k2 + 1}, {1}]
m = Length[kv2];

ff = 
      Outer[Bsplines3D[k1, k2, #1, #2] &, kv1, kv2, 1, 1] // 
        Flatten

PiecewiseForm[#] & /@ ff

Plot3D[#, {u, 0, 6}, {v, 0, 6}, PlotRange -> All] & /@ 
      ff

B-splines Surfaces

p = {
{{0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {3, 0, 
              0}, {4, 0, 0}, {5, 0, 0}, {6, 0, 0}}, 
{{0, 
              1, 0}, {1, 1, 1}, {2, 1, 1}, {3, 1, 1}, {4, 1, 1}, {5, 1, 
              1}, {6, 1, 0}}, 
{{0, 2, 0}, {1, 2, 1}, {2, 
              2, 1}, {3, 2, 1}, {4, 2, 1}, {5, 2, 1}, {6, 2, 
              0}}, 
{{0, 3, 0}, {1, 3, 1}, {2, 3, 1}, {3, 
              3, 1}, {4, 3, 1}, {5, 3, 1}, {6, 3, 
              0}}, 
{{0, 4, 0}, {1, 4, 1}, {2, 4, 1}, {3, 
              4, 1}, {4, 4, 1}, {5, 4, 1}, {6, 4, 
              0}}, 
{{0, 5, 0}, {1, 5, 1}, {2, 5, 1}, {3, 
              5, 1}, {4, 5, 1}, {5, 5, 1}, {6, 5, 
              0}}, 
{{0, 6, 0}, {1, 6, 0}, {2, 6, 0}, {3, 
              6, 0}, {4, 6, 0}, {5, 6, 0}, {6, 6, 
              0}}
};

s = Surface[p]

PiecewiseForm[{s}]

g = 
      ParametricPlot3D[s // Evaluate, PlotPoints -> {15, 15}]

Show[
      g, 
Graphics3D[{RGBColor[1, 0, 0], 
          Map[Line, p], 
Map[Line, 
            p // Transpose]}]
]

s = Surface[{July, Robert}, p]

PiecewiseForm[{s}]

Surface[{4.5, 3.7}, p]