<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
               "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
  <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
]>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="../../../comsci/css/s011.css"/>
<style type="text/css">
</style>
<title> C++ Vector Interpolation of Points with Derivatives </title>
</head>
<body>


<div class="message_right">
  <a href="http://validator.w3.org/check/referer">
    <img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid
	XHTML 1.1!" height="31" width="88" />
  </a>

  <a href="http://jigsaw.w3.org/css-validator/">
    <img style="width:88px;height:31px"
       src="http://jigsaw.w3.org/css-validator/images/vcss" 
       alt="Valid CSS!" />
  </a>
  <br/>
  Created 2006-06-23 &nbsp; Modified 
<!--UPDATE_DATE_MODIFIED-->
<!--UPDATE_DATE_BEGIN-->
2007-01-25
<br/>
<a href="mailto:chelton.evans@yahoo.com">Chelton Evans</a>
<!--UPDATE_DATE_END-->
</div>



<h1> 
<a href="../doc.html">
<img alt="proj" src="../../../comsci/images/code.png" /> </a>
vecinterp
<a href="../../../../index.html">
<img alt="home" src="../../../comsci/images/Frame.gif" /> </a>
</h1>


<p>
<a href="#Intro">Intro</a><br/>
<a href="#Visual_Comparision_of_Zero_Order_and_First_Order_Interpolation">
  Visual Comparision of Zero Order and First Order Interpolation</a><br/>
<a href="#Mathematica_Script">Mathematica Script</a><br/>

<a href="#Three_Point_Problem">Three Point Problem</a><br/>


<a href="#&lt;TODO&gt;">&lt;TODO&gt;</a><br/>

</p>


<div class="float25">
<a id="Intro"></a>
<h2>Intro</h2>

<p><b>STATUS:</b> Working.</p>

<p>Vector interpolation.  Assume perfect information can be gained
 at points in space.  A vector function can be used to model or
 approximate the surface between two points - where surface I mean
 1 dimension less than what the points are in.
</p>

<p>
The example in 2D shows linear interpolation between two points
 and interpolation that satisfies the first vector derivative
 at the points.  
</p>

</div>

<div class="spacer" />

<div class="float25">
<a id="Visual_Comparision_of_Zero_Order_and_First_Order_Interpolation"></a>
<h2>Visual Comparision of Zero Order and First Order Interpolation</h2>

<p>Zero order interpolation is straight line interpolation.  
 First order interpolation corresponds to the derivatives being satisfied
 for a polynomial.
</p>

<p>This test image is interpolating two points on a circle.
 Since the circles derivative is known exactly this makes a
 good test case because we have perfect information.
</p>

<p>The red points are the two interpolated points. The blue
 is the linear interpolation, and the green is the first order
 interpolation.
</p>

<p>The orange line between the two is the circle that each is 
 interpolating.  Now you can see that the blue is further away
 from the true solution than the green.  As the order is increased
 the interpolation converge to the true function.
</p>

<p>I have deliberately used points spaced apart so you can see
 the interpolation effects.  Though in real life there are so
 many situations to see this anyway.
</p>

</div>

<div class="float25">
<img src="img01.png" alt="img01.png" />
</div>

<div class="spacer" />


<div class="float25">
<a id="Mathematica_Script"></a>
<h2>Mathematica Script</h2>

<p>The 3D version of the problem and I will be blowed if 
 I am going to solve it by hand. Well not that I have not done
 that sort of thing before, but if a computer can do it without
 error it should do it.  To make my life easier I have done 
 the coefficient calculation for the two point interpolation of 
 a curve in the first order.  
</p>

<pre>
f8[f0_,df0_,f1_,df1_] := Module[ {equ1,equ2,t1},
  equ1 = Sum[ a[i]*t^i,{i,0,3}];
  equ2 = D[equ1,t];
  t1 = Solve[ 
  {
    (equ1 /. t->0) == f0,
    (equ1 /. t->1) == f1,
    (equ2 /. t->0) == df0,
    (equ2 /. t->1) == df1
  }, 
  {a[0],a[1],a[2],a[3]} 
  ];
(*
  Print["t1=",t1];

  Print[ t1[[1]][[1]][[2]] ];
  Print[ t1[[1]][[2]][[2]] ];
  Print[ t1[[1]][[3]][[2]] ];
  Print[ t1[[1]][[4]][[2]] ]; 
*)
  Return[ equ1 /. t1 ];
]

f8[1,0,0,0]

fverify[a_,da_,b_,db_] := Module[ {e1,e2,c0,c1,c2,c3},
  e1 = f8[a,da,b,db];
Print["e1=",e1];
  e2 = D[e1,t];
Print["e2=",e2];
  c0 = (e1 /. t->0)[[1]];
  c1 = (e1 /. t->1)[[1]];
  c2 = (e2 /. t->0)[[1]];
  c3 = (e2 /. t->1)[[1]];
Print["c0=",c0];
Print["c1=",c1];
Print["c2=",c2];
Print["c3=",c3];
  Print[ c0 == a ];
  Print[ c1 == b ];
  Print[ c2 == da ];
  Print[ c3 == db ];
]

fverify[0,0,0,1]
</pre>


</div>



<!--UPDATE_SOURCE_TABLE-->
<!--UPDATE_SOURCE_TABLE_BEGIN-->
<div class="float25">
<a id="Source"> </a>
<h3> <a href="../../download.html">Source</a> </h3>
<div class="float10">
<a href="Makefile.html"> Makefile </a> <br/>
</div>
</div>
<!--UPDATE_SOURCE_TABLE_END-->

