File: spline.dem

package info (click to toggle)
gnuplot 3.5beta6.347-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 5,032 kB
  • ctags: 4,235
  • sloc: ansic: 42,086; makefile: 561; asm: 539; sh: 386; objc: 379; csh: 297; pascal: 194; perl: 138; lisp: 88
file content (98 lines) | stat: -rw-r--r-- 2,694 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#
# $Id: spline.dem,v 1.3 1997/04/05 19:44:48 drd Exp $
#
# Some curve plotting using common cubic polynomial basis function for cagd.
#
#				Gershon Elber, Aug. 1992
#
set xrang [0:1]
set grid

set yrange[-0.2:1.4]
m0(x) = 1
m1(x) = x
m2(x) = x**2
m3(x) = x**3
set title "The cubic Monomial basis functions"
plot m0(x), m1(x), m2(x), m3(x)
pause -1 "Press return to continue"

h00(x) = x**2 * ( 2 * x - 3) + 1
h01(x) = -x**2 * (2 * x - 3)
h10(x) = x * (x - 1)**2
h11(x) = x**2 * (x - 1)

set title "The cubic Hermite basis functions"
plot h00(x), h01(x), h10(x), h11(x)
pause -1 "Press return to continue"

bez0(x) = (1 - x)**3
bez1(x) = 3 * (1 - x)**2 * x
bez2(x) = 3 * (1 - x) * x**2
bez3(x) = x**3
set title "The cubic Bezier basis functions"
plot bez0(x), bez1(x), bez2(x), bez3(x)
pause -1 "Press return to continue"

bsp0(x) = ( 1 - 3 * x + 3 * x**2 - x**3 ) / 6;
bsp1(x) = ( 4 - 6 * x**2 + 3 * x**3 ) / 6;
bsp2(x) = ( 1 + 3 * x + 3 * x**2 - 3 * x**3 ) / 6
bsp3(x) = x**3 / 6
set title "The cubic uniform Bspline basis functions"
plot bsp0(x), bsp1(x), bsp2(x), bsp3(x)
pause -1 "Press return to continue"

y0 = 1
y1 = 0.2
y2 = 0.8
y3 = 0

x0 = 0
x1 = 0.33
x2 = 0.66
x3 = 1

xv0 = -0.3
yv0 = 0.5
xv1 = -0.4
yv1 = 0.2

set arrow from x0,y0 to x1,y1 nohead
set arrow from x1,y1 to x2,y2 nohead
set arrow from x2,y2 to x3,y3 nohead

cub_bezier_x(t) = bez0(t) * x0 + bez1(t) * x1 + bez2(t) * x2 + bez3(t) * x3
cub_bezier_y(t) = bez0(t) * y0 + bez1(t) * y1 + bez2(t) * y2 + bez3(t) * y3
cub_bsplin_x(t) = bsp0(t) * x0 + bsp1(t) * x1 + bsp2(t) * x2 + bsp3(t) * x3
cub_bsplin_y(t) = bsp0(t) * y0 + bsp1(t) * y1 + bsp2(t) * y2 + bsp3(t) * y3

set parametric
set trange [0:1]
set title "The cubic Bezier/Bspline basis functions in use"
plot cub_bezier_x(t), cub_bezier_y(t) with lines 2,\
     cub_bsplin_x(t), cub_bsplin_y(t) with lines 3
pause -1 "Press return to continue"

set noarrow
#
# Note the arrows here, scaled by 1/3 so they will fit into plotting area
#
set arrow from x1,y1 to x1+xv0/3,y1+yv0/3
set arrow from x2,y2 to x2+xv1/3,y2+yv1/3
set arrow from x1,y1 to x1+xv0,y1+yv0
set arrow from x2,y2 to x2+xv1,y2+yv1

cub_hermit_x1(t) = h00(t) * x1 + h01(t) * x2 + h10(t) * xv0 + h11(t) * xv1
cub_hermit_y1(t) = h00(t) * y1 + h01(t) * y2 + h10(t) * yv0 + h11(t) * yv1
cub_hermit_x2(t) = h00(t) * x1 + h01(t) * x2 + h10(t) * xv0*3 + h11(t) * xv1*3
cub_hermit_y2(t) = h00(t) * y1 + h01(t) * y2 + h10(t) * yv0*3 + h11(t) * yv1*3
set title "The cubic Hermite basis functions in use"
plot cub_hermit_x1(t), cub_hermit_y1(t) with lines 2,\
     cub_hermit_x2(t), cub_hermit_y2(t) with lines 3
pause -1 "Press return to continue"

set noparametric
set noarrow
set auto
set nogrid
set title ""