Files
pylib/docs/build/html/pylib.function.html
Daniel Weschke 4fc4903dc2 change data, mathematics, function, geometry and geometry_plot_pylab. add data_step, data_step_std and helper. add an example and more documentation.
inside the data module rename read to read_columns add add new read function to read the whole file as string. add print_list function to print one element per line. add unique_list and unique_list_hashable to reduce the list into a unique list with same order. add find_last, str_between, str_to_list functions.

inside the mathematics module for vector add normalized creating a new object (normalize will change the object), isclose and iscloseto, change ang to round internal number. for matrix improve slicing and add transposed creating a new object (transpose will change object).

inside the function module add b_spline_basis, b_spline_curve_with_knots and b_spline_knots functions. add sample_hal_open and sample_half_open_seq. add circle and ellipse.

inside the geometry module change CS init from using lists to Directions and add new constructor CS.init_xzy using lists. rename Wireframe to Polyline. add classes B_spline_curve_with_knots, Ellipse, ArcCircle, ArcEllipse, ArcBSplineCurveWithKnots. add function sample_half_open to create a list of Points.

inside the geometry_plot_pylab module change the help text.

add step_and data data_step_std module to read a step file to list and draw the content.

add helper module with context manager and decorator timeit to meassure the time for a section or function.

add example for b_spline function.
2020-01-08 21:59:53 +01:00