<div class="float25">
<a id="Three_Point_Problem"></a>
<h2>Three Point Problem</h2>

<p>
The two point interpolation produced a curve. The three point
 interpolation produces a surface.  n dimensional point interpolation
 generates a n-1 dimensional surface.
</p>

<p>A linear or zero order interpolation between the points
 in 3D is called <a href="../../../math/calculus/geometry/g001.xml#Barycentric_Coordinates"> Barycentric Coordinates</a>. I really object to silly names like
 this because it detracts from the maths, 0th order interpolation
 actually says something.
</p>

<p>The aim is to apply the same method as was done in 2D successfully for
 3D space.  Consider the first derivative problem.
</p>


<p class="equ">
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>u</mi>
  <mo>,</mo>
  <mi>v</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>+</mo>
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0u</mi></mrow>
  </msub>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0u</mi></mrow>
  </msub>
  <mo>+</mo>
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0v</mi></mrow>
  </msub>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0v</mi></mrow>
  </msub>
</math>
</p>

<p>This is  
<math xmlns="&mathml;">
  <mi>p</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
</math>
 contribution over the surface.  
</p>

<p>Lets consider just one of those f polynomial functions and
 how many conditions that it needs to satisfy.
</p>



<p class="equ">
<math xmlns="&mathml;">
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>1</mi>
  <mo>,</mo>
  <mi>0</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>1</mi>
</math>

<br/>

<math xmlns="&mathml;">
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>0</mi>
  <mo>,</mo>
  <mi>1</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>0</mi>
</math>

<br/>

<math xmlns="&mathml;">
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>0</mi>
  <mo>,</mo>
  <mi>0</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>0</mi>
</math>

</p>





<p class="equ">

<math xmlns="&mathml;">
  <mfrac>
    <mrow><mi>&PartialD;</mi></mrow>
    <mrow><mi>&PartialD;</mi><mi>u</mi></mrow>
  </mfrac>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>1</mi>
  <mo>,</mo>
  <mi>0</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>0</mi>
</math>

<br/>

<math xmlns="&mathml;">
  <mfrac>
    <mrow><mi>&PartialD;</mi></mrow>
    <mrow><mi>&PartialD;</mi><mi>u</mi></mrow>
  </mfrac>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>0</mi>
  <mo>,</mo>
  <mi>1</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>0</mi>
</math>

<br/>

<math xmlns="&mathml;">
  <mfrac>
    <mrow><mi>&PartialD;</mi></mrow>
    <mrow><mi>&PartialD;</mi><mi>u</mi></mrow>
  </mfrac>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>0</mi>
  <mo>,</mo>
  <mi>0</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>0</mi>
</math>

</p>

<p class="equ">


<math xmlns="&mathml;">
  <mfrac>
    <mrow><mi>&PartialD;</mi></mrow>
    <mrow><mi>&PartialD;</mi><mi>v</mi></mrow>
  </mfrac>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>1</mi>
  <mo>,</mo>
  <mi>0</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>0</mi>
</math>

<br/>

<math xmlns="&mathml;">
  <mfrac>
    <mrow><mi>&PartialD;</mi></mrow>
    <mrow><mi>&PartialD;</mi><mi>v</mi></mrow>
  </mfrac>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>0</mi>
  <mo>,</mo>
  <mi>1</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>0</mi>
</math>

<br/>

<math xmlns="&mathml;">
  <mfrac>
    <mrow><mi>&PartialD;</mi></mrow>
    <mrow><mi>&PartialD;</mi><mi>v</mi></mrow>
  </mfrac>
  <mi>f</mi>
  <msub>
    <mi></mi>
    <mrow><mi>0</mi></mrow>
  </msub>
  <mo>(</mo>
  <mi>0</mi>
  <mo>,</mo>
  <mi>0</mi>
  <mo>)</mo>
  <mo>=</mo>
  <mi>0</mi>
</math>

</p>

<p>This is just one of the functions.  The other two must 
 also be satisfied.  Now a cubic and lower expansion of two variables
 has 10 coefficients so there is one extra coefficient.
 This is where the element of risk lies.  Assuming symmetry is
 a good thing then either the constant coefficient or
 the u*v coefficient is to be ignored.
</p>

<p>Why do I consider this risky?  For a surface in 3D it really
 needs to be continuous. This means that given any two neighboring
 triangles which share a boundary of two points, the interpolated
 polynomial on one must match the interpolated polynomial of the
 other.  Else the surface would be broken where they meet.
</p>





</div>

<div class="float25">
<a id="&lt;TODO&gt;"></a>
<h2>&lt;TODO&gt;</h2>

<ul>

<li>Move test code to its own class. ie vecInterptest.h </li>
<li>Document all members - even p0 and p1.</li>

<li>Extend to 3D space</li>

<li>Integration of a vector function about a point.<br/>
 *** This is really important. Do any really elegant solutions
 exist?  Or are numerical approaches the only way.
<br/>
Here I believe is an acceptable approach. <br/> 
sum(i=0..n-1,1/2*(r[i]+r[i+1]))*dtheta<br/>
(1/2*(r[0]+r[n])+sum(r[i],i=1..n-1))*dtheta for 2D case.<br/>
r[i] = f(i/n) where f(t) is the vector function.<br/>
dtheta = (theta(n)-theta(0))/n
</li>

<li>The determination of partial derivatives numerically from
 a mesh of points.
</li>

<li>General coefficient solver scripts in Mathematica 
 would be nice.
</li>

</ul>

</div>

</body>
</html>




points.
</li>

<li>General coefficient solver scripts in Mathematica 
 would be nice.
</li>

</ul>

</div>

</body>
</html>




