add parametric equations for hypotrochoid

This commit is contained in:
2019-11-01 14:25:53 +01:00
parent f8b9cddfa6
commit 254fa75498
7 changed files with 199 additions and 12 deletions

View File

@@ -35,17 +35,18 @@
<h1>Source code for function</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>
<span class="sd">&quot;&quot;&quot;Mathematical functions.</span>
<span class="sd">&quot;&quot;&quot;Mathematical equations.</span>
<span class="sd">:Date: 2019-10-27</span>
<span class="sd">:Date: 2019-11-01</span>
<span class="sd">.. module:: function</span>
<span class="sd"> :platform: *nix, Windows</span>
<span class="sd"> :synopsis: Mathematical functions.</span>
<span class="sd"> :synopsis: Mathematical equations.</span>
<span class="sd">.. moduleauthor:: Daniel Weschke &lt;daniel.weschke@directbox.de&gt;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">from</span> <span class="nn">pylib.mathematics</span> <span class="k">import</span> <span class="n">lcm</span>
<div class="viewcode-block" id="sine_wave"><a class="viewcode-back" href="../function.html#function.sine_wave">[docs]</a><span class="k">def</span> <span class="nf">sine_wave</span><span class="p">(</span><span class="n">A</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">phi</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">D</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">degree</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sa">r</span><span class="sd">&quot;&quot;&quot;A sine wave or sinusoid is a mathematical curve that describes a</span>
@@ -64,6 +65,10 @@
<span class="sd"> :param degree: boolean to switch between radians and degree. If</span>
<span class="sd"> False phi is interpreted in radians and if True then phi is</span>
<span class="sd"> interpreted in degrees.</span>
<span class="sd"> :type degree: bool</span>
<span class="sd"> :results: sine wave function of spatial variable x and optional</span>
<span class="sd"> time t</span>
<span class="sd"> In general, the function is:</span>
@@ -124,6 +129,10 @@
<span class="sd"> :param degree: boolean to switch between radians and degree. If</span>
<span class="sd"> False phi is interpreted in radians and if True then phi is</span>
<span class="sd"> interpreted in degrees.</span>
<span class="sd"> :type degree: bool</span>
<span class="sd"> :results: sine wave function of spatial variable x and optional</span>
<span class="sd"> time t</span>
<span class="sd"> .. seealso::</span>
<span class="sd"> :meth:`function_sine_wave_degree`</span>
@@ -133,6 +142,59 @@
<span class="k">else</span><span class="p">:</span>
<span class="n">phi</span> <span class="o">=</span> <span class="n">phi</span> <span class="o">+</span> <span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">/</span><span class="mi">2</span>
<span class="k">return</span> <span class="n">sine_wave</span><span class="p">(</span><span class="n">A</span><span class="o">=</span><span class="n">A</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="n">k</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="n">f</span><span class="p">,</span> <span class="n">phi</span><span class="o">=</span><span class="n">phi</span><span class="p">,</span> <span class="n">D</span><span class="o">=</span><span class="n">D</span><span class="p">,</span> <span class="n">degree</span><span class="o">=</span><span class="n">degree</span><span class="p">)</span></div>
<span class="c1">#</span>
<span class="c1"># Parametric equations</span>
<span class="c1">#</span>
<div class="viewcode-block" id="hypotrochoid"><a class="viewcode-back" href="../function.html#function.hypotrochoid">[docs]</a><span class="k">def</span> <span class="nf">hypotrochoid</span><span class="p">(</span><span class="n">R</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
<span class="sa">r</span><span class="sd">&quot;&quot;&quot;Hypotrochoid</span>
<span class="sd"> A point is attached with a distance d from the center of a circle</span>
<span class="sd"> of radius r. The circle is rolling around the inside of a fixed</span>
<span class="sd"> circle of radius R.</span>
<span class="sd"> :param R: radius of the fixed exterior circle</span>
<span class="sd"> :type R: float</span>
<span class="sd"> :param r: radius of the rolling circle inside of the fixed circle</span>
<span class="sd"> :typre r: float</span>
<span class="sd"> :param d: distance from the center of the interior circle</span>
<span class="sd"> :type d: float</span>
<span class="sd"> :results: functions for x of theta and y of theta</span>
<span class="sd"> :rtype: tuple</span>
<span class="sd"> .. math::</span>
<span class="sd"> x(\theta) = (R - r)\cos\theta + d\cos\left(\frac{R-r}{r}\theta\right) \\</span>
<span class="sd"> y(\theta) = (R - r)\sin\theta - d\sin\left(\frac{R-r}{r}\theta\right) \\</span>
<span class="sd"> \theta = \left[0, 2\pi\frac{\mathrm{lcm}(r, R)}{R}\right]</span>
<span class="sd"> ::</span>
<span class="sd"> * * *</span>
<span class="sd"> * R *</span>
<span class="sd"> * *</span>
<span class="sd"> * * * *</span>
<span class="sd"> * * r **</span>
<span class="sd"> * * .... *</span>
<span class="sd"> * * d *</span>
<span class="sd"> * * **</span>
<span class="sd"> * * * *</span>
<span class="sd"> * *</span>
<span class="sd"> * *</span>
<span class="sd"> * * *</span>
<span class="sd"> &gt;&gt;&gt; x, y = hyotrochoid(20, 6, 6)[:1]</span>
<span class="sd"> &gt;&gt;&gt; x, y, theta_end = hyotrochoid(20, 6, 6)</span>
<span class="sd"> .. seealso::</span>
<span class="sd"> :meth:`mathematics.lcm`</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">x</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">theta</span><span class="p">:</span> <span class="p">(</span><span class="n">R</span><span class="o">-</span><span class="n">r</span><span class="p">)</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span> <span class="o">+</span> <span class="n">d</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">cos</span><span class="p">((</span><span class="n">R</span><span class="o">-</span><span class="n">r</span><span class="p">)</span><span class="o">/</span><span class="n">r</span> <span class="o">*</span> <span class="n">theta</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">theta</span><span class="p">:</span> <span class="p">(</span><span class="n">R</span><span class="o">-</span><span class="n">r</span><span class="p">)</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span> <span class="o">-</span> <span class="n">d</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">sin</span><span class="p">((</span><span class="n">R</span><span class="o">-</span><span class="n">r</span><span class="p">)</span><span class="o">/</span><span class="n">r</span> <span class="o">*</span> <span class="n">theta</span><span class="p">)</span>
<span class="n">theta_end</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span><span class="n">lcm</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">R</span><span class="p">)</span><span class="o">/</span><span class="n">R</span>
<span class="k">return</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">theta_end</span></div>
</pre></div>
</div>

View File

@@ -34,10 +34,10 @@
<div class="section" id="module-function">
<span id="function-module"></span><h1>function module<a class="headerlink" href="#module-function" title="Permalink to this headline"></a></h1>
<p>Mathematical functions.</p>
<p>Mathematical equations.</p>
<dl class="field-list simple">
<dt class="field-odd">Date</dt>
<dd class="field-odd"><p>2019-10-27</p>
<dd class="field-odd"><p>2019-11-01</p>
</dd>
</dl>
<span class="target" id="module-function"></span><dl class="function">
@@ -56,11 +56,15 @@ lags the cosine.</p>
<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> boolean to switch between radians and degree. If
<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>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
@@ -68,6 +72,59 @@ interpreted in degrees.</p></li>
</div>
</dd></dl>
<dl class="function">
<dt id="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/function.html#hypotrochoid"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#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</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="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">1</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">theta_end</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="mathematics.html#mathematics.lcm" title="mathematics.lcm"><code class="xref py py-meth docutils literal notranslate"><span class="pre">mathematics.lcm()</span></code></a></p>
</div>
</dd></dl>
<dl class="function">
<dt id="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/function.html#sine_wave"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#function.sine_wave" title="Permalink to this definition"></a></dt>
@@ -81,11 +138,15 @@ smooth periodic oscillation.</p>
<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> boolean to switch between radians and degree. If
<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>
</dl>
<p>In general, the function is:</p>
<div class="math notranslate nohighlight">

View File

@@ -173,6 +173,8 @@
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="time_of_day.html#time_of_day.hours_norm">hours_norm() (in module time_of_day)</a>
</li>
<li><a href="function.html#function.hypotrochoid">hypotrochoid() (in module function)</a>
</li>
</ul></td>
</tr></table>

Binary file not shown.

View File

@@ -79,7 +79,7 @@
<td></td>
<td>
<a href="function.html#module-function"><code class="xref">function</code></a> <em>(*nix, Windows)</em></td><td>
<em>Mathematical functions.</em></td></tr>
<em>Mathematical equations.</em></td></tr>
<tr class="pcap"><td></td><td>&#160;</td><td></td></tr>
<tr class="cap" id="cap-g"><td></td><td>
<strong>g</strong></td><td></td></tr>

File diff suppressed because one or more lines are too long

View File

@@ -1,16 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Mathematical functions.
"""Mathematical equations.
:Date: 2019-10-27
:Date: 2019-11-01
.. module:: function
:platform: *nix, Windows
:synopsis: Mathematical functions.
:synopsis: Mathematical equations.
.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
"""
import math
from pylib.mathematics import lcm
def sine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False):
r"""A sine wave or sinusoid is a mathematical curve that describes a
@@ -29,6 +30,10 @@ def sine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False):
:param degree: boolean to switch between radians and degree. If
False phi is interpreted in radians and if True then phi is
interpreted in degrees.
:type degree: bool
:results: sine wave function of spatial variable x and optional
time t
In general, the function is:
@@ -89,6 +94,10 @@ def cosine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False):
:param degree: boolean to switch between radians and degree. If
False phi is interpreted in radians and if True then phi is
interpreted in degrees.
:type degree: bool
:results: sine wave function of spatial variable x and optional
time t
.. seealso::
:meth:`function_sine_wave_degree`
@@ -98,3 +107,56 @@ def cosine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False):
else:
phi = phi + math.pi/2
return sine_wave(A=A, k=k, f=f, phi=phi, D=D, degree=degree)
#
# Parametric equations
#
def hypotrochoid(R, r, d):
r"""Hypotrochoid
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.
:param R: radius of the fixed exterior circle
:type R: float
:param r: radius of the rolling circle inside of the fixed circle
:typre r: float
:param d: distance from the center of the interior circle
:type d: float
:results: functions for x of theta and y of theta
:rtype: tuple
.. math::
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]
::
* * *
* R *
* *
* * * *
* * r **
* * .... *
* * d *
* * **
* * * *
* *
* *
* * *
>>> x, y = hyotrochoid(20, 6, 6)[:1]
>>> x, y, theta_end = hyotrochoid(20, 6, 6)
.. seealso::
:meth:`mathematics.lcm`
"""
x = lambda theta: (R-r)*math.cos(theta) + d*math.cos((R-r)/r * theta)
y = lambda theta: (R-r)*math.sin(theta) - d*math.sin((R-r)/r * theta)
theta_end = 2*math.pi*lcm(r, R)/R
return x, y, theta_end