math/doc/html/math_toolkit/vector_barycentric.html
2019-10-31 17:55:35 +00:00

130 lines
14 KiB
HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Vector-valued Barycentric Rational Interpolation</title>
<link rel="stylesheet" href="../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Math Toolkit 2.11.0">
<link rel="up" href="../interpolation.html" title="Chapter&#160;12.&#160;Interpolation">
<link rel="prev" href="barycentric.html" title="Barycentric Rational Interpolation">
<link rel="next" href="catmull_rom.html" title="Catmull-Rom Splines">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="barycentric.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../interpolation.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="catmull_rom.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="math_toolkit.vector_barycentric"></a><a class="link" href="vector_barycentric.html" title="Vector-valued Barycentric Rational Interpolation">Vector-valued Barycentric
Rational Interpolation</a>
</h2></div></div></div>
<h4>
<a name="math_toolkit.vector_barycentric.h0"></a>
<span class="phrase"><a name="math_toolkit.vector_barycentric.synopsis"></a></span><a class="link" href="vector_barycentric.html#math_toolkit.vector_barycentric.synopsis">Synopsis</a>
</h4>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">interpolators</span><span class="special">/</span><span class="identifier">vector_barycentric_rational</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">TimeContainer</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">SpaceContainer</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">vector_barycentric_rational</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">using</span> <span class="identifier">Real</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">TimeContainer</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">Point</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">SpaceContainer</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">;</span>
<span class="identifier">vector_barycentric_rational</span><span class="special">(</span><span class="identifier">TimeContainer</span><span class="special">&amp;&amp;</span> <span class="identifier">times</span><span class="special">,</span> <span class="identifier">SpaceContainer</span><span class="special">&amp;&amp;</span> <span class="identifier">points</span><span class="special">,</span> <span class="identifier">size_t</span> <span class="identifier">approximation_order</span> <span class="special">=</span> <span class="number">3</span><span class="special">);</span>
<span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">Point</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">Point</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">Real</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="keyword">void</span> <span class="identifier">prime</span><span class="special">(</span><span class="identifier">Point</span><span class="special">&amp;</span> <span class="identifier">dxdt</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">Point</span> <span class="identifier">prime</span><span class="special">(</span><span class="identifier">Real</span> <span class="identifier">t</span><span class="special">);</span>
<span class="keyword">void</span> <span class="identifier">eval_with_prime</span><span class="special">(</span><span class="identifier">Point</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">Point</span><span class="special">&amp;</span> <span class="identifier">dxdt</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">Point</span><span class="special">,</span> <span class="identifier">Point</span><span class="special">&gt;</span> <span class="identifier">eval_with_prime</span><span class="special">(</span><span class="identifier">Real</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
<span class="special">}}</span>
</pre>
<h4>
<a name="math_toolkit.vector_barycentric.h1"></a>
<span class="phrase"><a name="math_toolkit.vector_barycentric.description"></a></span><a class="link" href="vector_barycentric.html#math_toolkit.vector_barycentric.description">Description</a>
</h4>
<p>
The <span class="emphasis"><em>n</em></span> dimensional vector-valued barycentric rational interpolator
is exactly the same as <span class="emphasis"><em>n</em></span> scalar-valued barycentric rational
interpolators. This is provided primarily for convenience and a slight improvement
in efficiency over using <span class="emphasis"><em>n</em></span> different rational interpolators
and combining their results.
</p>
<p>
Use of the class requires a <code class="computeroutput"><span class="identifier">Point</span></code>-type
which has size known at compile-time. These requirements are satisfied by (for
example) <code class="computeroutput"><span class="identifier">Eigen</span><span class="special">::</span><span class="identifier">Vector2d</span></code>s and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">array</span><span class="special">&lt;</span><span class="identifier">Real</span><span class="special">,</span> <span class="identifier">N</span><span class="special">&gt;</span></code> classes. The call to the constructor computes
the weights:
</p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">vector_barycentric_rational</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">t</span><span class="special">(</span><span class="number">100</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="identifier">Eigen</span><span class="special">::</span><span class="identifier">Vector2d</span><span class="special">&gt;</span> <span class="identifier">y</span><span class="special">(</span><span class="number">100</span><span class="special">);</span>
<span class="comment">// initialize t and y . . .</span>
<span class="identifier">vector_barycentric_rational</span><span class="special">&lt;</span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">t</span><span class="special">),</span> <span class="keyword">decltype</span><span class="special">(</span><span class="identifier">y</span><span class="special">)&gt;</span> <span class="identifier">interpolant</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">t</span><span class="special">),</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">y</span><span class="special">));</span>
</pre>
<p>
To evaluate the interpolant, use
</p>
<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">t</span> <span class="special">=</span> <span class="number">2.3</span><span class="special">;</span>
<span class="identifier">Eigen</span><span class="special">::</span><span class="identifier">Vector2d</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">interpolant</span><span class="special">(</span><span class="identifier">t</span><span class="special">);</span>
</pre>
<p>
If you want to populate a vector passed into the interpolant, rather than get
it returned, that syntax is supported:
</p>
<pre class="programlisting"><span class="identifier">Eigen</span><span class="special">::</span><span class="identifier">Vector2d</span> <span class="identifier">y</span><span class="special">;</span>
<span class="identifier">interpolant</span><span class="special">(</span><span class="identifier">y</span><span class="special">,</span> <span class="identifier">t</span><span class="special">);</span>
</pre>
<p>
We tested this with <code class="computeroutput"><span class="identifier">Eigen</span><span class="special">::</span><span class="identifier">Vector</span></code>s and found no performance benefit,
but other <code class="computeroutput"><span class="identifier">Point</span></code>-types might
not be the same.
</p>
<p>
To evaluate the derivative of the interpolant use
</p>
<pre class="programlisting"><span class="keyword">auto</span> <span class="special">[</span><span class="identifier">y</span><span class="special">,</span> <span class="identifier">y_prime</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">interpolant</span><span class="special">.</span><span class="identifier">eval_with_prime</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
</pre>
<p>
Computation of the derivative requires evaluation, so if you can try to use
both values at once.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
Daryle Walker and Xiaogang Zhang<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="barycentric.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../interpolation.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="catmull_rom.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>