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.
This commit is contained in:
2020-01-08 21:59:53 +01:00
parent 4b42d7b508
commit 4fc4903dc2
56 changed files with 8756 additions and 947 deletions

View File

@@ -17,7 +17,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="pylib.time_of_day module" href="pylib.time_of_day.html" />
<link rel="prev" title="pylib.geometry_plot_pylab module" href="pylib.geometry_plot_pylab.html" />
<link rel="prev" title="pylib.helper module" href="pylib.helper.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
@@ -62,8 +62,16 @@
<dd class="field-odd"><p></p></dd>
</dl>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">[:])</span>
<span class="go">[[1, 2, 3, 0], [4, 5, 6, 0], [7, 8, 9, 0], [0, 0, 0, 0]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="go">[7, 8, 9, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:])</span>
<span class="go">[7, 8, 9, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">[:,</span> <span class="mi">2</span><span class="p">])</span>
<span class="go">[3, 6, 9, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="go">9</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">:</span><span class="mi">3</span><span class="p">])</span>
<span class="go">[[2, 3], [5, 6], [8, 9], [0, 0]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span><span class="mi">3</span><span class="p">])</span>
@@ -160,6 +168,12 @@ for wrong usage (result will be nonsense).</p>
</div>
</dd></dl>
<dl class="method">
<dt id="pylib.mathematics.matrix.__setitem__">
<code class="sig-name descname">__setitem__</code><span class="sig-paren">(</span><em class="sig-param">index</em>, <em class="sig-param">value</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#matrix.__setitem__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.matrix.__setitem__" title="Permalink to this definition"></a></dt>
<dd><p>Set self[key] to value.</p>
</dd></dl>
<dl class="method">
<dt id="pylib.mathematics.matrix.__str__">
<code class="sig-name descname">__str__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#matrix.__str__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.matrix.__str__" title="Permalink to this definition"></a></dt>
@@ -400,6 +414,39 @@ where it should be.</p>
\end{bmatrix}\end{split}\]</div>
</dd></dl>
<dl class="method">
<dt id="pylib.mathematics.matrix.transpose">
<code class="sig-name descname">transpose</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#matrix.transpose"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.matrix.transpose" title="Permalink to this definition"></a></dt>
<dd><p>Transpose</p>
</dd></dl>
<dl class="method">
<dt id="pylib.mathematics.matrix.transposed">
<em class="property">static </em><code class="sig-name descname">transposed</code><span class="sig-paren">(</span><em class="sig-param">a</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#matrix.transposed"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.matrix.transposed" title="Permalink to this definition"></a></dt>
<dd><p>Transpose</p>
</dd></dl>
<dl class="method">
<dt id="pylib.mathematics.matrix.zeros">
<em class="property">static </em><code class="sig-name descname">zeros</code><span class="sig-paren">(</span><em class="sig-param">m</em>, <em class="sig-param">n</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#matrix.zeros"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.matrix.zeros" title="Permalink to this definition"></a></dt>
<dd><p>Returns a zero matrix of size mxn; m rows and n columns
filled with zeros.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>m</strong> (<em>int</em>) number of rows of the matrix, e. g. 3</p></li>
<li><p><strong>n</strong> (<em>int</em>) number of columns of the matrix, e. g. 3</p></li>
</ul>
</dd>
<dt class="field-even">Example</dt>
<dd class="field-even"><p></p></dd>
</dl>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">matrix</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> <span class="p">[[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">]]</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
<dl class="class">
@@ -848,13 +895,12 @@ The direction of c can be found with the right-hand rule.</p>
<dl class="method">
<dt id="pylib.mathematics.vector.full">
<em class="property">static </em><code class="sig-name descname">full</code><span class="sig-paren">(</span><em class="sig-param">length</em>, <em class="sig-param">fill_value</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.full"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.full" title="Permalink to this definition"></a></dt>
<dd><p>Returns a vector of length m or matrix of size m rows, n
columns filled with v.</p>
<dd><p>Returns a vector of length m filled with v.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>length</strong> (<em>int</em>) length of the vector, e. g. 3</p></li>
<li><p><strong>fill_value</strong> Fill value</p></li>
<li><p><strong>fill_value</strong> fill value</p></li>
</ul>
</dd>
<dt class="field-even">Type fill_value</dt>
@@ -878,9 +924,33 @@ columns filled with v.</p>
</dl>
</dd></dl>
<dl class="method">
<dt id="pylib.mathematics.vector.isclose">
<em class="property">static </em><code class="sig-name descname">isclose</code><span class="sig-paren">(</span><em class="sig-param">a</em>, <em class="sig-param">b</em>, <em class="sig-param">rel_tol=0.05</em>, <em class="sig-param">abs_tol=1e-08</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.isclose"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.isclose" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="method">
<dt id="pylib.mathematics.vector.iscloseto">
<code class="sig-name descname">iscloseto</code><span class="sig-paren">(</span><em class="sig-param">other</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.iscloseto"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.iscloseto" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="method">
<dt id="pylib.mathematics.vector.normalize">
<em class="property">static </em><code class="sig-name descname">normalize</code><span class="sig-paren">(</span><em class="sig-param">a</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.normalize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.normalize" title="Permalink to this definition"></a></dt>
<code class="sig-name descname">normalize</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.normalize"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.normalize" title="Permalink to this definition"></a></dt>
<dd><p>Normalize a vector (i. e. the vector has a length of 1)</p>
<dl class="field-list simple">
</dl>
<div class="math notranslate nohighlight">
\[\mathbf{\hat{a}} = \frac{\mathbf{a}}{|\mathbf{a}|}\]</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#pylib.mathematics.vector.__abs__" title="pylib.mathematics.vector.__abs__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__abs__()</span></code></a> for a norm (magnitude) of a vector</p>
</div>
</dd></dl>
<dl class="method">
<dt id="pylib.mathematics.vector.normalized">
<em class="property">static </em><code class="sig-name descname">normalized</code><span class="sig-paren">(</span><em class="sig-param">a</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.normalized"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.normalized" title="Permalink to this definition"></a></dt>
<dd><p>Normalize a vector (i. e. the vector has a length of 1)</p>
<dl class="field-list simple">
</dl>
@@ -895,8 +965,7 @@ columns filled with v.</p>
<dl class="method">
<dt id="pylib.mathematics.vector.ones">
<em class="property">static </em><code class="sig-name descname">ones</code><span class="sig-paren">(</span><em class="sig-param">length</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.ones"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.ones" title="Permalink to this definition"></a></dt>
<dd><p>Returns a vector of length m or matrix of size rows, n
columns filled with ones.</p>
<dd><p>Returns a vector of length m filled with ones.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>length</strong> (<em>int</em>) lhape of the vector, e. g. 3</p>
@@ -904,7 +973,7 @@ columns filled with ones.</p>
<dt class="field-even">Example</dt>
<dd class="field-even"><p></p></dd>
</dl>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">ones</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">vector</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">[1.0, 1.0, 1.0]</span>
</pre></div>
@@ -913,17 +982,20 @@ columns filled with ones.</p>
<dl class="method">
<dt id="pylib.mathematics.vector.random">
<em class="property">static </em><code class="sig-name descname">random</code><span class="sig-paren">(</span><em class="sig-param">shape</em>, <em class="sig-param">lmin=0.0</em>, <em class="sig-param">lmax=1.0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.random"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.random" title="Permalink to this definition"></a></dt>
<dd><p>Returns a random vector of length n or matrix of size m rows,
n columns filled with random numbers.</p>
<em class="property">static </em><code class="sig-name descname">random</code><span class="sig-paren">(</span><em class="sig-param">length</em>, <em class="sig-param">lmin=0.0</em>, <em class="sig-param">lmax=1.0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.random"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.random" title="Permalink to this definition"></a></dt>
<dd><p>Returns a random vector of length n filled with random
numbers.</p>
<dl class="field-list simple">
<dt class="field-odd">Example</dt>
<dd class="field-odd"><p></p></dd>
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>length</strong> (<em>int</em>) lhape of the vector, e. g. 3</p>
</dd>
<dt class="field-even">Example</dt>
<dd class="field-even"><p></p></dd>
</dl>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">vector</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">[0.9172905912930438, 0.8908124278322492, 0.5256002790725927]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">random</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="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">vector</span><span class="o">.</span><span class="n">random</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="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">[1.2563665665080803, 1.9270454509964547, 1.2381672401270487]</span>
</pre></div>
@@ -1022,8 +1094,7 @@ where it should be.</p>
<dl class="method">
<dt id="pylib.mathematics.vector.zeros">
<em class="property">static </em><code class="sig-name descname">zeros</code><span class="sig-paren">(</span><em class="sig-param">length</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pylib/mathematics.html#vector.zeros"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pylib.mathematics.vector.zeros" title="Permalink to this definition"></a></dt>
<dd><p>Returns a zero vector of length m or matrix of size rows, n
columns filled with zeros.</p>
<dd><p>Returns a zero vector of length m filled with zeros.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>length</strong> (<em>int</em>) length of the vector, e. g. 3</p>
@@ -1031,7 +1102,7 @@ columns filled with zeros.</p>
<dt class="field-even">Example</dt>
<dd class="field-even"><p></p></dd>
</dl>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">v</span> <span class="o">=</span> <span class="n">vector</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="go">[0.0, 0.0, 0.0]</span>
</pre></div>
@@ -1073,7 +1144,7 @@ columns filled with zeros.</p>
<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.geometry_plot_pylab.html" title="previous chapter">pylib.geometry_plot_pylab module</a></li>
<li>Previous: <a href="pylib.helper.html" title="previous chapter">pylib.helper module</a></li>
<li>Next: <a href="pylib.time_of_day.html" title="next chapter">pylib.time_of_day module</a></li>
</ul></li>
</ul></li>