684 lines
38 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>pylib.function module &#8212; pylib 2019.12.21 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="pylib.geometry module" href="pylib.geometry.html" />
<link rel="prev" title="pylib.drawblock module" href="pylib.drawblock.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-pylib.function">
<span id="pylib-function-module"></span><h1>pylib.function module<a class="headerlink" href="#module-pylib.function" title="Permalink to this headline"></a></h1>
<p>Mathematical equations.</p>
<dl class="field-list simple">
<dt class="field-odd">Date</dt>
<dd class="field-odd"><p>2019-11-15</p>
</dd>
</dl>
<span class="target" id="module-function"></span><p>Functions returns function to apply conditions.</p>
<dl class="function">
<dt id="pylib.function.b_spline_basis">
<code class="sig-name descname">b_spline_basis</code><span class="sig-paren">(</span><em class="sig-param">knots</em>, <em class="sig-param">knot_span</em>, <em class="sig-param">degree</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#b_spline_basis"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.b_spline_basis" title="Permalink to this definition"></a></dt>
<dd><p>Cox-de Boor algorithm / recursion formula.</p>
<p>Calculate the i-th B-spline basis function of degree p: N_{i,p}(u)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>knots</strong> (<em>list</em>) Knot vector U. m + 1 non-decreasing numbers / knots,
<span class="math notranslate nohighlight">\(u_0 &lt;= u_1 &lt;= u_2 &lt;= ... &lt;= u_m\)</span></p></li>
<li><p><strong>knot_span</strong> (<em>int</em>) i-th knot span</p></li>
<li><p><strong>degree</strong> (<em>int</em>) degree of B-spline basis function</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>B-spline basis function using variable, u in [u_0, u_m]</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>function</p>
</dd>
</dl>
<div class="math notranslate nohighlight">
\[\begin{split}N_{i,0}(u) &amp;= \begin{cases} 1 &amp; \text{if } u_i \le u \lt u_{i+1} \\
0 &amp; \text{otherwise}\end{cases} \\
N_{i,p}(u) &amp;= \frac{u - u_i}{u_{i+p} - u_i} N_{i,p-1}(u) +
\frac{u_{i+p+1} - u}{u_{i+p+1} - u_{i+1}} N_{i+1,p-1}(u)\end{split}\]</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.b_spline_curve_with_knots">
<code class="sig-name descname">b_spline_curve_with_knots</code><span class="sig-paren">(</span><em class="sig-param">degree</em>, <em class="sig-param">control_points</em>, <em class="sig-param">knots</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#b_spline_curve_with_knots"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.b_spline_curve_with_knots" title="Permalink to this definition"></a></dt>
<dd><p>B-spline curve of degree p (order + 1) on a given set of knots.</p>
<p>n, m and p must satisfy m = n + p + 1.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>degree</strong> (<em>int</em>) degree of B-spline basis functions</p></li>
<li><p><strong>control_points</strong> (<em>list</em>) control points P, n + 1 control points</p></li>
<li><p><strong>knots</strong> (<em>list</em>) Knot vector U. m + 1 non-decreasing numbers / knots,
<span class="math notranslate nohighlight">\(u_0 &lt;= u_1 &lt;= u_2 &lt;= ... &lt;= u_m\)</span></p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>B-spline curve using variable, u in [u_0, u_m]</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>function</p>
</dd>
</dl>
<div class="math notranslate nohighlight">
\[\mathbf{C}_p(u) = \sum\limits_{i=0}^{n} N_{i,p}(u) \mathbf{P}_i\]</div>
<ul class="simple">
<li><p>open B-spline curves</p>
<ul>
<li><p>the curve will not touch the first and last legs of the
control polyline</p></li>
<li><p>the knot vector does not have any particular structure</p></li>
<li><p>for degree p, intervals [u_0, u_p) and [u_{n-p}, u_n) will not
have “full support” of basis functions and are ignored when a
B-spline curve is open. For open B-spline curves, the domain
is inteval [u_p, u_{n-p}]</p></li>
</ul>
</li>
<li><p>clamped B-spline curves, nonperiodic B-spline curves</p>
<ul>
<li><p>the curve is tangent to the first and the last legs just like
a Bézier curve</p></li>
<li><p>the first knot and the last knot must be repeated p+1 times
(i. e., of multiplicity p+1)</p></li>
</ul>
</li>
<li><p>closed B-spline curves</p>
<ul>
<li><p>the start and the end of the generated curve join together
forming a closed loop</p></li>
<li><p>repeating some knots and control points # TODO: which?</p></li>
</ul>
</li>
<li><p>uniform B-spline curves</p>
<ul>
<li><p>internal knots are equally spaced</p></li>
</ul>
</li>
<li><p>Bézier curves</p>
<ul>
<li><p>a B-spline with no internal knots.</p></li>
</ul>
</li>
</ul>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#pylib.function.b_spline_knots" title="pylib.function.b_spline_knots"><code class="xref py py-meth docutils literal notranslate"><span class="pre">b_spline_knots()</span></code></a></p>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.b_spline_knots">
<code class="sig-name descname">b_spline_knots</code><span class="sig-paren">(</span><em class="sig-param">control_point_spans</em>, <em class="sig-param">degree=3</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#b_spline_knots"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.b_spline_knots" title="Permalink to this definition"></a></dt>
<dd><p>B-spline knots to generate a clamped uniform B-spline curve
of degree p (order + 1).</p>
<p>The internal knots are equally spaced (uniform B-spline curve)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>control_point_spans</strong> (<em>int</em>) number of control points + 1</p></li>
<li><p><strong>degree</strong> (<em>int</em>) degree of B-spline basis functions (default = 3)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>knot vector</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>tuple</p>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#pylib.function.b_spline_curve_with_knots" title="pylib.function.b_spline_curve_with_knots"><code class="xref py py-meth docutils literal notranslate"><span class="pre">b_spline_curve_with_knots()</span></code></a></p>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.circle">
<code class="sig-name descname">circle</code><span class="sig-paren">(</span><em class="sig-param">r</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#circle"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.circle" title="Permalink to this definition"></a></dt>
<dd><p>Circle</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>r</strong> (<em>float</em>) radius of the circle</p>
</dd>
<dt class="field-even">Results</dt>
<dd class="field-even"><p>functions for x of theta and y of theta and the interval</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>tuple</p>
</dd>
</dl>
<div class="math notranslate nohighlight">
\[\begin{split}x(\theta) = r\cos\theta \\
y(\theta) = r\sin\theta \\
\theta = \left[0, 2\pi\right]\end{split}\]</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="n">r</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">circle</span><span class="p">(</span><span class="mi">20</span><span class="p">)[:</span><span class="mi">2</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">circle</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">interval</span> <span class="o">=</span> <span class="n">circle</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.cosine_wave">
<code class="sig-name descname">cosine_wave</code><span class="sig-paren">(</span><em class="sig-param">A=1</em>, <em class="sig-param">k=1</em>, <em class="sig-param">f=1</em>, <em class="sig-param">phi=0</em>, <em class="sig-param">D=0</em>, <em class="sig-param">degree=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#cosine_wave"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.cosine_wave" title="Permalink to this definition"></a></dt>
<dd><p>A cosine wave is said to be sinusoidal, because,
<span class="math notranslate nohighlight">\(\cos(x) = \sin(x + \pi/2)\)</span>, which is also a sine wave with a
phase-shift of π/2 radians. Because of this head start, it is often
said that the cosine function leads the sine function or the sine
lags the cosine.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>A</strong> (<em>float</em><em> or </em><em>int</em>) amplitude</p></li>
<li><p><strong>k</strong> (<em>float</em><em> or </em><em>int</em>) (angular) wave number</p></li>
<li><p><strong>f</strong> (<em>float</em><em> or </em><em>int</em>) ordinary frequency</p></li>
<li><p><strong>phi</strong> (<em>float</em><em> or </em><em>int</em>) phase</p></li>
<li><p><strong>D</strong> (<em>float</em><em> or </em><em>int</em>) non-zero center amplitude</p></li>
<li><p><strong>degree</strong> (<em>bool</em>) boolean to switch between radians and degree. If
False phi is interpreted in radians and if True then phi is
interpreted in degrees.</p></li>
</ul>
</dd>
<dt class="field-even">Results</dt>
<dd class="field-even"><p>sine wave function of spatial variable x and optional
time t</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>function</p>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#pylib.function.sine_wave" title="pylib.function.sine_wave"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sine_wave()</span></code></a></p>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.ellipse">
<code class="sig-name descname">ellipse</code><span class="sig-paren">(</span><em class="sig-param">a</em>, <em class="sig-param">b</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#ellipse"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.ellipse" title="Permalink to this definition"></a></dt>
<dd><p>Ellipse</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>a</strong> (<em>float</em>) semi-major axis</p></li>
<li><p><strong>b</strong> (<em>float</em>) semi-minor axis</p></li>
</ul>
</dd>
<dt class="field-even">Results</dt>
<dd class="field-even"><p>functions for x of theta and y of theta and the interval</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>tuple</p>
</dd>
</dl>
<div class="math notranslate nohighlight">
\[\begin{split}x(\theta) = a\cos\theta \\
y(\theta) = b\sin\theta \\
\theta = \left[0, 2\pi\right]\end{split}\]</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="o">*</span> <span class="o">.*</span>
<span class="o">*</span> <span class="n">b</span> <span class="p">:</span> <span class="o">*</span>
<span class="o">*</span> <span class="p">:</span><span class="o">......*</span>
<span class="o">*</span> <span class="n">a</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">ellipse</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">)[:</span><span class="mi">2</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">ellipse</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">interval</span> <span class="o">=</span> <span class="n">ellipse</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.epitrochoid">
<code class="sig-name descname">epitrochoid</code><span class="sig-paren">(</span><em class="sig-param">R</em>, <em class="sig-param">r</em>, <em class="sig-param">d</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#epitrochoid"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.epitrochoid" title="Permalink to this definition"></a></dt>
<dd><p>Epitrochoid</p>
<p>A point is attached with a distance d from the center of a circle
of radius r. The circle is rolling around the outside of a fixed
circle of radius R.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>R</strong> (<em>float</em>) radius of the fixed interior circle</p></li>
<li><p><strong>r</strong> radius of the rolling circle outside of the fixed circle</p></li>
<li><p><strong>d</strong> (<em>float</em>) distance from the center of the exterior circle</p></li>
</ul>
</dd>
<dt class="field-even">Typre r</dt>
<dd class="field-even"><p>float</p>
</dd>
<dt class="field-odd">Results</dt>
<dd class="field-odd"><p>functions for x of theta and y of theta and the interval</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>tuple</p>
</dd>
</dl>
<div class="math notranslate nohighlight">
\[\begin{split}x(\theta) = (R + r)\cos\theta - d\cos\left(\frac{R+r}{r}\theta\right) \\
y(\theta) = (R + r)\sin\theta - d\sin\left(\frac{R+r}{r}\theta\right) \\
\theta = \left[0, 2\pi\right]\end{split}\]</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="n">R</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">*</span> <span class="n">r</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">**</span> <span class="o">..</span><span class="p">,</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">**</span> <span class="n">d</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">epitrochoid</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)[:</span><span class="mi">2</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">epitrochoid</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">interval</span> <span class="o">=</span> <span class="n">epitrochoid</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.hypotrochoid">
<code class="sig-name descname">hypotrochoid</code><span class="sig-paren">(</span><em class="sig-param">R</em>, <em class="sig-param">r</em>, <em class="sig-param">d</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#hypotrochoid"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.hypotrochoid" title="Permalink to this definition"></a></dt>
<dd><p>Hypotrochoid</p>
<p>A point is attached with a distance d from the center of a circle
of radius r. The circle is rolling around the inside of a fixed
circle of radius R.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>R</strong> (<em>float</em>) radius of the fixed exterior circle</p></li>
<li><p><strong>r</strong> radius of the rolling circle inside of the fixed circle</p></li>
<li><p><strong>d</strong> (<em>float</em>) distance from the center of the interior circle</p></li>
</ul>
</dd>
<dt class="field-even">Typre r</dt>
<dd class="field-even"><p>float</p>
</dd>
<dt class="field-odd">Results</dt>
<dd class="field-odd"><p>functions for x of theta and y of theta and the interval</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>tuple</p>
</dd>
</dl>
<div class="math notranslate nohighlight">
\[\begin{split}x(\theta) = (R - r)\cos\theta + d\cos\left(\frac{R-r}{r}\theta\right) \\
y(\theta) = (R - r)\sin\theta - d\sin\left(\frac{R-r}{r}\theta\right) \\
\theta = \left[0, 2\pi\frac{\mathrm{lcm}(r, R)}{R}\right]\end{split}\]</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> <span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="n">R</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="n">r</span> <span class="o">**</span>
<span class="o">*</span> <span class="o">*</span> <span class="p">,</span><span class="o">..</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="n">d</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">**</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span>
<span class="o">*</span> <span class="o">*</span> <span class="o">*</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">hyotrochoid</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">)[:</span><span class="mi">2</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">hyotrochoid</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">interval</span> <span class="o">=</span> <span class="n">hyotrochoid</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="pylib.mathematics.html#pylib.mathematics.lcm" title="pylib.mathematics.lcm"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pylib.mathematics.lcm()</span></code></a></p>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.sample_half_open">
<code class="sig-name descname">sample_half_open</code><span class="sig-paren">(</span><em class="sig-param">f</em>, <em class="sig-param">a</em>, <em class="sig-param">b</em>, <em class="sig-param">n=50</em>, <em class="sig-param">endpoint_epsilon=1e-07</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#sample_half_open"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.sample_half_open" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="pylib.function.sample_half_open_seq">
<code class="sig-name descname">sample_half_open_seq</code><span class="sig-paren">(</span><em class="sig-param">f</em>, <em class="sig-param">x</em>, <em class="sig-param">endpoint_epsilon=1e-07</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#sample_half_open_seq"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.sample_half_open_seq" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="pylib.function.sine_wave">
<code class="sig-name descname">sine_wave</code><span class="sig-paren">(</span><em class="sig-param">A=1</em>, <em class="sig-param">k=1</em>, <em class="sig-param">f=1</em>, <em class="sig-param">phi=0</em>, <em class="sig-param">D=0</em>, <em class="sig-param">degree=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#sine_wave"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.sine_wave" title="Permalink to this definition"></a></dt>
<dd><p>A sine wave or sinusoid is a mathematical curve that describes a
smooth periodic oscillation.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>A</strong> (<em>float</em><em> or </em><em>int</em>) amplitude</p></li>
<li><p><strong>k</strong> (<em>float</em><em> or </em><em>int</em>) (angular) wave number</p></li>
<li><p><strong>f</strong> (<em>float</em><em> or </em><em>int</em>) ordinary frequency</p></li>
<li><p><strong>phi</strong> (<em>float</em><em> or </em><em>int</em>) phase</p></li>
<li><p><strong>D</strong> (<em>float</em><em> or </em><em>int</em>) non-zero center amplitude</p></li>
<li><p><strong>degree</strong> (<em>bool</em>) boolean to switch between radians and degree. If
False phi is interpreted in radians and if True then phi is
interpreted in degrees.</p></li>
</ul>
</dd>
<dt class="field-even">Results</dt>
<dd class="field-even"><p>sine wave function of spatial variable x and optional
time t</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>function</p>
</dd>
</dl>
<p>In general, the function is:</p>
<div class="math notranslate nohighlight">
\[\begin{split}y(x,t) = A\sin(kx + \omega t + \varphi) + D \\
y(x,t) = A\sin(kx + 2\pi f t + \varphi) + D\end{split}\]</div>
<p>where:</p>
<blockquote>
<div><ul class="simple">
<li><p>A, amplitude, the peak deviation of the function from zero.</p></li>
<li><p>f, ordinary frequency, the number of oscillations (cycles) that
occur each second of time.</p></li>
<li><p>ω = 2πf, angular frequency, the rate of change of the function
argument in units of radians per second. If ω &lt; 0 the wave is
moving to the right, if ω &gt; 0 the wave is moving to the left.</p></li>
<li><p>φ, phase, specifies (in radians) where in its cycle the
oscillation is at t = 0.</p></li>
<li><p>x, spatial variable that represents the position on the
dimension on which the wave propagates.</p></li>
<li><p>k, characteristic parameter called wave number (or angular wave
number), which represents the proportionality between the
angular frequency ω and the linear speed (speed of propagation)
ν.</p></li>
<li><p>D, non-zero center amplitude.</p></li>
</ul>
</div></blockquote>
<p>The wavenumber is related to the angular frequency by:</p>
<div class="math notranslate nohighlight">
\[k={\omega \over v}={2\pi f \over v}={2\pi \over \lambda }\]</div>
<p>where λ (lambda) is the wavelength, f is the frequency, and v is the
linear speed.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#pylib.function.cosine_wave" title="pylib.function.cosine_wave"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cosine_wave()</span></code></a></p>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.to_str">
<code class="sig-name descname">to_str</code><span class="sig-paren">(</span><em class="sig-param">f</em>, <em class="sig-param">x=None</em>, <em class="sig-param">x_0=0</em>, <em class="sig-param">x_1=1</em>, <em class="sig-param">t=None</em>, <em class="sig-param">h=10</em>, <em class="sig-param">w=80</em>, <em class="sig-param">density=1</em>, <em class="sig-param">char_set='line'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#to_str"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.to_str" title="Permalink to this definition"></a></dt>
<dd><p>Represent functions as string frame with a specific character set.
which are normed to the range of [0, 1] to</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>f</strong> (<em>function</em><em> or </em><em>list</em>) function or list of functions normed to the range of [0, 1]</p></li>
<li><p><strong>h</strong> (<em>int</em>) number of chars in vertical direction</p></li>
<li><p><strong>w</strong> (<em>int</em>) number of chars in horizontal direction</p></li>
<li><p><strong>char_set</strong> (<em>str</em>) either “braille” or “block”. “braille” uses Unicode
Characters in the Braille Patterns Block (first index U+2800, last
index U+28FF <a class="reference internal" href="#cudb" id="id1"><span>[CUDB]</span></a>) and the “block” uses part of the Unicode
Characters in the Block Elements Block (fisrt index U+2580, last
index U+259F <a class="reference internal" href="#cudb" id="id2"><span>[CUDB]</span></a>). Alias for braille is line and alias for
block is histogram</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Usage:</dt><dd><ul class="simple">
<li><p>case dependent arguments</p>
<ul>
<li><p>1 quasi line plot (braille characters)
f = lambda function (lambda x, t=0: …)
x_1 = max x value
x_0 = min x value
t = time (animation)</p></li>
<li><p>2 histogram (block characters)
f = lambda function (lambda x, t=0: …)
x_1 = max x value
x_0 = min x value
t = time (animation)
chart=”histogram”</p></li>
</ul>
</li>
<li><p>general arguments
w = window width in number of chars
density = number of data point per pixel (for line chart higher density makes thicker lines)
chart = either “line” or “histogram”</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Braille Patterns Block</p>
<ul class="simple">
<li><p>Dots or pixels per character in vertical direction: 6</p></li>
<li><p>Dots or pixels per character in horizontal direction: 2</p></li>
</ul>
<p>First dot (bottom left) is the zero (0) position of the
function. So, a function value of zero does not mean to have zero
dots but one.
Example of 3 columns and 3 rows (upside down view of normal braille/drawille position)</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> | ^ y axis
| |
| ,_____,,_____,,_____,
7 + | * *|| * *|| * *|
6 + | * *|| * *|| * *|
5 + | * *|| * *|| * *|
4 + | * *|| * *|| * *|
| ;=====;;=====;;=====;
3 + | * *|| * *|| * *|
2 + | * *|| * *|| * *|
1 + | * *|| * *|| * *|
0 + - | * *|| * *|| * *| ---&gt; x axis
| ;=====;;=====;;=====;
-1 + | * *|| * *|| * *|
-2 + | * *|| * *|| * *|
-3 + | * *|| * *|| * *|
-4 + | * *|| * *|| * *|
| `````````````````````
| |
`-----+--+---+--+---+--+-------------
-2 -1 0 1 2 3
</pre></div>
</div>
<p class="rubric">Block Elements Block</p>
<ul class="simple">
<li><p>Dots or pixels per character in vertical direction: 8</p></li>
<li><p>Dots or pixels per character in horizontal direction: 1</p></li>
</ul>
<p>Example of 3 columns and 3 rows</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> | ^ y axis
| |
| ,_____,,_____,,_____,
15 + | --- || --- || --- |
14 + | --- || --- || --- |
13 + | --- || --- || --- |
12 + | --- || --- || --- |
11 + | --- || --- || --- |
10 + | --- || --- || --- |
9 + | --- || --- || --- |
8 + | --- || --- || --- |
| ;=====;;=====;;=====;
7 + | --- || --- || --- |
6 + | --- || --- || --- |
5 + | --- || --- || --- |
4 + | --- || --- || --- |
3 + | --- || --- || --- |
2 + | --- || --- || --- |
1 + | --- || --- || --- |
0 + - | --- || --- || --- | ---&gt; x axis
| ;=====;;=====;;=====;
-1 + | --- || --- || --- |
-2 + | --- || --- || --- |
-3 + | --- || --- || --- |
-4 + | --- || --- || --- |
-5 + | --- || --- || --- |
-6 + | --- || --- || --- |
-7 + | --- || --- || --- |
-8 + | --- || --- || --- |
| `````````````````````
| |
`------+------+------+---------------
-1 0 1
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="cudb"><span class="brackets">CUDB</span><span class="fn-backref">(<a href="#id1">1</a>,<a href="#id2">2</a>)</span></dt>
<dd><p><a class="reference external" href="ftp://ftp.unicode.org/Public/UNIDATA/Blocks.txt">Unicode Database - Blocks</a></p>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#pylib.function.transformation" title="pylib.function.transformation"><code class="xref py py-meth docutils literal notranslate"><span class="pre">transformation()</span></code></a></p>
</div>
</dd></dl>
<dl class="function">
<dt id="pylib.function.transformation">
<code class="sig-name descname">transformation</code><span class="sig-paren">(</span><em class="sig-param">f</em>, <em class="sig-param">scale_vertical=1</em>, <em class="sig-param">scale_horizontal=1</em>, <em class="sig-param">shift_horizontal=0</em>, <em class="sig-param">shift_vertical=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/function.html#transformation"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.function.transformation" title="Permalink to this definition"></a></dt>
<dd><p>Transform functions.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>f</strong> (<em>function</em><em> or </em><em>list</em>) function or list of functions</p></li>
<li><p><strong>scale_vertical</strong> “a” scale factor in vertical direction (default
= 1)</p></li>
<li><p><strong>scale_horizontal</strong> “b” scale factor in horizontal direction
(default = 1)</p></li>
<li><p><strong>shift_horizontal</strong> “c” shift factor in horizontal direction
(default = 0)</p></li>
<li><p><strong>shift_vertical</strong> “d” shift factor in vertical direction (default
= 0)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>transformed function or list of transformed functions</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>function or list</p>
</dd>
</dl>
<div class="math notranslate nohighlight">
\[y = a \, f(b\,(x-c)) + d\]</div>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html">pylib</a></h1>
<h3>Navigation</h3>
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">pylib</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="pylib.html">pylib package</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li><a href="modules.html">pylib</a><ul>
<li><a href="pylib.html">pylib package</a><ul>
<li>Previous: <a href="pylib.drawblock.html" title="previous chapter">pylib.drawblock module</a></li>
<li>Next: <a href="pylib.geometry.html" title="next chapter">pylib.geometry module</a></li>
</ul></li>
</ul></li>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2019, Daniel Weschke.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 2.2.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
<a href="_sources/pylib.function.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>