summaryrefslogtreecommitdiff
path: root/modules/interpolation/help/en_US/splin3d.xml
blob: 7a9d64454b762e8d3d942673834e345d7e3115ca (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?xml version="1.0" encoding="UTF-8"?>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="splin3d" xml:lang="en">
    <refnamediv>
        <refname>splin3d</refname>
        <refpurpose>spline gridded 3d interpolation</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Calling Sequence</title>
        <synopsis>tl = splin3d(x, y, z, v, [order])</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>x,y,z</term>
                <listitem>
                    <para>strictly increasing row vectors (each with at least 3
                        components) defining the 3d interpolation grid
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>v</term>
                <listitem>
                    <para>nx x ny x nz hypermatrix (nx, ny, nz being the length of
                        <literal>x</literal>, <literal>y</literal> and
                        <literal>z</literal>)
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>order</term>
                <listitem>
                    <para>(optional) a 1x3 vector [kx,ky,kz] given the order of the
                        tensor spline in each direction (default [4,4,4], i.e. tricubic
                        spline)
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>tl</term>
                <listitem>
                    <para>a tlist of type splin3d defining the spline</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            This function computes a 3d tensor spline <emphasis>s</emphasis>
            which interpolates the <emphasis>(xi,yj,zk,vijk)</emphasis> points, ie, we
            have <emphasis>s(xi,yj,zk)=vijk</emphasis> for all
            <emphasis>i=1,..,nx</emphasis>, <emphasis>j=1,..,ny</emphasis> and
            <emphasis>k=1,..,nz</emphasis>. The resulting spline
            <emphasis>s</emphasis> is defined by <literal>tl</literal> which consists
            in a B-spline-tensor representation of <emphasis>s</emphasis>. The
            evaluation of <emphasis>s</emphasis> at some points must be done by the
            <link linkend="interp3d">interp3d</link> function (to compute
            <emphasis>s</emphasis> and its first derivatives) or by the <link linkend="bsplin3val">bsplin3val</link> function (to compute an arbitrary
            derivative of <emphasis>s</emphasis>) . Several kind of splines may be
            computed by selecting the order of the spline in each direction
            <literal>order=[kx,ky,kz]</literal>.
        </para>
    </refsection>
    <refsection>
        <title>Remark</title>
        <para>This function works under the conditions:</para>
        <informalequation>
            <mediaobject>
                <imageobject>
                    <imagedata align="center" fileref="../mml/splin3d_equation1.mml"/>
                </imageobject>
            </mediaobject>
        </informalequation>
        <para>an error being issued when they are not respected.</para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[ 
// example 1
// =============================================================================

func =  "v=cos(2*%pi*x).*sin(2*%pi*y).*cos(2*%pi*z)";
deff("v=f(x,y,z)",func);
n = 10;  // n x n x n  interpolation points
x = linspace(0,1,n); y=x; z=x; // interpolation grid
[X,Y,Z] = ndgrid(x,y,z);
V = f(X,Y,Z);
tl = splin3d(x,y,z,V,[5 5 5]);
m = 10000;
// compute an approximated error
xp = grand(m,1,"def"); yp = grand(m,1,"def"); zp = grand(m,1,"def");
vp_exact = f(xp,yp,zp);
vp_interp = interp3d(xp,yp,zp, tl);
er = max(abs(vp_exact - vp_interp))
// now retry with n=20 and see the error
 ]]></programlisting>
        
        <programlisting role="example"><![CDATA[ 

// example 2 (see linear_interpn help page which have the
//            same example with trilinear interpolation)
// =============================================================================

exec("SCI/modules/interpolation/demos/interp_demo.sci")
func =  "v=(x-0.5).^2 + (y-0.5).^3 + (z-0.5).^2";
deff("v=f(x,y,z)",func);
n = 5;
x = linspace(0,1,n); y=x; z=x;
[X,Y,Z] = ndgrid(x,y,z);
V = f(X,Y,Z);
tl = splin3d(x,y,z,V);
// compute (and display) the 3d spline interpolant on some slices
m = 41;
direction = ["z="  "z="  "z="  "x="  "y="];
val = [ 0.1   0.5   0.9   0.5   0.5];
ebox = [0 1 0 1 0 1];
XF=[]; YF=[]; ZF=[]; VF=[];
for i = 1:length(val)
  [Xm,Xp,Ym,Yp,Zm,Zp] = slice_parallelepiped(direction(i), val(i), ebox, m, m, m);
  Vm = interp3d(Xm,Ym,Zm, tl);
  [xf,yf,zf,vf] = nf3dq(Xm,Ym,Zm,Vm,1);
  XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf]; 
  Vp = interp3d(Xp,Yp,Zp, tl);
  [xf,yf,zf,vf] = nf3dq(Xp,Yp,Zp,Vp,1);
  XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf]; 
end
nb_col = 128;
vmin = min(VF); vmax = max(VF);
color_example = dsearch(VF,linspace(vmin,vmax,nb_col+1));
xset("colormap",jetcolormap(nb_col));
clf(); xset("hidden3d",xget("background"));
colorbar(vmin,vmax)
plot3d(XF, YF, list(ZF,color_example), flag=[-1 6 4])
xtitle("3d spline interpolation of "+func)
show_window()
 ]]></programlisting>
        <scilab:image localized="true">
            exec("SCI/modules/interpolation/demos/interp_demo.sci")
            func =  "v=(x-0.5).^2 + (y-0.5).^3 + (z-0.5).^2";
            deff("v=f(x,y,z)",func);
            n = 5;
            x = linspace(0,1,n); y=x; z=x;
            [X,Y,Z] = ndgrid(x,y,z);
            V = f(X,Y,Z);
            tl = splin3d(x,y,z,V);
            m = 41;
            direction = ["z="  "z="  "z="  "x="  "y="];
            val = [ 0.1   0.5   0.9   0.5   0.5];
            ebox = [0 1 0 1 0 1];
            XF=[]; YF=[]; ZF=[]; VF=[];
            for i = 1:length(val)
            [Xm,Xp,Ym,Yp,Zm,Zp] = slice_parallelepiped(direction(i), val(i), ebox, m, m, m);
            Vm = interp3d(Xm,Ym,Zm, tl);
            [xf,yf,zf,vf] = nf3dq(Xm,Ym,Zm,Vm,1);
            XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf]; 
            Vp = interp3d(Xp,Yp,Zp, tl);
            [xf,yf,zf,vf] = nf3dq(Xp,Yp,Zp,Vp,1);
            XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf]; 
            end
            nb_col = 128;
            vmin = min(VF); vmax = max(VF);
            color_example = dsearch(VF,linspace(vmin,vmax,nb_col+1));
            xset("colormap",jetcolormap(nb_col));
            clf(); xset("hidden3d",xget("background"));
            colorbar(vmin,vmax)
            plot3d(XF, YF, list(ZF,color_example), flag=[-1 6 4])
            xtitle("3d spline interpolation of "+func)
        </scilab:image>
    </refsection>
    <refsection role="see also">
        <title>See Also</title>
        <simplelist type="inline">
            <member>
                <link linkend="linear_interpn">linear_interpn</link>
            </member>
            <member>
                <link linkend="interp3d">interp3d</link>
            </member>
            <member>
                <link linkend="bsplin3val">bsplin3val</link>
            </member>
        </simplelist>
    </refsection>
    <refsection>
        <title>History</title>
        <revhistory>
            <revision>
                <revnumber>5.4.0</revnumber>
                <revremark>previously, imaginary part of input arguments were implicitly ignored.</revremark>
            </revision>
        </revhistory>
    </refsection>
</refentry>