From 95a289be7520200d8f09da38d9c83fe9f6cad436 Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Sat, 21 Dec 2019 12:51:34 +0100 Subject: [PATCH] move geometry to geometry2d and add new geometry module (3d) --- docs/build/html/.buildinfo | 2 +- docs/build/html/_modules/data.html | 305 --- docs/build/html/_modules/date.html | 221 -- docs/build/html/_modules/function.html | 516 ----- docs/build/html/_modules/geometry_plot.html | 185 -- docs/build/html/_modules/index.html | 22 +- docs/build/html/_modules/mathematics.html | 1025 --------- docs/build/html/_modules/numerical/fit.html | 196 -- .../html/_modules/numerical/integration.html | 250 --- docs/build/html/_modules/numerical/ode.html | 540 ----- .../html/_modules/numerical/ode_model.html | 219 -- docs/build/html/_modules/pylib/data.html | 22 +- docs/build/html/_modules/pylib/date.html | 18 +- docs/build/html/_modules/pylib/drawblock.html | 25 +- docs/build/html/_modules/pylib/function.html | 18 +- docs/build/html/_modules/pylib/geometry.html | 686 ++---- .../{geometry.html => pylib/geometry2d.html} | 72 +- ...eometry_plot.html => geometry2d_plot.html} | 19 +- .../html/_modules/pylib/mathematics.html | 70 +- .../html/_modules/pylib/numerical/fit.html | 10 +- .../_modules/pylib/numerical/integration.html | 8 +- .../html/_modules/pylib/numerical/ode.html | 20 +- .../_modules/pylib/numerical/ode_model.html | 12 +- .../html/_modules/pylib/time_of_day.html | 26 +- docs/build/html/_modules/time_of_day.html | 253 --- docs/build/html/_sources/data.rst.txt | 7 - docs/build/html/_sources/date.rst.txt | 7 - docs/build/html/_sources/function.rst.txt | 7 - docs/build/html/_sources/geometry.rst.txt | 7 - docs/build/html/_sources/index.rst.txt | 2 + docs/build/html/_sources/mathematics.rst.txt | 7 - docs/build/html/_sources/numerical.rst.txt | 46 - docs/build/html/_sources/pylib.data.rst.txt | 7 + docs/build/html/_sources/pylib.date.rst.txt | 7 + .../html/_sources/pylib.drawblock.rst.txt | 7 + ...ry_plot.rst.txt => pylib.function.rst.txt} | 4 +- .../html/_sources/pylib.geometry.rst.txt} | 4 +- .../html/_sources/pylib.geometry2d.rst.txt | 7 + .../_sources/pylib.geometry2d_plot.rst.txt | 7 + .../html/_sources/pylib.mathematics.rst.txt | 7 + .../html/_sources/pylib.numerical.fit.rst.txt | 7 + .../pylib.numerical.integration.rst.txt | 7 + .../html/_sources/pylib.numerical.ode.rst.txt | 7 + .../pylib.numerical.ode_model.rst.txt | 7 + .../html/_sources/pylib.numerical.rst.txt | 49 +- docs/build/html/_sources/pylib.rst.txt | 86 +- .../html/_sources/pylib.time_of_day.rst.txt | 7 + docs/build/html/_sources/time_of_day.rst.txt | 7 - .../html/_static/documentation_options.js | 2 +- docs/build/html/genindex.html | 606 ++---- docs/build/html/index.html | 15 +- docs/build/html/modules.html | 40 +- docs/build/html/numerical.html | 589 ----- docs/build/html/objects.inv | Bin 1531 -> 1421 bytes docs/build/html/py-modindex.html | 127 +- .../build/html/{data.html => pylib.data.html} | 55 +- .../build/html/{date.html => pylib.date.html} | 47 +- docs/build/html/pylib.drawblock.html | 145 ++ .../{function.html => pylib.function.html} | 59 +- docs/build/html/pylib.geometry.html | 307 +++ .../{geometry.html => pylib.geometry2d.html} | 101 +- ...y_plot.html => pylib.geometry2d_plot.html} | 33 +- docs/build/html/pylib.html | 1909 +---------------- ...athematics.html => pylib.mathematics.html} | 151 +- docs/build/html/pylib.numerical.fit.html | 189 ++ docs/build/html/pylib.numerical.html | 507 +---- .../html/pylib.numerical.integration.html | 205 ++ docs/build/html/pylib.numerical.ode.html | 357 +++ .../build/html/pylib.numerical.ode_model.html | 194 ++ ...ime_of_day.html => pylib.time_of_day.html} | 61 +- docs/build/html/search.html | 6 +- docs/build/html/searchindex.js | 2 +- docs/source/conf.py | 2 +- docs/source/data.rst | 7 - docs/source/date.rst | 7 - docs/source/function.rst | 7 - docs/source/geometry.rst | 7 - docs/source/index.rst | 2 + docs/source/mathematics.rst | 7 - docs/source/numerical.rst | 46 - docs/source/pylib.data.rst | 7 + docs/source/pylib.date.rst | 7 + docs/source/pylib.drawblock.rst | 7 + docs/source/pylib.function.rst | 7 + docs/source/pylib.geometry.rst | 7 + docs/source/pylib.geometry2d.rst | 7 + docs/source/pylib.geometry2d_plot.rst | 7 + docs/source/pylib.mathematics.rst | 7 + docs/source/pylib.numerical.fit.rst | 7 + docs/source/pylib.numerical.integration.rst | 7 + docs/source/pylib.numerical.ode.rst | 7 + docs/source/pylib.numerical.ode_model.rst | 7 + docs/source/pylib.numerical.rst | 49 +- docs/source/pylib.rst | 86 +- docs/source/pylib.time_of_day.rst | 7 + docs/source/time_of_day.rst | 7 - pylib/drawblock.py | 17 +- pylib/geometry.py | 680 ++---- pylib/geometry2d.py | 511 +++++ .../{geometry_plot.py => geometry2d_plot.py} | 7 +- tests/test_geometry.py | 304 +-- tests/test_geometry2d.py | 259 +++ 102 files changed, 3771 insertions(+), 9082 deletions(-) delete mode 100644 docs/build/html/_modules/data.html delete mode 100644 docs/build/html/_modules/date.html delete mode 100644 docs/build/html/_modules/function.html delete mode 100644 docs/build/html/_modules/geometry_plot.html delete mode 100644 docs/build/html/_modules/mathematics.html delete mode 100644 docs/build/html/_modules/numerical/fit.html delete mode 100644 docs/build/html/_modules/numerical/integration.html delete mode 100644 docs/build/html/_modules/numerical/ode.html delete mode 100644 docs/build/html/_modules/numerical/ode_model.html rename docs/build/html/_modules/{geometry.html => pylib/geometry2d.html} (90%) rename docs/build/html/_modules/pylib/{geometry_plot.html => geometry2d_plot.html} (92%) delete mode 100644 docs/build/html/_modules/time_of_day.html delete mode 100644 docs/build/html/_sources/data.rst.txt delete mode 100644 docs/build/html/_sources/date.rst.txt delete mode 100644 docs/build/html/_sources/function.rst.txt delete mode 100644 docs/build/html/_sources/geometry.rst.txt delete mode 100644 docs/build/html/_sources/mathematics.rst.txt delete mode 100644 docs/build/html/_sources/numerical.rst.txt create mode 100644 docs/build/html/_sources/pylib.data.rst.txt create mode 100644 docs/build/html/_sources/pylib.date.rst.txt create mode 100644 docs/build/html/_sources/pylib.drawblock.rst.txt rename docs/build/html/_sources/{geometry_plot.rst.txt => pylib.function.rst.txt} (59%) rename docs/{source/geometry_plot.rst => build/html/_sources/pylib.geometry.rst.txt} (59%) create mode 100644 docs/build/html/_sources/pylib.geometry2d.rst.txt create mode 100644 docs/build/html/_sources/pylib.geometry2d_plot.rst.txt create mode 100644 docs/build/html/_sources/pylib.mathematics.rst.txt create mode 100644 docs/build/html/_sources/pylib.numerical.fit.rst.txt create mode 100644 docs/build/html/_sources/pylib.numerical.integration.rst.txt create mode 100644 docs/build/html/_sources/pylib.numerical.ode.rst.txt create mode 100644 docs/build/html/_sources/pylib.numerical.ode_model.rst.txt create mode 100644 docs/build/html/_sources/pylib.time_of_day.rst.txt delete mode 100644 docs/build/html/_sources/time_of_day.rst.txt delete mode 100644 docs/build/html/numerical.html rename docs/build/html/{data.html => pylib.data.html} (77%) rename docs/build/html/{date.html => pylib.date.html} (77%) create mode 100644 docs/build/html/pylib.drawblock.html rename docs/build/html/{function.html => pylib.function.html} (84%) create mode 100644 docs/build/html/pylib.geometry.html rename docs/build/html/{geometry.html => pylib.geometry2d.html} (76%) rename docs/build/html/{geometry_plot.html => pylib.geometry2d_plot.html} (63%) rename docs/build/html/{mathematics.html => pylib.mathematics.html} (75%) create mode 100644 docs/build/html/pylib.numerical.fit.html create mode 100644 docs/build/html/pylib.numerical.integration.html create mode 100644 docs/build/html/pylib.numerical.ode.html create mode 100644 docs/build/html/pylib.numerical.ode_model.html rename docs/build/html/{time_of_day.html => pylib.time_of_day.html} (70%) delete mode 100644 docs/source/data.rst delete mode 100644 docs/source/date.rst delete mode 100644 docs/source/function.rst delete mode 100644 docs/source/geometry.rst delete mode 100644 docs/source/mathematics.rst delete mode 100644 docs/source/numerical.rst create mode 100644 docs/source/pylib.data.rst create mode 100644 docs/source/pylib.date.rst create mode 100644 docs/source/pylib.drawblock.rst create mode 100644 docs/source/pylib.function.rst create mode 100644 docs/source/pylib.geometry.rst create mode 100644 docs/source/pylib.geometry2d.rst create mode 100644 docs/source/pylib.geometry2d_plot.rst create mode 100644 docs/source/pylib.mathematics.rst create mode 100644 docs/source/pylib.numerical.fit.rst create mode 100644 docs/source/pylib.numerical.integration.rst create mode 100644 docs/source/pylib.numerical.ode.rst create mode 100644 docs/source/pylib.numerical.ode_model.rst create mode 100644 docs/source/pylib.time_of_day.rst delete mode 100644 docs/source/time_of_day.rst create mode 100644 pylib/geometry2d.py rename pylib/{geometry_plot.py => geometry2d_plot.py} (96%) create mode 100644 tests/test_geometry2d.py diff --git a/docs/build/html/.buildinfo b/docs/build/html/.buildinfo index 2c89628..85ac018 100644 --- a/docs/build/html/.buildinfo +++ b/docs/build/html/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: aaf67f6f94ce2e6ce3750a4b226f6461 +config: 2cbc17343901b023dfef01a2244f3120 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/build/html/_modules/data.html b/docs/build/html/_modules/data.html deleted file mode 100644 index c64a7a2..0000000 --- a/docs/build/html/_modules/data.html +++ /dev/null @@ -1,305 +0,0 @@ - - - - - - - data — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for data

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""Read and write data to or from file and manipulate data structures.
-
-:Date: 2019-10-11
-
-.. module:: data
-  :platform: *nix, Windows
-  :synopsis: Handle data files and structures.
-
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-import math
-import pickle
-
-
[docs]def read(file_name, x_column, y_column, default=None, verbose=False): - """Read ascii data file. - - :param filename: file to read - :type filename: str - :param x_column: column index for the x data (first column is 0) - :type x_column: int - :param y_column: column index for the y data (first column is 0) - :type y_column: int - :param default: return object if data loading fails - :type default: object - :param verbose: verbose information (default = False) - :type verbose: bool - - :returns: x and y - :rtype: tuple(list, list) - """ - import re - - x = default - y = default - - if verbose: - print('check if data is available') - try: - file = open(file_name) - x = [] - y = [] - for row in file: - fields = re.split(r'\s+', row.strip()) - x.append(float(fields[x_column])) - y.append(float(fields[y_column])) - file.close() - except IOError: - if verbose: - print('data file not found') - return x, y
- -
[docs]def write(file_name, data): - """Write ascii file. - - :param file_name: file to write - :type file_name: str - :param data: data to write - :type data: str - """ - with open(file_name, 'w') as file: - file.write(data)
- -
[docs]def load(file_name, default=None, verbose=False): - """Load stored program objects from binary file. - - :param file_name: file to load - :type file_name: str - :param default: return object if data loading fails - :type default: object - :param verbose: verbose information (default = False) - :type verbose: bool - - :returns: loaded data - :rtype: object - """ - if verbose: - print('check if data is available') - try: - with open(file_name, 'rb') as input: - # one load for every dump is needed to load all the data - object_data = pickle.load(input) - if verbose: - print('found:') - print(object_data) - except IOError: - object_data = default - if verbose: - print('no saved datas found') - return object_data
- -
[docs]def store(file_name, object_data): - """Store program objects to binary file. - - :param file_name: file to store - :type file_name: str - :param object_data: data to store - :type object_data: object - """ - with open(file_name, 'wb') as output: - # every dump needs a load - pickle.dump(object_data, output, pickle.HIGHEST_PROTOCOL)
- -
[docs]def fold_list(lst, n): - """Convert one-dimensional kx1 array (list) to two-dimensional mxn - array. m = k / n - - :param lst: list to convert - :type lst: list - :param n: length of the second dimenson - :type n: int - - :returns: two-dimensional array (list of lists) - :rtype: list - """ - k = len(lst) - if k % n == 0: - length = int(k/n) - return [lst[i*n:i*n+n] for i in range(length)]
- -
[docs]def seq(start, stop=None, step=1): - r"""Create an arithmetic bounded sequence. - - The sequence is one of the following; - - - empty :math:`\{\}=\emptyset`, if start and stop are the same - - degenerate :math:`\{a\}`, if the sequence has only one element. - - left-close and right-open :math:`[a, b)` - - :param start: start of the sequence, the lower bound. If only start - is given than it is interpreted as stop and start will be 0. - :type start: int or float - :param stop: stop of sequence, the upper bound. - :type stop: int or float - :param step: step size, the common difference (constant difference - between consecutive terms). - :type step: int or float - :returns: arithmetic bounded sequence - :rtype: list - """ - # example of seq(4, 0, -0.4) - # without round: - # [4.0, 3.6, 3.2, 2.8, 2.4, 2.0, 1.5999999999999996, - # 1.1999999999999997, 0.7999999999999998, 0.3999999999999999] - # with round: - # [4.0, 3.6, 3.2, 2.8, 2.4, 2.0, 1.6, 1.2, 0.8, 0.4] - # example of seq(4, 0, -0.41) - # without round: - # [4.0, 3.59, 3.18, 2.77, 2.3600000000000003, - # 1.9500000000000002, 1.54, 1.1300000000000003, - # 0.7200000000000002, 0.31000000000000005] - # with round: - # [4.0, 3.59, 3.18, 2.77, 2.36, 1.95, 1.54, 1.13, 0.72, 0.31] - if stop is None: - return seq(0, start, step) - - start_str = str(start) - start_exp = 0 - if '.' in start_str: - start_exp = len(start_str.split('.')[1]) - - step_str = str(step) - step_exp = 0 - if '.' in step_str: - step_exp = len(step_str.split('.')[1]) - - exponent = max(start_exp, step_exp) # no stop because it is an open bound - - n = int(math.ceil((stop - start)/float(step))) - lst = [] - if n > 0: - lst = [round(start + step*i, exponent) for i in range(n)] - return lst
- -
[docs]def unique_ending(ids, n=1): - """From id list get list with unique ending. - - :param ids: ids - :type ids: list - :param n: minumum chars or ints - :type n: int - - :returns: unique ending of ids - :rtype: list - """ - if ids is not None: - x = [idi[-n:] for idi in ids] - if len(x) > len(set(x)): - return unique_ending(ids, n+1) - else: - return x
- -
[docs]def get_id(ids, uide): - """Get full id from unique id ending. - - :param ids: ids - :type ids: list - :param uide: unique id ending - :type uide: str - - :returns: full id - :rtype: str or int - """ - # take first element, because we know it is a unique ending - return [idi for idi in ids if idi.endswith(uide)][0]
-
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/date.html b/docs/build/html/_modules/date.html deleted file mode 100644 index 9a842aa..0000000 --- a/docs/build/html/_modules/date.html +++ /dev/null @@ -1,221 +0,0 @@ - - - - - - - date — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for date

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""Calculate spacial dates.
-
-:Date: 2018-01-15
-
-.. module:: date
-  :platform: *nix, Windows
-  :synopsis: Special dates.
-   
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-
-
[docs]def gaußsche_osterformel(year): - """Gaußsche Osterformel. - - :param year: the year to calculate the Easter Sunday - :type year: int - - :returns: the day of Easter Sunday as a day in march. - :rtype: int - - :ivar X: Das Jahr / year - :vartype X: int - :ivar K(X): Die Säkularzahl - :vartype K(X): int - :ivar M(X): Die säkulare Mondschaltung - :vartype M(X): int - :ivar S(K): Die säkulare Sonnenschaltung - :vartype S(K): int - :ivar A(X): Den Mondparameter - :vartype A(X): int - :ivar D(A,M): Den Keim für den ersten Vollmond im Frühling - :vartype D(A,M): int - :ivar R(D,A): Die kalendarische Korrekturgröße - :vartype R(D,A): int - :ivar OG(D,R): Die Ostergrenze - :vartype OG(D,R): int - :ivar SZ(X,S): Den ersten Sonntag im März - :vartype SZ(X,S): int - :ivar OE(OG,SZ): Die Entfernung des Ostersonntags von der Ostergrenze (Osterentfernung in Tagen) - :vartype OE(OG,SZ): int - :ivar OS(OG,OE): Das Datum des Ostersonntags als Märzdatum (32. März = 1. April usw.) - :vartype OS(OG,OE): int - - Algorithmus gilt für den Gregorianischen Kalender. - - source: https://de.wikipedia.org/wiki/Gau%C3%9Fsche_Osterformel - """ - x = year - k = x // 100 - m = 15 + (3*k + 3) // 4 - (8*k + 13) // 25 - s = 2 - (3*k + 3) // 4 - a = x % 19 - d = (19*a + m) % 30 - r = (d + a // 11) // 29 - og = 21 + d - r - sz = 7 - (x + x // 4 + s) % 7 - oe = 7 - (og - sz) % 7 - os = og + oe - return os
- -
[docs]def easter_sunday(year): - """Easter Sunday. - - :param year: the year to calculate the Easter Sunday - :type year: int - - :returns: the day of Easter Sunday - :rtype: datetime.date""" - import datetime - march = datetime.date(year, 3, 1) - day = march + datetime.timedelta(days=gaußsche_osterformel(year)) - return day
- -
[docs]def easter_friday(year): - """Easter Friday. - - :param year: the year to calculate the Easter Friday - :type year: int - - :returns: the day of Easter Friday - :rtype: datetime.date""" - import datetime - day = easter_sunday(year) + datetime.timedelta(days=-2) - return day
- -
[docs]def easter_monday(year): - """Easter Monday. - - :param year: the year to calculate the Easter Monday - :type year: int - - :returns: the day of Easter Monday - :rtype: datetime.date""" - import datetime - day = easter_sunday(year) + datetime.timedelta(days=+1) - return day
- -
[docs]def ascension_of_jesus(year): - """Ascension of Jesus. - - :param year: the year to calculate the ascension of Jesus - :type year: int - - :returns: the day of ascension of Jesus - :rtype: datetime.date""" - import datetime - day = easter_sunday(year) + datetime.timedelta(days=+39) - return day
- -
[docs]def pentecost(year): - """Pentecost. - - :param year: the year to calculate the Pentecost - :type year: int - - :returns: the day of Pentecost - :rtype: datetime.date""" - import datetime - day = easter_sunday(year) + datetime.timedelta(days=+49) - return day
-
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/function.html b/docs/build/html/_modules/function.html deleted file mode 100644 index d3cf54c..0000000 --- a/docs/build/html/_modules/function.html +++ /dev/null @@ -1,516 +0,0 @@ - - - - - - - function — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for function

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""Mathematical equations.
-
-:Date: 2019-11-15
-
-.. module:: function
-  :platform: *nix, Windows
-  :synopsis: Mathematical equations.
-
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-import math
-from pylib.data import seq
-from pylib.mathematics import lcm
-
-
[docs]def transformation(f, scale_vertical=1, scale_horizontal=1, - shift_horizontal=0, shift_vertical=0): - r"""Transform functions. - - :param f: function or list of functions - :type f: function or list - :param scale_vertical: "a" scale factor in vertical direction (default - = 1) - :type height: float - :param scale_horizontal: "b" scale factor in horizontal direction - (default = 1) - :type height: float - :param shift_horizontal: "c" shift factor in horizontal direction - (default = 0) - :type height: float - :param shift_vertical: "d" shift factor in vertical direction (default - = 0) - :type height: float - - :returns: transformed function or list of transformed functions - :rtype: function or list - - .. math:: - y = a \, f(b\,(x-c)) + d - """ - # shorter variables - a = scale_vertical - b = scale_horizontal - c = shift_horizontal - d = shift_vertical - - # check if f is a function than put it in a list and return only - # the function, not the one element list - if callable(f): - return transformation( - [f], scale_vertical=a, scale_horizontal=b, shift_horizontal=c, shift_vertical=d)[0] - - # otherwise assume list of functions - if not f: # if f is empty. End of the recursive fucntion - return [] - return [lambda x, t: a*f[0](b*(x-c), t)+d] +\ - transformation( - f[1:], scale_vertical=a, scale_horizontal=b, shift_horizontal=c, shift_vertical=d)
- -
[docs]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 - smooth periodic oscillation. - - :param A: amplitude - :type A: float or int - :param k: (angular) wave number - :type k: float or int - :param f: ordinary frequency - :type f: float or int - :param phi: phase - :type phi: float or int - :param D: non-zero center amplitude - :type D: float or int - :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: - - .. math:: - y(x,t) = A\sin(kx + 2\pi f t + \varphi) + D \\ - y(x,t) = A\sin(kx + \omega t + \varphi) + D - - where: - - * A, amplitude, the peak deviation of the function from zero. - * f, ordinary frequency, the number of oscillations (cycles) that - occur each second of time. - * ω = 2πf, angular frequency, the rate of change of the function - argument in units of radians per second. If ω < 0 the wave is - moving to the right, if ω > 0 the wave is moving to the left. - * φ, phase, specifies (in radians) where in its cycle the - oscillation is at t = 0. - * x, spatial variable that represents the position on the - dimension on which the wave propagates. - * 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) - ν. - * D, non-zero center amplitude. - - The wavenumber is related to the angular frequency by: - - .. math:: - k={\omega \over v}={2\pi f \over v}={2\pi \over \lambda } - - where λ (lambda) is the wavelength, f is the frequency, and v is the - linear speed. - - .. seealso:: - :meth:`cosine_wave` - """ - if degree: - phi = math.radians(phi) - return lambda x, t=0: A*math.sin(k*x + 2*math.pi*f*t + phi) + D
- -
[docs]def cosine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False): - r"""A cosine wave is said to be sinusoidal, because, - :math:`\cos(x) = \sin(x + \pi/2)`, 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. - - :param A: amplitude - :type A: float or int - :param k: (angular) wave number - :type k: float or int - :param f: ordinary frequency - :type f: float or int - :param phi: phase - :type phi: float or int - :param D: non-zero center amplitude - :type D: float or int - :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:`sine_wave` - """ - if degree: - phi = phi + 90 - else: - phi = phi + math.pi/2 - return sine_wave(A=A, k=k, f=f, phi=phi, D=D, degree=degree)
- - -# -# Parametric equations -# roulette -# - -
[docs]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
- -
[docs]def epitrochoid(R, r, d): - r"""Epitrochoid - - 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. - - :param R: radius of the fixed interior circle - :type R: float - :param r: radius of the rolling circle outside of the fixed circle - :typre r: float - :param d: distance from the center of the exterior 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\right] - - :: - - * * * - * R * - * * - * * * * - * * * r * - * ** .... * - * ** d * - * * * * - * * * * - * * - * * - * * * - - >>> x, y = epitrochoid(3, 1, 0.5)[:1] - >>> x, y, theta_end = epitrochoid(3, 1, 0.5) - """ - 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 - return x, y, theta_end
- -
[docs]def to_str(f, x=None, x_0=0, x_1=1, t=None, h=10, w=80, density=1, char_set="line"): - """Represent functions as string frame with a specific character set. - which are normed to the range of [0, 1] to - - :param f: function or list of functions normed to the range of [0, 1] - :type f: function or list - :param h: number of chars in vertical direction - :type h: int - :param w: number of chars in horizontal direction - :type w: int - - :param char_set: either "braille" or "block". "braille" uses Unicode - Characters in the Braille Patterns Block (fisrt index U+2800, last - index U+28FF [CUDB]_) and the "block" uses part of the Unicode - Characters in the Block Elements Block (fisrt index U+2580, last - index U+259F [CUDB]_). Alias for braille is line and alias for - block is histogram - :type char_set: str - - Usage: - * case dependent arguments - - * 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) - * 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" - - * 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" - - - .. rubric:: Braille Patterns Block - - * Dots or pixels per character in vertical direction: 6 - * Dots or pixels per character in horizontal direction: 2 - - 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) - - :: - - | ^ y axis - | | - | ,_____,,_____,,_____, - 7 + | * *|| * *|| * *| - 6 + | * *|| * *|| * *| - 5 + | * *|| * *|| * *| - 4 + | * *|| * *|| * *| - | ;=====;;=====;;=====; - 3 + | * *|| * *|| * *| - 2 + | * *|| * *|| * *| - 1 + | * *|| * *|| * *| - 0 + - | * *|| * *|| * *| ---> x axis - | ;=====;;=====;;=====; - -1 + | * *|| * *|| * *| - -2 + | * *|| * *|| * *| - -3 + | * *|| * *|| * *| - -4 + | * *|| * *|| * *| - | ````````````````````` - | | - `-----+--+---+--+---+--+------------- - -2 -1 0 1 2 3 - - - .. rubric:: Block Elements Block - - * Dots or pixels per character in vertical direction: 8 - * Dots or pixels per character in horizontal direction: 1 - - Example of 3 columns and 3 rows - - :: - - | ^ y axis - | | - | ,_____,,_____,,_____, - 15 + | --- || --- || --- | - 14 + | --- || --- || --- | - 13 + | --- || --- || --- | - 12 + | --- || --- || --- | - 11 + | --- || --- || --- | - 10 + | --- || --- || --- | - 9 + | --- || --- || --- | - 8 + | --- || --- || --- | - | ;=====;;=====;;=====; - 7 + | --- || --- || --- | - 6 + | --- || --- || --- | - 5 + | --- || --- || --- | - 4 + | --- || --- || --- | - 3 + | --- || --- || --- | - 2 + | --- || --- || --- | - 1 + | --- || --- || --- | - 0 + - | --- || --- || --- | ---> x axis - | ;=====;;=====;;=====; - -1 + | --- || --- || --- | - -2 + | --- || --- || --- | - -3 + | --- || --- || --- | - -4 + | --- || --- || --- | - -5 + | --- || --- || --- | - -6 + | --- || --- || --- | - -7 + | --- || --- || --- | - -8 + | --- || --- || --- | - | ````````````````````` - | | - `------+------+------+--------------- - -1 0 1 - - - .. rubric:: References - - .. [CUDB] `Unicode Database - Blocks <ftp://ftp.unicode.org/Public/UNIDATA/Blocks.txt>`_ - - - .. seealso:: - :meth:`pylib.function.transformation` - """ - # scale function to used chars and dots/pixel in y direction (4 for braille characters): from [0, 1] to [0, chars*4-1] - # negate the function because the y axis is pointing downwards: from [0, 1] to [-1, 0] or from [0, chars*4-1] to [-(chars*4-1), 0] - # and becasue of the negation shift the function by one dot/pixel, otherwise the function would need another char, because the 0 is on an another char on the "positive side". - # devide the time by the number of dots/pixel in x direction (2 for braille characters) - window_factor = w/(x_1-x_0) - frame = "" - if char_set in ["line", "braille"]: - import drawille - - pixels_horizontal = 2 - pixels_vertical = 4 - a = -(h*pixels_vertical-1) - b = 1/pixels_horizontal - f = transformation(f, a, b, 0, -1) - - canvas = drawille.Canvas() - # divide step width of the sequence by 2 (double density, 2 dots/pixel per char) - # multiplicate x by 2 (2 dots/pixel per char) - for x_i in seq(x_0*window_factor*pixels_horizontal, x_1*window_factor*pixels_horizontal, 1/density): - canvas.set(x_i, f(x_i, t)) - #frame = canvas.frame(min_x=a*pixel_per_char, min_y=1, max_x=b*pixel_per_char, max_y=21) - frame = canvas.frame() - elif char_set in ["histogram", "block"]: - import drawblock - - pixels_horizontal = 1 - pixels_vertical = 8 - a = h*pixels_vertical-1 - f = transformation(f, a, 1, 0, 0) - - density = min(density, 1) # density max 1! - x = seq(x_0*window_factor, x_1*window_factor, 1/pixels_horizontal/density) - f = [f(xi, t) for xi in x] - frame = drawblock.histogram(f, x) - - return frame
-
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/geometry_plot.html b/docs/build/html/_modules/geometry_plot.html deleted file mode 100644 index 3d3ae3d..0000000 --- a/docs/build/html/_modules/geometry_plot.html +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - geometry_plot — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for geometry_plot

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""2D geometry plotter using  matplotlib (pylab).
-
-:Date: 2019-08-20
-
-.. module:: geometry_plot
-  :platform: *nix, Windows
-  :synopsis: Geometry plotting.
-
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-import math
-import pylab
-from geometry import (
-  distance, angle, line, interpolate_hermite, rotate_xy, translate_xy
-)
-
-pylab.style.use('dark_background')
-pylab.rcParams['grid.color'] = 'gray'
-
-# The kwargs are Line2D properties:
-# https://matplotlib.org/3.1.1/_modules/matplotlib/lines.html#Line2D
-# https://matplotlib.org/devdocs/_modules/matplotlib/lines.html#Line2D
-pylab_Line2D_properties = [
-  'linewidth', 'linestyle', 'color',
-  'marker', 'markersize', 'markeredgewidth', 'markeredgecolor',
-  'markerfacecolor', 'markerfacecoloralt',
-  'fillstyle', 'antialiased',
-  'dash_capstyle', 'solid_capstyle',
-  'dash_joinstyle', 'solid_joinstyle',
-  'pickradius', 'drawstyle', 'markevery',
-]
-
-
-
[docs]def plot_lines(lns, **kwargs): - if 'color' not in kwargs: - # Colors from "tab10" colormap - cmap = pylab.get_cmap("tab10") - kwargs['color'] = cmap(0) - - # Colors from color cycle - cycle = pylab.rcParams['axes.prop_cycle'].by_key()['color'] - kwargs['color'] = cycle[0] - - # Colors from CN notation (same as the first 10 colors from the color cycle) - kwargs['color'] = "C0" - - for ln in lns: - x, y = line(*ln) - pylab.plot(x, y, **kwargs)
- - -
[docs]def plot_cubic_lines(lns, **kwargs): - if 'color' not in kwargs: - # Colors from "tab10" colormap - cmap = pylab.get_cmap("tab10") - kwargs['color'] = cmap(0) - - # Colors from color cycle - cycle = pylab.rcParams['axes.prop_cycle'].by_key()['color'] - kwargs['color'] = cycle[0] - - # Colors from CN notation (same as the first 10 colors from the color cycle) - kwargs['color'] = "C0" - - factor = 1 - if 'factor' in kwargs: - factor = kwargs['factor'] - - samples = 10 - if 'samples' in kwargs: - samples = kwargs['samples'] - - kwargs = {k: v for k, v in kwargs.items() if k in pylab_Line2D_properties} - - for ln in lns: - l, r, d = ln - L = distance(l, r) - ang = angle(l, r) - x, y = interpolate_hermite(d[1], d[2], d[4], d[5], d[0], d[3], - scale_x=L, scale_y=factor, samples=samples) - x, y = rotate_xy((0, 0), ang, x, y) - x, y = translate_xy(l, x, y) - - pylab.plot(x, y, **kwargs)
-
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/index.html b/docs/build/html/_modules/index.html index 3509ca8..34e9952 100644 --- a/docs/build/html/_modules/index.html +++ b/docs/build/html/_modules/index.html @@ -4,7 +4,7 @@ - Overview: module code — pylib 2019.5.19 documentation + Overview: module code — pylib 2019.12.21 documentation @@ -33,29 +33,19 @@

All modules for which code is available

-
@@ -74,6 +64,10 @@

Navigation

+

Contents:

+

Related Topics

diff --git a/docs/build/html/_modules/mathematics.html b/docs/build/html/_modules/mathematics.html deleted file mode 100644 index 8c007d8..0000000 --- a/docs/build/html/_modules/mathematics.html +++ /dev/null @@ -1,1025 +0,0 @@ - - - - - - - mathematics — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for mathematics

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""Mathematical functions and objects.
-
-:Date: 2019-12-12
-
-.. module:: mathematics
-  :platform: *nix, Windows
-  :synopsis: Mathematical functions and objects.
-
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-import math
-from math import gcd
-
-
[docs]def lcm(a, b): - """Compute the lowest common multiple of a and b""" - return a/gcd(a, b)*b
- - -
[docs]class vector(list): - """Use/create vector like lists - - * size -> len(a) - * abs -> abs(a) - * dot -> a * b - * outer -> a @ b - - use super constructor - - use super __iter__ - - use super __setitem__ - - >>> v = vector([1,2,3,4,5]) - >>> v[3:5] = [1,2] - >>> print(v) - [1, 2, 3, 1, 2] - >>> isinstance(v, vector) - True - - use super __lt__(a, b) - - use super __le__(a, b) - - use super __eq__(a, b) - - >>> v = vector([1,2,3,1,2]) - >>> v2 = vector([1,2,3,1,2]) - >>> v == v2 - True - - use super __ne__(a, b) - - use super __ge__(a, b) - - use super __gt__(a, b) - - use super __contains__ - - >>> 2 in vector([1,2,3]) - True - - __isub__ - - >>> v = vector([1,2,3]) - >>> v -= vector([3,3,3]) - >>> print(v) - [-2, -1, 0] - - __imul__ - - >>> v = vector([1,2,3]) - >>> v *= vector([3,3,3]) - >>> print(v) - 18 - - __imatmul__ - - >>> m = vector([1,2,3]) - >>> m *= vector([3,3,3]) - >>> print(v) - [[3, 3, 3], [6, 6, 6], [9, 9, 9]] - """ - - def __getitem__(self, index): - """ - For index return value, for range return new vector object. - - :Example: - - >>> v = vector([1, 2, 3, 4, 5]) - >>> v[1:3] - [2, 3] - >>> v = vector([1, 2, 3, 4, 5]) - >>> v[3] - 4 - """ - # use the list.__getslice__ method and convert result to vector - item = super().__getitem__(index) - return vector(item) if isinstance(item, list) else item - - def __pos__(self): - """+ a (new object) - """ - return vector([*self]) - - def __neg__(self): - """- a (new object) - """ - return vector([-i for i in self]) - - def __add__(self, other): - """a + b (new object) - - :Example: - - >>> v = vector([1,2,3]) + vector([1,2,3]) - >>> print(v) - [2, 4, 6] - """ - return vector([i+j for i, j in zip(self, other)]) - - def __iadd__(self, other): - """a += b (new object) - - :Example: - - >>> v = vector([1,2,3]) - >>> v += vector([3,3,3]) - >>> print(v) - [4, 5, 6] - """ - return vector([i+j for i, j in zip(self, other)]) - - def __sub__(self, other): - """a - b (new object) - - :Example: - - >>> v = vector([1,2,3]) - vector([1,2,3]) - >>> print(v) - [0, 0, 0] - """ - return vector([i-j for i, j in zip(self, other)]) - - def __mul__(self, other): - r"""Scalar multiplication, dot product (inner product) or - vector-matrix multiplication. - - a * b (new object) - - :type other: scalar, vector (or 1d list), matrix (or 2d list) - - .. math:: - \mathbf{c} &= \mathbf{a} \cdot b \\ - \mathbf{c} &= \mathbf{a} \cdot \mathbf{b} \\ - \mathbf{c} &= \mathbf{a} \cdot \mathbf{B} - - .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). - - :Example: - - >>> v = vector([1,2,3,4,5])*3 - >>> print(v) - [3, 6, 9, 12, 15] - >>> v = vector([1,2,3,4,5])*3. - >>> print(v) - [3.0, 6.0, 9.0, 12.0, 15.0] - >>> s = vector([1,2,3])*vector([1,2,3]) - >>> print(s) - 14 - - .. seealso:: - :meth:`__rmul__` - """ - try: # vector * vector - return sum([i*j for i, j in zip(self, other)]) - except: - try: # vector * matrix - return vector([sum(c*d for c, d in zip(self, b_col)) for b_col in zip(*other)]) - except: # vector * scalar - return vector([i*other for i in self]) - - def __rmul__(self, other): - r"""Scalar multiplication, dot product (inner product) or - matrix-vector multiplication. - - a * b (new object) - - :type other: scalar (or 1d list and 2d list) - - .. math:: - \mathbf{c} &= a \cdot \mathbf{b} \\ - \mathbf{c} &= \mathbf{a} \cdot \mathbf{b} \\ - \mathbf{c} &= \mathbf{A} \cdot \mathbf{b} - - .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). - - :Example: - - >>> v = 3*vector([1,2,3,4,5]) - >>> print(v) - [3, 6, 9, 12, 15] - >>> v = 3.*vector([1,2,3,4,5]) - >>> print(v) - [3.0, 6.0, 9.0, 12.0, 15.0] - - .. seealso:: - :meth:`__mul__` - :meth:`matrix.__mul__` for matrix * vector - """ - try: # 2d list * vector (matrix * vector see matrix.__mul__) - return vector([sum(c*d for c, d in zip(a_row, self)) for a_row in other]) - except: # scalar * vector - return self*other - - def __matmul__(self, other): - r"""Outer product a @ b (new object) - - .. math:: - \vec{a} \otimes \vec{b} - = - \begin{pmatrix} - a_{1}\\ - a_{2}\\ - a_{3} - \end{pmatrix} - \otimes - \begin{pmatrix} - b_{1}\\ - b_{2}\\ - b_{3} - \end{pmatrix} - = - \begin{pmatrix} - a_{1}b_{1}&a_{1}b_{2}&a_{1}b_{3}\\ - a_{2}b_{1}&a_{2}b_{2}&a_{2}b_{3}\\ - a_{3}b_{1}&a_{3}b_{2}&a_{3}b_{3} - \end{pmatrix} - - - :Example: - - >>> m = vector([1,2,3]) @ vector([1,2,4]) - >>> print(m) - [[1, 2, 4], [2, 4, 8], [3, 6, 12]] - """ - try: # vector * vector - return matrix([[i*j for j in other] for i in self]) - except: # vector * number - return self*other - - def __abs__(self): - r"""Magnitude / norm of a vector - - .. math:: - b = \sqrt{\sum a_i^2} - - :Example: - - >>> norm([3, 4]) - 5 - >>> norm(vector([3, 4])) - 5 - """ - return math.sqrt(self * self) - - def __str__(self): - return str([*self]) - - def __repr__(self): - return "vector(" + str(self) + ")" - -
[docs] @staticmethod - def full(length, fill_value): - """Returns a vector of length m or matrix of size m rows, n - columns filled with v. - - :param length: length of the vector, e. g. 3 - :type length: int - :param fill_value: Fill value - :Type fill_value: scalar - - :Example: - - >>> v = vector.full(3, 7) - >>> print(v) - [7, 7, 7] - """ - return vector([fill_value for i in range(length)])
- -
[docs] @staticmethod - def zeros(length): - """Returns a zero vector of length m or matrix of size rows, n - columns filled with zeros. - - :param length: length of the vector, e. g. 3 - :type length: int - - :Example: - - >>> v = zeros(3) - >>> print(v) - [0.0, 0.0, 0.0] - """ - return vector.full(length, 0.)
- -
[docs] @staticmethod - def ones(length): - """Returns a vector of length m or matrix of size rows, n - columns filled with ones. - - :param length: lhape of the vector, e. g. 3 - :type length: int - - :Example: - - >>> v = ones(3) - >>> print(v) - [1.0, 1.0, 1.0] - """ - return vector.full(length, 1.)
- -
[docs] @staticmethod - def random(shape, lmin=0.0, lmax=1.0): - """Returns a random vector of length n or matrix of size m rows, n - columns filled with random numbers. - - :Example: - - >>> v = random(3) - >>> print(v) - [0.9172905912930438, 0.8908124278322492, 0.5256002790725927] - >>> v = random(3, 1, 2) - >>> print(v) - [1.2563665665080803, 1.9270454509964547, 1.2381672401270487] - """ - import random - dl = lmax-lmin - return vector([dl*random.random()+lmin for i in range(shape)])
- -
[docs] @staticmethod - def normalize(a): - r"""Normalize a vector (i. e. the vector has a length of 1) - - :type a: vector - - .. math:: - \vec{e}_a = \frac{\vec{a}}{|\vec{a}|} - - .. seealso:: - :meth:`norm` for a norm (magnitude) of a vector - """ - a_mag = abs(a) - return vector([i/a_mag for i in a])
- -
[docs] @staticmethod - def ang(a, b): - return math.acos(a * b / (abs(a) * abs(b)))
- -
[docs] @staticmethod - def conjugate(a): - """ - New vector object - - :type a: list - """ - return vector([i.conjugate() for i in a])
- -
[docs] @staticmethod - def re(a): - """Return the real parts of a complex vector - - :type a: list - """ - return vector([i.real for i in a])
- -
[docs] @staticmethod - def im(a): - """Return the imaginary parts of a complex vector - - :type a: list - """ - return vector([i.imag for i in a])
- -
[docs] @staticmethod - def abs(a): - """Return modulus parts of a complex vector - - :type a: list - """ - return vector([abs(i) for i in a])
- -
[docs] @staticmethod - def arg(a): - """Return phase parts of a complex vector - - :type a: list - """ - return vector([math.atan2(i.imag, i.real) for i in a])
- -
[docs] @staticmethod - def cross(a, b): - r"""Cross product - - :type a: list - :type b: list - - c is orthogonal to both a and b. - The direction of c can be found with the right-hand rule. - - .. math:: - \vec{c} = \vec{a} \times \vec{b} - """ - return [a[1]*b[2] - a[2]*b[1], - a[2]*b[0] - a[0]*b[2], - a[0]*b[1] - a[1]*b[0]]
- -
[docs] def xyz(self): - return self[:3]
- -
[docs] def rotate_x(self, theta): - r"""Rotation about the x dirction. - - .. math:: - \begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = - \begin{bmatrix} - 1 & 0 & 0 & 0 \\ - 0 & \cos \theta & -\sin \theta & 0 \\ - 0 & \sin \theta & \cos \theta & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix} - """ - self[:] = matrix.rx(theta) * self - return self
- -
[docs] def rotate_y(self, theta): - r"""Rotation about the y dirction. - - .. math:: - \begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = - \begin{bmatrix} - \cos \theta & 0 & \sin \theta & 0 \\ - 0 & 1 & 0 & 0 \\ - -\sin \theta & 0 & \cos \theta & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix} - """ - self[:] = matrix.ry(theta) * self - return self
- -
[docs] def rotate_z(self, theta): - r"""Rotation about the z dirction. - - .. math:: - \begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = - \begin{bmatrix} - \cos \theta & -\sin \theta & 0 & 0 \\ - \sin \theta & \cos \theta & 0 & 0 \\ - 0 & 0 & 1 & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix} - """ - self[:] = matrix.rz(theta) * self - return self
- -
[docs] def translate(self, tx, ty, tz): - r"""Translation - - .. math:: - \begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = - \begin{bmatrix} - 1 & 0 & 0 & t_x \\ - 0 & 1 & 0 & t_y \\ - 0 & 0 & 1 & t_z \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix} - """ - self[:] = matrix.t(tx, ty, tz) * self - return self
- -
[docs] def scale(self, sx, sy=None, sz=None): - r"""Scaling - - uniform scaling if sx=sy=sz=s. - Note that scaling happens around the origin, so objects not - centered at the origin will have their centers move. To avoid this, - either scale the object when it's located at the origin, or - perform a translation afterwards to move the object back to where - it should be. - - .. math:: - \begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = - \begin{bmatrix} - s_x & 0 & 0 & 0 \\ - 0 & s_y & 0 & 0 \\ - 0 & 0 & s_z & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix} - """ - if not sy: - sy = sx - sz = sx - self[:] = matrix.s(sx, sy, sz) * self - return self
- -
[docs] def ch_cs(self, cs): - r"""Transform this vector from its defined coordinate system to a - new coordinate system, defined by the given coordinate system (u, - v and w direction vectors). - - .. math:: - \begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = - \begin{bmatrix} - u_x & u_y & u_z & 0 \\ - v_x & v_y & v_z & 0 \\ - w_x & w_y & w_z & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix} - """ - self[:] = cs * self - return self
- -
[docs]class matrix(list): - """Use/create matrix like list of lists - """ - - def __getitem__(self, index): - """ - For index return value, for range return new vector object. - - :Example: - - >>> m = matrix([[1, 2, 3, 0], [4, 5, 6, 0], [7, 8, 9, 0], [0, 0, 0, 0]]) - >>> print(m[2]) - [7, 8, 9, 0] - >>> print(m[:,1:3]) - [[2, 3], [5, 6], [8, 9], [0, 0]] - >>> print(m[0:2,1:3]) - [[2, 3], [5, 6]] - >>> print(m[::2,::2]) - [[1, 3], [7, 9]] - """ - # index: slice(stop), slice(start, stop[, step]) - # for e. g. m[(1,3),:] -> index = ((1, 3), slice(None, None, None)) - # use the list.__getslice__ method and convert result to vector - try: # 2d slicing (tuple of sclices) - item = [row.__getitem__(index[1]) for row in super().__getitem__(index[0])] - except: # 1d slicing - item = super().__getitem__(index) - return matrix(item) if isinstance(item, list) else item - -
[docs] @staticmethod - def rx(theta): - r"""Rotation matrix about the x direction. - - Rotates the coordinate system of vectors - - .. math:: - R_{x}(\theta) = - \begin{bmatrix} - 1 & 0 & 0 & 0 \\ - 0 & \cos \theta & -\sin \theta & 0 \\ - 0 & \sin \theta & \cos \theta & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - """ - s = math.sin(theta) - c = math.cos(theta) - T = matrix([[ 1, 0, 0, 0], - [ 0, c,-s, 0], - [ 0, s, c, 0], - [ 0, 0, 0, 1]]) - return T
- -
[docs] @staticmethod - def ry(theta): - r"""Rotation matrix about the y direction. - - Rotates the coordinate system of vectors - - .. math:: - R_{y}(\theta) = - \begin{bmatrix} - \cos \theta & 0 & \sin \theta & 0 \\ - 0 & 1 & 0 & 0 \\ - -\sin \theta & 0 & \cos \theta & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - """ - s = math.sin(theta) - c = math.cos(theta) - T = matrix([[ c, 0, s, 0], - [ 0, 1, 0, 0], - [-s, 0, c, 0], - [ 0, 0, 0, 1]]) - return T
- -
[docs] @staticmethod - def rz(theta): - r"""Rotation matrix about the z direction. - - Rotates the coordinate system of vectors - - .. math:: - R_{z}(\theta) = - \begin{bmatrix} - \cos \theta & -\sin \theta & 0 & 0 \\ - \sin \theta & \cos \theta & 0 & 0 \\ - 0 & 0 & 1 & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - - :Example: - - .. math:: - R_{z}(\theta) \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = - \begin{bmatrix} - \cos 90° & -\sin 90° & 0 & 0 \\ - \sin 90° & \cos 90° & 0 & 0 \\ - 0 & 0 & 1 & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = - \begin{bmatrix} - 0 & -1 & 0 & 0 \\ - 1 & 0 & 0 & 0 \\ - 0 & 0 & 1 & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = - \begin{bmatrix}0 \\ 1 \\ 0 \\ 1\end{bmatrix} - """ - s = math.sin(theta) - c = math.cos(theta) - T = matrix([[ c,-s, 0, 0], - [ s, c, 0, 0], - [ 0, 0, 1, 0], - [ 0, 0, 0, 1]]) - return T
- -
[docs] @staticmethod - def t(tx, ty, tz): - r"""Translation matrix - - .. math:: - T = - \begin{bmatrix} - 1 & 0 & 0 & t_x \\ - 0 & 1 & 0 & t_y \\ - 0 & 0 & 1 & t_z \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - """ - T = matrix([[ 1, 0, 0,tx], - [ 0, 1, 0,ty], - [ 0, 0, 1,tz], - [ 0, 0, 0, 1]]) - return T
- -
[docs] @staticmethod - def s(sx, sy=None, sz=None): - r"""Scaling matrix - - uniform scaling if sx=sy=sz=s. - Note that scaling happens around the origin, so objects not - centered at the origin will have their centers move. To avoid this, - either scale the object when it's located at the origin, or - perform a translation afterwards to move the object back to where - it should be. - - .. math:: - S = - \begin{bmatrix} - s_x & 0 & 0 & 0 \\ - 0 & s_y & 0 & 0 \\ - 0 & 0 & s_z & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - """ - if not sy: - sy = sx - sz = sx - T = matrix([[sx, 0, 0, 0], - [ 0,sy, 0, 0], - [ 0, 0,sz, 0], - [ 0, 0, 0, 1]]) - return T
- - def __mul__(self, other): - r"""Scalar multiplication, dot product (inner product) or - matrix-vector multiplication. - - a * b (new object) - - :type other: scalar, vector (or 1d list), matrix (or 2d list) - - .. math:: - \mathbf{C} &= \mathbf{A} \cdot b \\ - \mathbf{c} &= \mathbf{A} \cdot \mathbf{b} \\ - \mathbf{C} &= \mathbf{A} \cdot \mathbf{B} - - .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). - - :Example: - - >>> m = matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [0, 0, 0, 1]]) * 5 - >>> print(m) - [[5, 10, 15, 20], [25, 30, 35, 40], [45, 50, 55, 60], [0, 0, 0, 5]] - >>> m = matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [0, 0, 0, 1]]) * 5. - >>> print(m) - [[5.0, 10.0, 15.0, 20.0], [25.0, 30.0, 35.0, 40.0], [45.0, 50.0, 55.0, 60.0], [0.0, 0.0, 0.0, 5.0]] - >>> v = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) * vector([12, 12, 13]) - >>> print(v) - [75, 186, 297] - >>> m = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) * matrix([[12, 12, 13], [14, 15, 16], [17, 18, 19]]) - >>> print(m) - [[91, 96, 102], [220, 231, 246], [349, 366, 390]] - - .. seealso:: - :meth:`__rmul__` - """ - try: # matrix * matrix - return matrix([[sum(c*d for c, d in zip(a_row, b_col)) for b_col in zip(*other)] for a_row in self]) - except: - try: # matrix * vector - return vector([sum(c*d for c, d in zip(a_row, other)) for a_row in self]) - except: # matrix * scalar - return matrix([[a*other for a in a_row] for a_row in self]) - - def __rmul__(self, other): - r"""Scalar multiplication, dot product (inner product) or - vector-matrix multiplication. - - a * b (new object) - - :type other: scalar (or 1d list and 2d list) - - .. math:: - \mathbf{C} &= a \cdot \mathbf{B} \\ - \mathbf{c} &= \mathbf{a} \cdot \mathbf{B} \\ - \mathbf{C} &= \mathbf{A} \cdot \mathbf{B} - - .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). - - :Example: - - >>> m = 5 * matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [0, 0, 0, 1]]) * 5 - >>> print(m) - [[5, 10, 15, 20], [25, 30, 35, 40], [45, 50, 55, 60], [0, 0, 0, 5]] - >>> m = 5. * matrix([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [0, 0, 0, 1]]) - >>> print(m) - [[5.0, 10.0, 15.0, 20.0], [25.0, 30.0, 35.0, 40.0], [45.0, 50.0, 55.0, 60.0], [0.0, 0.0, 0.0, 5.0]] - - .. seealso:: - :meth:`__mul__` - :meth:`vector.__mul__` for vector * matrix - """ - try: # 2d list * matrix (matrix * matrix see matrix.__mul__) - return matrix([[sum(c*d for c, d in zip(a_row, b_col)) for b_col in zip(*self)] for a_row in other]) - except: - try: # 1d list * matrix (vector * matrix see vector.__mul__) - return vector([sum(c*d for c, d in zip(other, b_col)) for b_col in zip(*self)]) - except: # scalar * vector - return self*other - - def __str__(self): - return str([*self]) - - def __repr__(self): - return "matrix(" + str(self) + ")" - -
[docs] def rotate_x(self, theta): - r"""Rotation about the x dirction. - - .. math:: - \begin{bmatrix} - xx & xy & xz & t_x \\ - yx' & yy' & yz' & t_y' \\ - zx' & zy' & zz' & t_z' \\ - 0 & 0 & 0 & h - \end{bmatrix} = - \begin{bmatrix} - 1 & 0 & 0 & 0 \\ - 0 & \cos \theta & -\sin \theta & 0 \\ - 0 & \sin \theta & \cos \theta & 0 \\ - 0 & 0 & 0 & h - \end{bmatrix} - \begin{bmatrix} - xx & xy & xz & t_x \\ - yx & yy & yz & t_y \\ - zx & zy & zz & t_z \\ - 0 & 0 & 0 & h - \end{bmatrix} - """ - self[:] = matrix.rx(theta) * self - return self
- -
[docs] def rotate_y(self, theta): - r"""Rotation about the y dirction. - - .. math:: - \begin{bmatrix} - xx' & xy' & xz' & t_x' \\ - yx & yy & yz & t_y \\ - zx' & zy' & zz' & t_z' \\ - 0 & 0 & 0 & h - \end{bmatrix} = - \begin{bmatrix} - \cos \theta & 0 & \sin \theta & 0 \\ - 0 & 1 & 0 & 0 \\ - -\sin \theta & 0 & \cos \theta & 0 \\ - 0 & 0 & 0 & h - \end{bmatrix} - \begin{bmatrix} - xx & xy & xz & t_x \\ - yx & yy & yz & t_y \\ - zx & zy & zz & t_z \\ - 0 & 0 & 0 & h - \end{bmatrix} - """ - self[:] = matrix.ry(theta) * self - return self
- -
[docs] def rotate_z(self, theta): - r"""Rotation about the z dirction. - - .. math:: - \begin{bmatrix} - xx' & xy' & xz' & t_x' \\ - yx' & yy' & yz' & t_y' \\ - zx & zy & zz & t_z \\ - 0 & 0 & 0 & h - \end{bmatrix} = - \begin{bmatrix} - \cos \theta & -\sin \theta & 0 & 0 \\ - \sin \theta & \cos \theta & 0 & 0 \\ - 0 & 0 & 1 & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix} - xx & xy & xz & t_x \\ - yx & yy & yz & t_y \\ - zx & zy & zz & t_z \\ - 0 & 0 & 0 & h - \end{bmatrix} - """ - self[:] = matrix.rz(theta) * self - return self
- -
[docs] def translate(self, tx, ty, tz): - r"""Translation - - .. math:: - \begin{bmatrix} - xx & xy & xz & t_x' \\ - yx & yy & yz & t_y' \\ - zx & zy & zz & t_z' \\ - 0 & 0 & 0 & h - \end{bmatrix} = - \begin{bmatrix} - 1 & 0 & 0 & t_x \\ - 0 & 1 & 0 & t_y \\ - 0 & 0 & 1 & t_z \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix} - xx & xy & xz & t_x \\ - yx & yy & yz & t_y \\ - zx & zy & zz & t_z \\ - 0 & 0 & 0 & h - \end{bmatrix} - """ - self[:] = matrix.t(tx, ty, tz) * self - return self
- -
[docs] def scale(self, sx, sy=None, sz=None): - r"""Scaling - - uniform scaling if sx=sy=sz=s. - Note that scaling happens around the origin, so objects not - centered at the origin will have their centers move. To avoid this, - either scale the object when it's located at the origin, or - perform a translation afterwards to move the object back to where - it should be. - - .. math:: - \begin{bmatrix} - xx' & xy' & xz' & t_x' \\ - yx' & yy' & yz' & t_y' \\ - zx' & zy' & zz' & t_z' \\ - 0 & 0 & 0 & h - \end{bmatrix} = - \begin{bmatrix} - s_x & 0 & 0 & 0 \\ - 0 & s_y & 0 & 0 \\ - 0 & 0 & s_z & 0 \\ - 0 & 0 & 0 & 1 - \end{bmatrix} - \begin{bmatrix} - xx & xy & xz & t_x \\ - yx & yy & yz & t_y \\ - zx & zy & zz & t_z \\ - 0 & 0 & 0 & h - \end{bmatrix} - """ - if not sy: - sy = sx - sz = sx - self[:] = matrix.s(sx, sy, sz) * self - return self
-
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/numerical/fit.html b/docs/build/html/_modules/numerical/fit.html deleted file mode 100644 index b2dbf92..0000000 --- a/docs/build/html/_modules/numerical/fit.html +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - numerical.fit — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for numerical.fit

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""Function and approximation.
-
-:Date: 2019-10-15
-
-.. module:: fit
-  :platform: *nix, Windows
-  :synopsis: Function and approximation.
-
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-from __future__ import print_function
-from pylab import array, argmax, gradient, exp, sqrt, log, linspace
-from scipy.optimize import curve_fit
-
-
[docs]def gauss(x, *p): - """Gauss distribution function. - - .. math:: - f(x)=ae^{-(x-b)^{2}/(2c^{2})} - - :param x: positions where the gauss function will be calculated - :type x: int or float or list or numpy.ndarray - :param p: gauss parameters [a, b, c, d]: - - * a -- amplitude (:math:`\\int y \\,\\mathrm{d}x=1 \\Leftrightarrow a=1/(c\\sqrt{2\\pi})` ) - * b -- expected value :math:`\\mu` (position of maximum, default = 0) - * c -- standard deviation :math:`\\sigma` (variance :math:`\\sigma^2=c^2`) - * d -- vertical offset (default = 0) - :type p: list - - :returns: gauss values at given positions x - :rtype: numpy.ndarray - """ - x = array(x) # cast e. g. list to numpy array - a, b, c, d = p - return a*exp(-(x - b)**2./(2. * c**2.)) + d
- -
[docs]def gauss_fit(x, y, e=None, x_fit=None, verbose=False): - """Fit Gauss distribution function to data. - - :param x: positions - :type x: int or float or list or numpy.ndarray - :param y: values - :type y: int or float or list or numpy.ndarray - :param e: error values (default = None) - :type e: int or float or list or numpy.ndarray - :param x_fit: positions of fitted function (default = None, if None then x - is used) - :type x_fit: int or float or list or numpy.ndarray - :param verbose: verbose information (default = False) - :type verbose: bool - - :returns: - * numpy.ndarray -- fitted values (y_fit) - * numpy.ndarray -- parameters of gauss distribution function (popt: - amplitude a, expected value :math:`\\mu`, standard deviation - :math:`\\sigma`, vertical offset d) - * numpy.float64 -- full width at half maximum (FWHM) - :rtype: tuple - - .. seealso:: - :meth:`gauss` - """ - x = array(x) # cast e. g. list to numpy array - y = array(y) # cast e. g. list to numpy array - y_max = max(y) - y_max_pos = argmax(y) - x_y_max = x[y_max_pos] - - # starting parameter - p0 = [y_max, x_y_max, .1, y[0]] - if verbose: - print('p0:', end=' ') - print(p0) - if e is not None: - popt, pcov = curve_fit(gauss, x, y, p0=p0, sigma=e) - else: - popt, pcov = curve_fit(gauss, x, y, p0=p0) - if verbose: - print('popt:', end=' ') - print(popt) - #print(pcov) - - FWHM = 2*sqrt(2*log(2))*popt[2] - if verbose: - print('FWHM', FWHM) - - if x_fit is None: - x_fit = x - y_fit = gauss(x_fit, *popt) - - return y_fit, popt, FWHM
- -if __name__ == "__main__": - pass -
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/numerical/integration.html b/docs/build/html/_modules/numerical/integration.html deleted file mode 100644 index b39524c..0000000 --- a/docs/build/html/_modules/numerical/integration.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - - - - numerical.integration — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for numerical.integration

-# -*- coding: utf-8 -*-
-"""Numerical integration, numerical quadrature.
-
-de: numerische Integration, numerische Quadratur.
-
-:Date: 2015-10-15
-
-.. module:: integration
-  :platform: *nix, Windows
-  :synopsis: Numerical integration.
-
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-
-from __future__ import division
-from numpy import linspace, trapz, zeros
-
-
[docs]def trapez(f, a=0, b=1, N=10, x=None, verbose=False, - save_values=False): - r""" - Integration of :math:`f(x)` using the trapezoidal rule - (Simpson's rule, Kepler's rule). - - de: Trapezregel, Simpsonregel (Thomas Simpson), Keplersche - Fassregel (Johannes Kepler) - - :param f: function to integrate. - :type f: function or list - :param a: lower limit of integration (default = 0). - :type a: float - :param b: upper limit of integration (default = 1). - :type b: float - :param N: specify the number of subintervals. - :type N: int - :param x: variable of integration, necessary if f is a list - (default = None). - :type x: list - :param verbose: print information (default = False) - :type verbose: bool - - :returns: the definite integral as approximated by trapezoidal - rule. - :rtype: float - - The trapezoidal rule approximates the integral by the area of a - trapezoid with base h=b-a and sides equal to the values of the - integrand at the two end points. - - .. math:: - f_n(x) = f(a)+\frac{f(b)-f(a)}{b-a}(x-a) - - .. math:: - I &= \int\limits_a^b f(x) \,\mathrm{d}x \\ - I &\approx \int\limits_a^b f_n(x) \,\mathrm{d}x \\ - &= \int\limits_a^b - \left( f(a)+\frac{f(b)-f(a)}{b-a}(x-a) \right) - \mathrm{d}x \\ - &= \left.\left( f(a)-a\frac{f(b)-f(a)}{b-a} \right) - x \right\vert_a^b + - \left. \frac{f(b)-f(a)}{b-a} \frac{x^2}{2} - \right\vert_a^b \\ - &= \frac{b-a}{2}\left[f(a)+f(b)\right] - - The composite trapezium rule. If the interval is divided into n - segments (not necessarily equal) - - .. math:: - a = x_0 \leq x_1 \leq x_2 \leq \ldots \leq x_n = b - - .. math:: - I &\approx \sum\limits_{i=0}^{n-1} \frac{1}{2} (x_{i+1}-x_i) - \left[f(x_{i+1})+f(x_i)\right] \\ - - Special Case (Equaliy spaced base points) - - .. math:: - x_{i+1}-x_i = h \quad \forall i - - .. math:: - I \approx h \left\{ \frac{1}{2} \left[f(x_0)+f(x_n)\right] + - \sum\limits_{i=1}^{n-1} f(x_i) \right\} - - .. rubric:: Example - - .. math:: - I &= \int\limits_a^b f(x) \,\mathrm{d}x \\ - f(x) &= x^2 \\ - a &= 0 \\ - b &= 1 - - analytical solution - - .. math:: - I = \int\limits_{0}^{1} x^2 \,\mathrm{d}x - = \left. \frac{1}{3} x^3 \right\vert_0^1 - = \frac{1}{3} - - numerical solution - - >>> f = lambda(x): x**2 - >>> trapez(f, 0, 1, 1) - 0.5 - >>> trapez(f, 0, 1, 10) - 0.3350000000000001 - >>> trapez(f, 0, 1, 100) - 0.33335000000000004 - """ - N = int(N) - # f is function or list - if callable(f): - # h width of each subinterval - h = (b-a)/N - - # x variable of integration - x = linspace(a, b, N+1) - if save_values: - # ff contribution from the points - ff = zeros((N+1)) - for n in linspace(0, N, N+1): - ff[n] = f(x[n]) - T = (ff[0]/2.+sum(ff[1:N])+ff[N]/2.)*h - else: - TL = f(x[0]) - TR = f(x[N]) - TI = 0 - for n in range(1, N): - TI = TI + f(x[n]) - T = (TL/2.+TI+TR/2.)*h - else: - N = len(f)-1 - T = 0 - for n in range(N): - T = T + (x[n+1]-x[n])/2*(f[n+1]+f[n]) - - if verbose: - print(T) - - return T
- - -if __name__ == '__main__': - func = lambda x: x**2 - trapez(func, 0, 1, 1e6, verbose=True) - #print(trapz(func, linspace(0,1,10))) - - trapez([0, 1, 4, 9], x=[0, 1, 2, 3], verbose=True) - #print(trapz([0,1,4,9])) - - trapez([2, 2], x=[-1, 1], verbose=True) - - trapez([-1, 1, 1, -1], x=[-1, -1, 1, 1], verbose=True) -
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/numerical/ode.html b/docs/build/html/_modules/numerical/ode.html deleted file mode 100644 index 7a0edb1..0000000 --- a/docs/build/html/_modules/numerical/ode.html +++ /dev/null @@ -1,540 +0,0 @@ - - - - - - - numerical.ode — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for numerical.ode

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""Numerical solver of ordinary differential equations.
-
-Solves the initial value problem for systems of first order
-ordinary differential equations.
-
-:Date: 2015-09-21
-
-.. module:: ode
-  :platform: *nix, Windows
-  :synopsis: Numerical solver.
-
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-
-from __future__ import division, print_function
-from numpy import array, isnan, sum, zeros, dot
-from numpy.linalg import norm, inv
-
-
[docs]def e1(f, x0, t, *p, verbose=False): - r"""Explicit first-order method / - (standard, or forward) Euler method / - Runge-Kutta 1st order method. - - de: - Euler'sche Polygonzugverfahren / explizite Euler-Verfahren / - Euler-Cauchy-Verfahren / Euler-vorwärts-Verfahren - - :param f: the function to solve - :type f: function - :param x0: initial condition - :type x0: list - :param t: time - :type t: list - :param `*p`: parameters of the function (thickness, diameter, - ...) - :param verbose: print information (default = False) - :type verbose: bool - - Approximate the solution of the initial value problem - - .. math :: - \dot{x} &= f(t,x) \\ - x(t_0) &= x_0 - - Choose a value h for the size of every step and set - - .. math :: - t_i = t_0 + i h ~,\quad i=1,2,\ldots,n - - The derivative of the solution is approximated as the forward - difference equation - - .. math :: - \dot{x}_i = f(t_i, x_i) = \frac{x_{i+1} - x_i}{t_{i+1}-t_i} - - Therefore one step :math:`h` of the Euler method from - :math:`t_i` to :math:`t_{i+1}` is - - .. math :: - x_{i+1} &= x_i + (t_{i+1}-t_i) f(t_i, x_i) \\ - x_{i+1} &= x_i + h f(t_i, x_i) \\ - - Example 1: - - .. math :: - m\ddot{u} + d\dot{u} + ku = f(t) \\ - \ddot{u} = m^{-1}(f(t) - d\dot{u} - ku) \\ - - with - - .. math :: - x_1 &= u &\quad \dot{x}_1 = \dot{u} = x_2 \\ - x_2 &= \dot{u} &\quad \dot{x}_2 = \ddot{u} \\ - - becomes - - .. math :: - \dot{x}_1 &= x_2 \\ - \dot{x}_2 &= m^{-1}(f(t) - d x_2 - k x_1) \\ - - or - - .. math :: - \dot{x} &= f(t,x) \\ - \begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &= - \begin{bmatrix} x_2 \\ m^{-1}(f(t) - d x_2 - k x_1) - \end{bmatrix} \\ - &= - \begin{bmatrix} 0 \\ m^{-1} f(t) \end{bmatrix} + - \begin{bmatrix} 0 & 1 \\ -m^{-1} k & -m^{-1} d \end{bmatrix} - \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - - Example 2: - - .. math :: - m(u)\ddot{u} + d(u,\dot{u})\dot{u} + k(u)u = f(t) \\ - \ddot{u} = m^{-1}(u)(f(t) - d(u,\dot{u})\dot{u} - k(u)u) \\ - - with - - .. math :: - x_1 &= u &\quad \dot{x}_1 = \dot{u} = x_2 \\ - x_2 &= \dot{u} &\quad \dot{x}_2 = \ddot{u} \\ - - becomes - - .. math :: - \dot{x}_1 &= x_2 \\ - \dot{x}_2 &= - m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) \\ - - or - - .. math :: - \dot{x} &= f(t,x) \\ - \begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &= - \begin{bmatrix} - x_2 \\ m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) - \end{bmatrix} \\ - &= - \begin{bmatrix} 0 \\ m^{-1}(x_1) f(t) \end{bmatrix} + - \begin{bmatrix} - 0 & 1 \\ -m^{-1}(x_1) k(x_1) & -m^{-1} d(x_1,x_2) - \end{bmatrix} - \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} - - The Euler method is a first-order method, which means that the - local error (error per step) is proportional to the square of - the step size, and the global error (error at a given time) is - proportional to the step size. - """ - x = zeros((len(t), len(x0))) # Preallocate array - x[0,:] = x0 # Initial condition gives solution at first t - for i in range(len(t)-1): # Calculation loop - Dt = t[i+1]-t[i] - dxdt = array(f(x[i,:], t[i], *p)) - # Approximate solution at next value of x - x[i+1,:] = x[i,:] + dxdt*Dt - if verbose: - print('Numerical integration of ODE using explicit ' + - 'first-order method (Euler / Runge-Kutta) was successful.') - return x
- -
[docs]def e2(f, x0, t, *p, verbose=False): - r"""Explicit second-order method / Runge-Kutta 2nd order method. - - :param f: the function to solve - :type f: function - :param x0: initial condition - :type x0: list - :param t: time - :type t: list - :param `*p`: parameters of the function (thickness, diameter, - ...) - :param verbose: print information (default = False) - :type verbose: bool - """ - x = zeros((len(t), len(x0))) # Preallocate array - x[0,:] = x0 # Initial condition gives solution at first t - for i in range(len(t)-1): # Calculation loop - Dt = t[i+1]-t[i] - k_1 = array(f(x[i,:], t[i], *p)) - k_2 = array(f(x[i,:]+0.5*Dt*k_1, t[i]+0.5*Dt, *p)) - # Approximate solution at next value of x - x[i+1,:] = x[i,:] + k_2*Dt - if verbose: - print('Numerical integration of ODE using explicit ' + - '2th-order method (Runge-Kutta) was successful.') - return x
- -
[docs]def e4(f, x0, t, *p, verbose=False): - r"""Explicit fourth-order method / Runge-Kutta 4th order method. - - :param f: the function to solve - :type f: function - :param x0: initial condition - :type x0: list - :param t: time - :type t: list - :param `*p`: parameters of the function (thickness, diameter, - ...) - :param verbose: print information (default = False) - :type verbose: bool - """ - x = zeros((len(t), len(x0))) # Preallocate array - x[0,:] = x0 # Initial condition - for i in range(len(t)-1): # Calculation loop - Dt = t[i+1]-t[i] - k_1 = array(f(x[i,:], t[i], *p)) - k_2 = array(f(x[i,:]+0.5*Dt*k_1, t[i]+0.5*Dt, *p)) - k_3 = array(f(x[i,:]+0.5*Dt*k_2, t[i]+0.5*Dt, *p)) - k_4 = array(f(x[i,:]+k_3*Dt, t[i]+Dt, *p)) - # Approximate solution at next value of x - x[i+1,:] = x[i,:] + 1./6*(k_1+2*k_2+2*k_3+k_4)*Dt - if verbose: - print('Numerical integration of ODE using explicit ' + - '4th-order method (Runge-Kutta) was successful.') - return x
- -
[docs]def fpi(f, xi, ti, ti1, *p, max_iterations=1000, tol=1e-9, - verbose=False): - r"""Fixed-point iteration. - - :param f: the function to iterate :math:`f = \dot{x}(x,t)` - :type f: function - :param xi: initial condition :math:`x_i` - :type xi: list - :param ti: time :math:`t_i` - :type ti: float - :param ti1: time :math:`t_{i+1}` - :type ti1: float - :param `*p`: parameters of the function (thickness, diameter, - ...) - :param max_iterations: maximum number of iterations - :type max_iterations: int - :param tol: tolerance against residuum :math:`\varepsilon` - (default = 1e-9) - :type tol: float - :param verbose: print information (default = False) - :type verbose: bool - - :returns: :math:`x_{i}` - - .. math :: - x_{i,j=0} = x_{i} - - .. math :: - x_{i,j+1} = x_i + \dot{x}(x_{i,j}, t_{i+1})\cdot(t_{i+1}-t_i) - - .. math :: - \text{residuum} = \frac{\lVert x_{i,j+1}-x_{i,j}\rVert} - {\lVert x_{i,j+1} \rVert} < \varepsilon - - .. math :: - x_{i} = x_{i,j=\text{end}} - """ - xij = xi - for j in range(max_iterations): - dxdt = array(f(xij, ti1, *p)) - # Approximate solution at next value of x - xij1 = xi + dxdt * (ti1-ti) - residuum = norm(xij1-xij)/norm(xij1) - xij = xij1 - if residuum < tol: - break - iterations = j+1 # number beginning with 1 therefore + 1 - return xij, iterations
- -
[docs]def i1(f, x0, t, *p, max_iterations=1000, tol=1e-9, - verbose=False): - r"""Implicite first-order method / backward Euler method. - - :param f: the function to solve - :type f: function - :param x0: initial condition - :type x0: list - :param t: time - :type t: list - :param `*p`: parameters of the function (thickness, diameter, - ...) - :param max_iterations: maximum number of iterations - :type max_iterations: int - :param tol: tolerance against residuum (default = 1e-9) - :type tol: float - :param verbose: print information (default = False) - :type verbose: bool - - The backward Euler method has order one and is A-stable. - """ - iterations = zeros((len(t), 1)) - x = zeros((len(t), len(x0))) # Preallocate array - x[0,:] = x0 # Initial condition gives solution at first t - # x(i+1) = x(i) + f(x(i+1), t(i+1)), exact value of - # f(x(i+1), t(i+1)) is not available therefore using - # Newton-Raphson method - for i in range(len(t)-1): - Dt = t[i+1]-t[i] - xi = x[i,:] - xi, iteration = fpi(f, xi, t[i], t[i+1], *p, max_iterations, - tol, verbose) - x[i+1,:] = xi - iterations[i] = iteration - if verbose: - print('Numerical integration of ODE using implicite ' + - 'first-order method (Euler) was successful.') - return x, iterations
- -
[docs]def newmark_newtonraphson(f, x0, xp0, xpp0, t, *p, gamma=.5, - beta=.25, max_iterations=1000, tol=1e-9, verbose=False): - r"""Newmark method. - - :param f: the function to solve - :type f: function - :param x0: initial condition - :type x0: list - :param xp0: initial condition - :type xp0: list - :param xpp0: initial condition - :type xpp0: list - :param t: time - :type t: list - :param `*p`: parameters of the function (thickness, diameter, - ...) - :param gamma: newmark parameter for velocity (default = 0.5) - :type gamma: float - :param beta: newmark parameter for displacement (default = 0.25) - :type beta: float - :param max_iterations: maximum number of iterations - :type max_iterations: int - :param tol: tolerance against residuum (default = 1e-9) - :type tol: float - :param verbose: print information (default = False) - :type verbose: bool - """ - iterations = zeros((len(t), 1)) - x = zeros((len(t), len(x0))) # Preallocate array - xp = zeros((len(t), len(xp0))) # Preallocate array - xpp = zeros((len(t), len(xpp0))) # Preallocate array - x[0,:] = x0 # Initial condition gives solution at first t - xp[0,:] = xp0 # Initial condition gives solution at first t - xpp[0,:] = xpp0 # Initial condition gives solution at first t - for i in range(len(t)-1): - Dt = t[i+1]-t[i] - - xi = x[i,:].reshape(3,1) - xpi = xp[i,:].reshape(3,1) - xppi = xpp[i,:].reshape(3,1) - x1 = xi - xp1 = xpi - xpp1 = xppi - j = 0 - for j in range(max_iterations): # Fixed-point iteration - #dxdt = array(f(t[i+1], x1, p)) - # Approximate solution at next value of x - #x11 = x[i,:] + dxdt*Dt - - N, dN, dNp, dNpp = f(x1.reshape(-1,).tolist(), - xp1.reshape(-1,).tolist(), xpp1.reshape(-1,).tolist(), - t[i], *p) - if isnan(sum(dN)) or isnan(sum(dNp)) or isnan(sum(dNpp)): - print('divergiert') - break - - xpp11 = xpp1 - dot(inv(dNpp), (N + dot(dN, (x1-xi)) + \ - dot(dNp, (xp1-xpi)))) - xp1 = xpi + Dt*( (1-gamma)*xppi + gamma*xpp11 ) - x1 = xi + Dt*xpi + Dt**2*( (.5-beta)*xppi + beta*xpp11 ) - - residuum = norm(xpp11-xpp1)/norm(xpp11) - xpp1 = xpp11 - if residuum < tol: - break - iterations[i] = j+1 - - xpp[i+1,:] = xpp1.reshape(-1,).tolist() - xp[i+1,:] = xp1.reshape(-1,).tolist() - x[i+1,:] = x1.reshape(-1,).tolist() - if verbose: - print('Numerical integration of ODE using explicite ' + - 'newmark method was successful.') - return x, xp, xpp, iterations
- # x = concatenate((x, xp, xpp), axis=1) - -
[docs]def newmark_newtonraphson_rdk(fnm, x0, xp0, xpp0, t, *p, gamma=.5, - beta=.25, max_iterations=1000, tol=1e-9, verbose=False): - r"""Newmark method. - - :param f: the function to solve - :type f: function - :param x0: initial condition - :type x0: list - :param xp0: initial condition - :type xp0: list - :param xpp0: initial condition - :type xpp0: list - :param t: time - :type t: list - :param `*p`: parameters of the function (thickness, diameter, - ...) - :param gamma: newmark parameter for velocity (default = 0.5) - :type gamma: float - :param beta: newmark parameter for displacement (default = 0.25) - :type beta: float - :param max_iterations: maximum number of iterations - :type max_iterations: int - :param tol: tolerance against residuum (default = 1e-9) - :type tol: float - :param verbose: print information (default = False) - :type verbose: bool - """ - iterations = zeros((len(t), 1)) - x = zeros((len(t), len(x0))) # Preallocate array - xp = zeros((len(t), len(xp0))) # Preallocate array - xpp = zeros((len(t), len(xpp0))) # Preallocate array - x[0,:] = x0 # Initial condition gives solution at first t - xp[0,:] = xp0 # Initial condition gives solution at first t - xpp[0,:] = xpp0 # Initial condition gives solution at first t - for i in range(len(t)-1): - Dt = t[i+1]-t[i] - - rm, rmx, rmxpp, rd, rdx, rdxp, rk, rkx, f = fnm(x[i,:], - xp[i,:], xpp[i,:], t[i], *p) - - xi = x[i,:].reshape(3,1) - xpi = xp[i,:].reshape(3,1) - xppi = xpp[i,:].reshape(3,1) - x1 = xi - xp1 = xpi - xpp1 = xppi - j = 0 - for j in range(max_iterations): # Fixed-point iteration - #dxdt = array(f(t[i+1], x1, p)) - # Approximate solution at next value of x - #x11 = x[i,:] + dxdt*Dt - - r = (rmx+rdx+rkx)*Dt**2./4 + rdxp*Dt/2 + rmxpp - rp = f - (rm + dot(rmx, (Dt*xpi+Dt**2./4*xppi)) - \ - dot(rmxpp, xppi) + \ - rd + dot(rdx, (Dt*xpi+Dt**2./4*xppi)) + \ - dot(rdxp, Dt/2*xppi) + \ - rk + dot(rkx, (Dt*xpi+Dt**2./4*xppi)) ) - xpp11 = dot(inv(r), rp) - xp1 = xpi + Dt*( (1-gamma)*xppi + gamma*xpp11 ) - x1 = xi + Dt*xpi + Dt**2*( (.5-beta)*xppi + beta*xpp11 ) - - residuum = norm(xpp11-xpp1)/norm(xpp11) - xpp1 = xpp11 - if residuum < tol: - break - iterations[i] = j+1 - - xpp[i+1,:] = xpp1.reshape(-1,).tolist() - xp[i+1,:] = xp1.reshape(-1,).tolist() - x[i+1,:] = x1.reshape(-1,).tolist() - if verbose: - print('Numerical integration of ODE using explicite ' + - 'newmark method was successful.') - return x, xp, xpp, iterations
- # x = concatenate((x, xp, xpp), axis=1) -
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/numerical/ode_model.html b/docs/build/html/_modules/numerical/ode_model.html deleted file mode 100644 index 454d466..0000000 --- a/docs/build/html/_modules/numerical/ode_model.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - numerical.ode_model — pylib 2019.5.19 documentation - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -

Source code for numerical.ode_model

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""Mathmatical models governed by ordinary differential equations.
-
-Describes initial value problems as systems of first order ordinary differential
-equations.
-
-:Date: 2019-05-25
-
-.. module:: ode_model
-  :platform: *nix, Windows
-  :synopsis: Models of ordinary differential equations.
-
-.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
-"""
-from __future__ import division, print_function
-from numpy import array, cos, sin, dot, square
-from numpy.linalg import inv
-
-
[docs]def disk(x, t, *p): - """Rotation of an eccentric disk. - - :param x: values of the function - :type x: list - :param t: time - :type t: list - :param `*p`: parameters of the function - - * diameter - * eccentricity - * torque - """ - qp1 = x[3] - qp2 = x[4] - qp3 = x[5] - M = array([[1, 0, cos(x[2])], [0, 1, -sin(x[2])], [0, 0, 1]]) - y = array([[-2*p[0]*x[3]+sin(x[2])*x[5]**2-2*p[0]*cos(x[2])*x[5]-x[0]], \ - [-2*p[0]*x[4]+cos(x[2])*x[5]**2-2*p[0]*sin(x[2])*x[5]-x[1]], \ - [p[2]-p[1]*x[1]*sin(x[2])+p[1]*x[0]*cos(x[2])]]) - qp46 = dot(inv(M), y) - qp4, qp5, qp6 = qp46.reshape(-1,).tolist() # 2d array to 1d array to list - return qp1, qp2, qp3, qp4, qp5, qp6
- -
[docs]def disk_nm(xn, xpn, xppn, t, *p): - """Rotation of an eccentric disk. - - :param xn: values of the function - :type xn: list - :param xpn: first derivative values of the function - :type xpn: list - :param xppn: second derivative values of the function - :type xppn: list - :param t: time - :type t: list - :param `*p`: parameters of the function - - * diameter - * eccentricity - * torque - """ - N = array([[xppn[0]+cos(xn[2])*xppn[2]+2*p[0]*xpn[0]+2*p[0]*cos(xn[2])*xpn[2]-sin(xn[2])*square(xpn[2])+xn[0]], - [xppn[1]-sin(xn[2])*xppn[2]+2*p[0]*xpn[1]-2*p[0]*sin(xn[2])*xpn[2]-cos(xn[2])*square(xpn[2])+xn[1]], - [xppn[2]+p[1]*(-cos(xn[2])*xn[0]+sin(xn[2])*xn[1])-p[2]]]) - dN = array([[1, 0, -sin(xn[2]*xppn[2])-2*p[0]*sin(xn[2])*xpn[2]-cos(xn[2])*square(xpn[2])], - [0, 1, -cos(xn[2]*xppn[2])-2*p[0]*cos(xn[2])*xpn[2]+sin(xn[2])*square(xpn[2])], - [-p[1]*cos(xn[2]), p[1]*cos(xn[2]), p[1]*(sin(xn[2])*xn[0]+cos(xn[2])*xn[1])]]) - dNp = array([[2*p[0], 0, 2*p[0]*cos(xn[2])-2*sin(xn[2])*xpn[2]], - [0, 2*p[0], -2*p[0]*sin(xn[2])-2*cos(xn[2])*xpn[2]], - [0, 0, 0]]) - dNpp = array([[1, 0, cos(xn[2])], - [0, 1, -sin(xn[2])], - [0, 0, 1]]) - return N, dN, dNp, dNpp
- -
[docs]def disk_nmmdk(xn, xpn, xppn, t, *p): - """Rotation of an eccentric disk. - - :param xn: values of the function - :type xn: list - :param xpn: derivative values of the function - :type xpn: list - :param xppn: second derivative values of the function - :type xppn: list - :param t: time - :type t: list - :param `*p`: parameters of the function - - * diameter - * eccentricity - * torque - """ - rm = array([[xppn[0]+cos(xn[2])*xppn[2]], - [xppn[1]-sin(xn[2])*xppn[2]], - [xppn[2]]]) - rmx = array([[0, 0, -sin(xn[2]*xppn[2])], - [0, 0, -cos(xn[2]*xppn[2])], - [0, 0, 0]]) - rmxpp = array([[1, 0, cos(xn[2])], - [0, 1, -sin(xn[2])], - [0, 0, 1]]) - rd = array([[2*p[0]*xpn[0]+2*p[0]*cos(xn[2])*xpn[2]-sin(xn[2])*square(xpn[2])], - [2*p[0]*xpn[1]-2*p[0]*sin(xn[2])*xpn[2]-cos(xn[2])*square(xpn[2])], - [0]]) - rdx = array([[0, 0, -2*p[0]*sin(xn[2])*xpn[2]-cos(xn[2])*square(xpn[2])], - [0, 0, -2*p[0]*cos(xn[2])*xpn[2]+sin(xn[2])*square(xpn[2])], - [0, 0, 0]]) - rdxp = array([[2*p[0], 0, 2*p[0]*cos(xn[2])-2*sin(xn[2])*xpn[2]], - [0, 2*p[0], -2*p[0]*sin(xn[2])-2*cos(xn[2])*xpn[2]], - [0, 0, 0]]) - rk = array([[xn[0]], - [xn[1]], - [p[1]*(-cos(xn[2])*xn[0]+sin(xn[2])*xn[1])]]) - rkx = array([[ 1, 0, 0], - [ 0, 1, 0], - [-p[1]*cos(xn[2]), p[1]*cos(xn[2]), p[1]*(sin(xn[2])*xn[0]+cos(xn[2])*xn[1])]]) - f = array([[0], [0], [p[2]]]) - return rm, rmx, rmxpp, rd, rdx, rdxp, rk, rkx, f
- -if __name__ == '__main__': - True -
- -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/build/html/_modules/pylib/data.html b/docs/build/html/_modules/pylib/data.html index 6c1bef2..4c0b454 100644 --- a/docs/build/html/_modules/pylib/data.html +++ b/docs/build/html/_modules/pylib/data.html @@ -4,7 +4,7 @@ - pylib.data — pylib 2019.5.19 documentation + pylib.data — pylib 2019.12.21 documentation @@ -48,7 +48,7 @@ import math import pickle -
[docs]def read(file_name, x_column, y_column, default=None, verbose=False): +
[docs]def read(file_name, x_column, y_column, default=None, verbose=False): """Read ascii data file. :param filename: file to read @@ -86,7 +86,7 @@ print('data file not found') return x, y
-
[docs]def write(file_name, data): +
[docs]def write(file_name, data): """Write ascii file. :param file_name: file to write @@ -97,7 +97,7 @@ with open(file_name, 'w') as file: file.write(data)
-
[docs]def load(file_name, default=None, verbose=False): +
[docs]def load(file_name, default=None, verbose=False): """Load stored program objects from binary file. :param file_name: file to load @@ -125,7 +125,7 @@ print('no saved datas found') return object_data
-
[docs]def store(file_name, object_data): +
[docs]def store(file_name, object_data): """Store program objects to binary file. :param file_name: file to store @@ -137,7 +137,7 @@ # every dump needs a load pickle.dump(object_data, output, pickle.HIGHEST_PROTOCOL)
-
[docs]def fold_list(lst, n): +
[docs]def fold_list(lst, n): """Convert one-dimensional kx1 array (list) to two-dimensional mxn array. m = k / n @@ -154,7 +154,7 @@ length = int(k/n) return [lst[i*n:i*n+n] for i in range(length)]
-
[docs]def seq(start, stop=None, step=1): +
[docs]def seq(start, stop=None, step=1): r"""Create an arithmetic bounded sequence. The sequence is one of the following; @@ -208,7 +208,7 @@ lst = [round(start + step*i, exponent) for i in range(n)] return lst
-
[docs]def unique_ending(ids, n=1): +
[docs]def unique_ending(ids, n=1): """From id list get list with unique ending. :param ids: ids @@ -226,7 +226,7 @@ else: return x
-
[docs]def get_id(ids, uide): +
[docs]def get_id(ids, uide): """Get full id from unique id ending. :param ids: ids @@ -257,6 +257,10 @@

Navigation

+

Contents:

+

Related Topics

diff --git a/docs/build/html/_modules/pylib/date.html b/docs/build/html/_modules/pylib/date.html index 9c6de39..39ced54 100644 --- a/docs/build/html/_modules/pylib/date.html +++ b/docs/build/html/_modules/pylib/date.html @@ -4,7 +4,7 @@ - pylib.date — pylib 2019.5.19 documentation + pylib.date — pylib 2019.12.21 documentation @@ -46,7 +46,7 @@ .. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de> """ -
[docs]def gaußsche_osterformel(year): +
[docs]def gaußsche_osterformel(year): """Gaußsche Osterformel. :param year: the year to calculate the Easter Sunday @@ -95,7 +95,7 @@ os = og + oe return os
-
[docs]def easter_sunday(year): +
[docs]def easter_sunday(year): """Easter Sunday. :param year: the year to calculate the Easter Sunday @@ -108,7 +108,7 @@ day = march + datetime.timedelta(days=gaußsche_osterformel(year)) return day
-
[docs]def easter_friday(year): +
[docs]def easter_friday(year): """Easter Friday. :param year: the year to calculate the Easter Friday @@ -120,7 +120,7 @@ day = easter_sunday(year) + datetime.timedelta(days=-2) return day
-
[docs]def easter_monday(year): +
[docs]def easter_monday(year): """Easter Monday. :param year: the year to calculate the Easter Monday @@ -132,7 +132,7 @@ day = easter_sunday(year) + datetime.timedelta(days=+1) return day
-
[docs]def ascension_of_jesus(year): +
[docs]def ascension_of_jesus(year): """Ascension of Jesus. :param year: the year to calculate the ascension of Jesus @@ -144,7 +144,7 @@ day = easter_sunday(year) + datetime.timedelta(days=+39) return day
-
[docs]def pentecost(year): +
[docs]def pentecost(year): """Pentecost. :param year: the year to calculate the Pentecost @@ -173,6 +173,10 @@

Navigation

+

Contents:

+

Related Topics

diff --git a/docs/build/html/_modules/pylib/drawblock.html b/docs/build/html/_modules/pylib/drawblock.html index d163117..e1dbd2a 100644 --- a/docs/build/html/_modules/pylib/drawblock.html +++ b/docs/build/html/_modules/pylib/drawblock.html @@ -4,7 +4,7 @@ - pylib.drawblock — pylib 2019.5.19 documentation + pylib.drawblock — pylib 2019.12.21 documentation @@ -35,12 +35,23 @@

Source code for pylib.drawblock

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
+"""Draw with block characters.
 
+:Date: 2019-11-15
 
-
[docs]def histogram(f, x=None): +.. module:: drawblock + :platform: *nix, Windows + :synopsis: Draw with block characters. + +.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de> +""" + +
[docs]def histogram(f, x=None): """Histogram chart with block symbols. - dots: + :: + + dots ,_, |8| |7| @@ -52,8 +63,8 @@ |1| ``` - ▁▂▃▄▅▆▇█ - 12345678 + ▁▂▃▄▅▆▇█ + 12345678 """ from collections import defaultdict chars = defaultdict(lambda: defaultdict(int)) @@ -176,6 +187,10 @@

Navigation

+

Contents:

+

Related Topics

diff --git a/docs/build/html/_modules/pylib/function.html b/docs/build/html/_modules/pylib/function.html index fd5df8d..028da16 100644 --- a/docs/build/html/_modules/pylib/function.html +++ b/docs/build/html/_modules/pylib/function.html @@ -4,7 +4,7 @@ - pylib.function — pylib 2019.5.19 documentation + pylib.function — pylib 2019.12.21 documentation @@ -49,7 +49,7 @@ from pylib.data import seq from pylib.mathematics import lcm -
[docs]def transformation(f, scale_vertical=1, scale_horizontal=1, +
[docs]def transformation(f, scale_vertical=1, scale_horizontal=1, shift_horizontal=0, shift_vertical=0): r"""Transform functions. @@ -93,7 +93,7 @@ transformation( f[1:], scale_vertical=a, scale_horizontal=b, shift_horizontal=c, shift_vertical=d)
-
[docs]def sine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False): +
[docs]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 smooth periodic oscillation. @@ -154,7 +154,7 @@ phi = math.radians(phi) return lambda x, t=0: A*math.sin(k*x + 2*math.pi*f*t + phi) + D
-
[docs]def cosine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False): +
[docs]def cosine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False): r"""A cosine wave is said to be sinusoidal, because, :math:`\cos(x) = \sin(x + \pi/2)`, which is also a sine wave with a phase-shift of π/2 radians. Because of this head start, it is often @@ -194,7 +194,7 @@ # roulette # -
[docs]def hypotrochoid(R, r, d): +
[docs]def hypotrochoid(R, r, d): r"""Hypotrochoid A point is attached with a distance d from the center of a circle @@ -242,7 +242,7 @@ theta_end = 2*math.pi*lcm(r, R)/R return x, y, theta_end
-
[docs]def epitrochoid(R, r, d): +
[docs]def epitrochoid(R, r, d): r"""Epitrochoid A point is attached with a distance d from the center of a circle @@ -287,7 +287,7 @@ theta_end = 2*math.pi return x, y, theta_end
-
[docs]def to_str(f, x=None, x_0=0, x_1=1, t=None, h=10, w=80, density=1, char_set="line"): +
[docs]def to_str(f, x=None, x_0=0, x_1=1, t=None, h=10, w=80, density=1, char_set="line"): """Represent functions as string frame with a specific character set. which are normed to the range of [0, 1] to @@ -468,6 +468,10 @@

Navigation

+

Contents:

+

Related Topics

diff --git a/docs/build/html/_modules/pylib/geometry.html b/docs/build/html/_modules/pylib/geometry.html index 3787977..c32d4c7 100644 --- a/docs/build/html/_modules/pylib/geometry.html +++ b/docs/build/html/_modules/pylib/geometry.html @@ -4,7 +4,7 @@ - pylib.geometry — pylib 2019.5.19 documentation + pylib.geometry — pylib 2019.12.21 documentation @@ -37,7 +37,7 @@ # -*- coding: utf-8 -*- """2D geometry objects. -:Date: 2019-08-28 +:Date: 2019-12-21 .. module:: geometry :platform: *nix, Windows @@ -46,504 +46,218 @@ .. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de> """ import math -import numpy as np +import copy +from mathematics import vector, matrix +
[docs]class Direction(vector): + """Direction in local coordinate system""" + def __init__(self, x=1, y=0, z=0): + super().__init__([x, y, z, 0]) -
[docs]def distance(point1, point2): - """Distance between two points (or length of a straight line). + def __str__(self): + return str(self.xyz())
- :param point1: first point (first end point of straight line) - :type point1: tuple - :param point2: second point (second end point of straight line) - :type point2: tuple +
[docs]class Point(vector): + """Point in local coordinate system""" + def __init__(self, x=0, y=0, z=0): + super().__init__([x, y, z, 1]) - :returns: distance between the two points - :rtype: float + def __str__(self): + return str(self.xyz())
+ +
[docs]class CS(matrix): + """Coordinate system """ - return math.sqrt((point2[0]-point1[0])**2 + (point2[1]-point1[1])**2)
+ def __init__(self, x=[1, 0, 0], y=[0, 1, 0], z=[0, 0, 1]): + super().__init__([[*x, 0], [*y, 0], [*z, 0], [0, 0, 0, 1]]) + def __str__(self): + return '[' + ', '.join([str(i) for i in self.get_coordinates()]) + ']' -
[docs]def angle(point1, point2=None): - """Angle of point or between two points. +
[docs] @staticmethod + def x90(): + return CS((1, 0, 0), (0, 0, -1), (0, 1, 0))
- :param point1: (first) point - :type point1: tuple - :param point2: second point (default = None) - :type point2: tuple +
[docs] @staticmethod + def xm90(): + return CS((1, 0, 0), (0, 0, 1), (0, -1, 0))
- :returns: angle of point or between two points - :rtype: float +
[docs] @staticmethod + def y90(): + return CS((0, 0, 1), (0, 1, 0), (-1, 0, 0))
+ +
[docs] @staticmethod + def ym90(): + return CS((0, 0, -1), (0, 1, 0), (1, 0, 0))
+ +
[docs] def get_coordinates(self): + """Get coordinates in 3d space""" + return self[:3,:3]
+ +
[docs]class World(): + """World-space with world-space coordinates """ - if point2 is None: - return math.atan2(point1[1], point1[0]) - return math.atan2(point2[1]-point1[1], point2[0]-point1[0])
+ def __init__(self): + self._cs = CS() # Camera + self._objects = [] + self._store_init() + def __iter__(self): + """Returns the Iterator object""" + return iter(self.objects()) -
[docs]def translate(vec, *pts): - """Translate a point or polygon by a given vector. + def _store_init(self): + """Initialize or reset calculated values, because a new object was added. + """ + self._bb = None + self._sd = None - :param vec: translation vector - :type vec: tuple - :param `*pts`: points to translate +
[docs] def cs(self, cs=None): + if cs: + self._cs = cs + return self._cs
- :returns: (point_x, point_y) or (point1, point2, ...) - :rtype: tuple +
[docs] def ch_cs(self, cs): + self._cs = self._cs * cs + return self
- .. seealso:: - :meth:`translate_xy` +
[docs] def rotate_x(self, theta): + self._cs.rotate_x(theta) + return self
+ +
[docs] def rotate_y(self, theta): + self._cs.rotate_y(theta) + return self
+ +
[docs] def rotate_z(self, theta): + self._cs.rotate_z(theta) + return self
+ +
[docs] def translate(self, tx, ty, tz): + self._cs.translate(tx, ty, tz) + return self
+ +
[docs] def scale(self, sx, sy=None, sz=None): + self._cs.scale(sx, sy, sz) + return self
+ +
[docs] def objects(self): + return [copy.deepcopy(i).ch_cs(self._cs) for i in self._objects]
+ +
[docs] def add(self, *objects): + self._store_init() # calculated values are not correct anymore + [self._objects.append(i) for i in objects] + return self
+ +
[docs] def bounding_box(self): + if self._bb is not None: + return self._bb + + xmin = math.inf + ymin = math.inf + zmin = math.inf + xmax = -math.inf + ymax = -math.inf + zmax = -math.inf + for i in self._objects: + xi, yi, zi = map(min, i.xyz()) + xs, ys, zs = map(max, i.xyz()) + #xmax = x if x > xmax: xmax = x + xmin = xi if xi < xmin else xmin + ymin = yi if yi < ymin else ymin + zmin = zi if zi < zmin else zmin + xmax = xs if xs > xmax else xmax + ymax = ys if ys > ymax else ymax + zmax = zs if zs > zmax else zmax + + self._bb = xmin, xmax, ymin, ymax, zmin, zmax + return self._bb
+ +
[docs] def space_diagonal(self): + if self._sd is not None: + return self._sd + + bb = self.bounding_box() + a, b, c = bb[1]-bb[0], bb[3]-bb[2], bb[5]-bb[4] + return math.sqrt(a**2+b**2+c**2)
+ +
[docs] def center(self): + bb = self.bounding_box() + self.ch_cs([[1,0,0,-(bb[1]-bb[0])/2],[0,1,0,-(bb[3]-bb[2])/2],[0,0,1,-(bb[5]-bb[4])/2],[0,0,0,1]]) + return self
+ +# TODO: Wireframe(list) or Wireframe(matrix) ? +# list of Points +
[docs]class Wireframe(): + """Open and closed wireframe object in local coordinate system + + This class create its own points (copy). """ - vx, vy = vec - return tuple([(x+vx, y+vy) for (x, y) in pts])
- - -
[docs]def translate_xy(vec, x, y): - """Translate a point or polygon by a given vector. - - :param vec: translation vector - :type vec: tuple - :param x: points to translate - :type x: int or float or list - :param y: points to translate - :type y: int or float or list - - :returns: (x', y') - :rtype: tuple - - .. seealso:: - :meth:`translate` - """ - vx, vy = vec - - if not hasattr(x, "__len__"): - x = [x] - - if not hasattr(y, "__len__"): - y = [y] - - xp = [xi+vx for xi in x] - yp = [yi+vy for yi in y] - - # no list if it is only one value - if len(xp) == 1: - return xp[0], yp[0] - - return xp, yp
- - -
[docs]def rotate(origin, angle, *pts, **kwargs): - """Rotate a point or polygon counterclockwise by a given angle - around a given origin. The angle should be given in radians. - - :param origin: the center of rotation - :type origin: tuple - :param angle: the rotation angle - :type angle: int or float - :param `*pts`: points to rotate - :param `**kwargs`: options - - :returns: (point_x, point_y) or (point1, point2, ...) - :rtype: tuple - - .. seealso:: - :meth:`rotate_xy` - """ - ox, oy = origin - - # add first point to the end - if "closed" in kwargs and kwargs["closed"] is True: - pts += (pts[0],) - - result = tuple([(ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy), - oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy)) - for (px, py) in pts]) - - # no tuple in tuple if it is only one point - if len(pts) == 1: - return result[0][0], result[0][1] - - return result
- - -
[docs]def rotate_deg(origin, angle, *pts, **kwargs): - """Rotate a point or polygon counterclockwise by a given angle - around a given origin. The angle should be given in degrees. - - :param origin: the center of rotation - :type origin: tuple - :param angle: the rotation angle - :type angle: int or float - :param `*pts`: points to rotate - :param `**kwargs`: options - - :returns: (point_x, point_y) or (point1, point2, ...) - :rtype: tuple - - .. seealso:: - :meth:`rotate` - """ - return rotate(origin, angle*math.pi/180, *pts, **kwargs)
- - -
[docs]def rotate_xy(origin, angle, x, y, **kwargs): - """Rotate x and y coordinates counterclockwise by a given angle - around a given origin. The angle should be given in radians. - - :param origin: the center of rotation - :type origin: tuple - :param angle: the rotation angle - :type angle: int or float - :param x: x coordinates - :type x: int or float or list - :param y: y coordinates - :type y: int or float or list - :param `**kwargs`: options - - .. seealso:: - :meth:`rotate` - """ - ox, oy = origin - - if not hasattr(x, "__len__"): - x = [x] - - if not hasattr(y, "__len__"): - y = [y] - - # add first point to the end - if "closed" in kwargs and kwargs["closed"] is True: - x.append(x[0]) - y.append(y[0]) - - x_result = [ox + math.cos(angle) * (xi - ox) - math.sin(angle) * (yi - oy) - for xi, yi in zip(x, y)] - - y_result = [oy + math.sin(angle) * (xi - ox) + math.cos(angle) * (yi - oy) - for xi, yi in zip(x, y)] - - # no list if it is only one value - if len(x_result) == 1: - return x_result[0], y_result[0] - - return x_result, y_result
- - -
[docs]def rectangle(width, height): - """\ - :param width: the width of the rectangle - :type width: int or float - :param height: the height of the rectangle - :type height: int or float - - :returns: (point1, point2, point3, point4) - :rtype: tuple - """ - pt1 = (-width/2, -height/2) - pt2 = (width/2, -height/2) - pt3 = (width/2, height/2) - pt4 = (-width/2, height/2) - return pt1, pt2, pt3, pt4, pt1
- - -
[docs]def square(width): - """\ - :param width: the edge size of the square - :type width: int or float - - :returns: (point1, point2, point3, point4) - :rtype: tuple - - .. seealso:: - :meth:`rectangle` - """ - return rectangle(width, width)
- - -
[docs]def lines(pts, **kwargs): - """Lines defined by a list of end points. - - :param pts: list of points in absolute global coordinate system. If - keyword inc is given than the inc decides what the left and the - right end point of the line is, otherwise it is assumed that the - points build a solid line, that is lines between the given points - in given order. - :type pts: list - - :param `**kwargs`: options: - - * deformation -- list of points. Additional deformation - (translation) at point. - * factor -- factor of the deformation (default = 1). - * inc -- the incidence table, a list of 2 element lists. The inc - decides what the left and the right end point of the line is. - * index_offset -- starting index of lists (default = 0). - - :returns: list of endpoints for each line; - [((point1_x, point1_y), (point2_x, point2_y)), - (p1, p2), - ...] - :rtype: list - - .. seealso:: - :meth:`~geometry_plot.plot_lines` of the :mod:`geometry_plot` - module to plot the lines - """ - if 'index_offset' not in kwargs: - kwargs['index_offset'] = 0 - if 'deformation' in kwargs: - if 'factor' not in kwargs: - kwargs['factor'] = 1 - pts = [(p[0]+d[0]*kwargs['factor'], p[1]+d[1]*kwargs['factor']) for - p, d in zip(pts, kwargs['deformation'])] - if 'inc' in kwargs: - return [(pts[l-kwargs['index_offset']], - pts[r-kwargs['index_offset']]) for l, r in kwargs['inc']] - return list(zip(pts[:-1], pts[1:]))
- - -
[docs]def cubics(pts, **kwargs): - """Cubic lines defined by a list of two end points. The deformation - as displacement and rotation (radians) is defined element wise as - keyword argument deformation or global node wise as - global_deformation. The global coordinate system is xy. x in the - right direction and y in the top direction. - - :param pts: list of points in absolute global coordinate system. If - keyword inc is given than the inc decides what the left and the - right end point of the line is, otherwise it is assumed that the - points build a solid line, that is lines between the given points - in given order. - :type pts_rot: list - - :param `**kwargs`: options: - - * deformation -- list of deformation element wise. Additional - deformation (translation and rotation in radians) at element - left and right node. - * rotation_plane -- rotation plane of the element wise - deformation defined by a string; either 'xy' or 'xz' (default - = 'xy'). x in the right direction and y in the top direction - or z in the bottom direction. - * global_deformation -- list of deformation global node wise. - Additional deformation (horizontal translation, vertical - translation and rotation in radians) at node. - * factor -- factor of the derformation (default = 1). - * inc -- the incidence table, a list of 2 element lists. The inc - decides what the left and the right end point of the line is. - * index_offset -- starting index of lists (default = 0). - - :returns: list of endpoints for each line; - [(((point1_x, point1_y) angle1), ((point2_x, point2_y), angle2), - (p1, angle1, p2, angle2), - ...] - :rtype: list - """ - if 'index_offset' not in kwargs: - kwargs['index_offset'] = 0 - if 'deformation' in kwargs or 'global_deformation' in kwargs: - if 'factor' not in kwargs: - kwargs['factor'] = 1 - if 'inc' in kwargs: - if 'global_deformation' in kwargs: - lr = [(pts[l-kwargs['index_offset']], - pts[r-kwargs['index_offset']]) for l, r in kwargs['inc']] - ang = [angle(l, r) for l, r in lr] - # system deformation - U = kwargs['global_deformation'] - if 'rotation_plane' in kwargs and 'xz' == kwargs['rotation_plane']: - # system deformation left X Z RY right X Z RY element wise - # Z downwards -> convert to X Y RZ - Ue = [[ U[(l-kwargs['index_offset'])][0], - -U[(l-kwargs['index_offset'])][1], - U[(l-kwargs['index_offset'])][2], - U[(r-kwargs['index_offset'])][0], - -U[(r-kwargs['index_offset'])][1], - U[(r-kwargs['index_offset'])][2]] for l, r in kwargs['inc']] - else: - # system deformation left X Y RZ right X Y RZ element wise - Ue = [[U[(l-kwargs['index_offset'])][0], - U[(l-kwargs['index_offset'])][1], - U[(l-kwargs['index_offset'])][2], - U[(r-kwargs['index_offset'])][0], - U[(r-kwargs['index_offset'])][1], - U[(r-kwargs['index_offset'])][2]] for l, r in kwargs['inc']] - # element deformation, X Y RZ to x r rz - # back transformation T^T = [[c, s, 0], [-s, c, 0], [0, 0, 1]] - u = [[( math.cos(angi)*Uei[0]+math.sin(angi)*Uei[1])*kwargs['factor'], - (-math.sin(angi)*Uei[0]+math.cos(angi)*Uei[1])*kwargs['factor'], - Uei[2] *kwargs['factor'], - ( math.cos(angi)*Uei[3]+math.sin(angi)*Uei[4])*kwargs['factor'], - (-math.sin(angi)*Uei[3]+math.cos(angi)*Uei[4])*kwargs['factor'], - Uei[5] *kwargs['factor']] - for Uei, angi in zip(Ue, ang)] - else: # deformation - # the deformation is in element coordinate system, therefore the angle is needed - if 'rotation_plane' in kwargs and 'xz' == kwargs['rotation_plane']: - u = [[ ue[0]*kwargs['factor'], - -ue[1]*kwargs['factor'], - ue[2]*kwargs['factor'], - ue[3]*kwargs['factor'], - -ue[4]*kwargs['factor'], - ue[5]*kwargs['factor']] for ue in kwargs['deformation']] - else: - u = [[ui*kwargs['factor'] for ui in ue] for ue in kwargs['deformation']] - return [(pts[l-kwargs['index_offset']], - pts[r-kwargs['index_offset']], - d) for (l, r), d in zip(kwargs['inc'], u)] - return list(zip(pts[:-1], pts[1:]))
- - -
[docs]def interpolate_hermite(lvd, lr, rvd, rr, lhd=0, rhd=0, scale_x=1, scale_y=1, samples=10): - r"""Interpolate cubic line with hermite boundary conditions. - - :param lvd: left vertcal deflection - :type lvd: int or float - :param lr: left rotation - :type lr: int or float - :param rvd: right vertical deflection - :type rvd: int or float - :param rr: right rotation - :type rr: int or float - :param lhd: left horizontal deformation (default = 0) - :type lhd: int or float - :param rhd: right horizontal deformation (default = 0) - :type rhd: int or float - :param scale_x: length of element (default = 1) - :type scale_x: int or float - :param scale_y: factor of the deformation (default = 1). - This does not change the length. - :type scale_y: int or float - :param samples: number of sampling points (default = 10) - :type samples: int - - .. math:: - s = \frac{x - x_1}{L} \\ - x = s\,L + x_1 - - """ - L = scale_x - Lp = L + rhd - lhd - - # x=[0,1] in non-dimensional coordinates - x = np.linspace(0, 1, num=samples) - N1 = 1 - 3*x**2 + 2*x**3 - N2 = ( x - 2*x**2 + x**3)*Lp - N3 = 3*x**2 - 2*x**3 - N4 = ( - x**2 + x**3)*Lp - x = x*Lp - - - # x=[0,L] in global coordinates - x = np.linspace(0, Lp, num=samples) - N1 = 1 - 3*x**2/Lp**2 + 2*x**3/Lp**3 - N2 = x - 2*x**2/Lp + x**3/Lp**2 - N3 = 3*x**2/Lp**2 - 2*x**3/Lp**3 - N4 = - x**2/Lp + x**3/Lp**2 - - - v = N1*lvd + N2*lr + N3*rvd + N4*rr - x = x + lhd - y = v*scale_y - - return x, y
- - -# -# matplotlib format, return lists for x and y -# - -
[docs]def line(point1, point2, samples=2): - """Line defined by two end points. - - .. math:: - y = \\frac{y_2-y_1}{x_2-x_1}(x-x_1) + y_1 - - :param point1: one end point - :type point1: tuple - :param point2: other end point - :type point2: tuple - :param samples: number of sampling points (default = 2) - :type samples: int - - :returns: ((point1_x, point2_x), (points1_y, point2_y)) or - ([sample_point1_x, sample_point2_x, ...], - [sample_points1_y, sample_point2_y, ...]) - :rtype: tuple - - :Example: - - >>> x, y = line((0, 0), (1, 0)) - >>> print(x, y) - ((0, 1), (0, 0)) - """ - p1x, p1y = point1 - p2x, p2y = point2 - - denominator = (p1x - p2x) - - if samples > 2 and denominator > 0: - x = np.linspace(p1x, p2x, samples) - a = (p1y - p2y) / denominator - b = (p1x*p2y - p2x*p1y) / denominator - y = a*x + b - return x, y - return (p1x, p2x), (p1y, p2y) # matplotlib format
- - -
[docs]def cubic(point1, angle1, point2, angle2, samples=10): - """Cubic line defined by two end points and the rotation in radians - at the points. - - :param point1: one end point - :type point1: tuple - :param angle1: the slope at the one end point - :type angle1: int or float - :param point2: other end point - :type point2: tuple - :param angle2: the slope at the other end point - :type angle2: int or float - :param samples: number of sampling points (default = 10) - :type samples: int - - :returns: ([sample_point1_x, sample_point2_x, ...], - [sample_points1_y, sample_point2_y, ...]) - :rtype: tuple - """ - p1x, p1y = point1 - p2x, p2y = point2 - - x = np.linspace(p1x, p2x, num=samples) - - p1ys = math.tan(angle1) - p2ys = math.tan(angle2) - a = (p1x*p1ys + p1x*p2ys - p2x*p1ys - p2x*p2ys - 2*p1y + 2*p2y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) - b = (- p1x**2*p1ys - 2*p1x**2*p2ys - p1x*p2x*p1ys + p1x*p2x*p2ys + 3*p1x*p1y - 3*p1x*p2y + 2*p2x**2*p1ys + p2x**2*p2ys + 3*p2x*p1y - 3*p2x*p2y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) - c = (p1x**3*p2ys + 2*p1x**2*p2x*p1ys + p1x**2*p2x*p2ys - p1x*p2x**2*p1ys - 2*p1x*p2x**2*p2ys - 6*p1x*p2x*p1y + 6*p1x*p2x*p2y - p2x**3*p1ys)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) - d = (- p1x**3*p2x*p2ys + p1x**3*p2y - p1x**2*p2x**2*p1ys + p1x**2*p2x**2*p2ys - 3*p1x**2*p2x*p2y + p1x*p2x**3*p1ys + 3*p1x*p2x**2*p1y - p2x**3*p1y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) - y = a*x**3 + b*x**2 + c*x + d - return x, y
- - -
[docs]def cubic_deg(point1, angle1, point2, angle2): - """Cubic line defined by two end points and the roation in degree - at the points. - - :param point1: one end point - :type point1: tuple - :param angle1: the slope at the one end point - :type angle1: int or float - :param point2: other end point - :type point2: tuple - :param angle2: the slope at the other end point - :type angle2: int or float - - :returns: ([sample_point1_x, sample_point2_x, ...], - [sample_points1_y, sample_point2_y, ...]) - :rtype: tuple - - .. seealso:: - :meth:`cubic` - """ - return cubic(point1, angle1 * math.pi/180, point2, angle2 * math.pi/180)
+ def __init__(self, *points, closed=False): + self._points = [copy.copy(i) for i in points] + self.closed = closed + + def __str__(self): + return '[' + ', '.join([str(point) for point in self._points]) + ']' + + def __iter__(self): + """Returns the Iterator object""" + return iter(self.points()) + +
[docs] def points(self): + """Get coordinates in 3d space""" + result = [i for i in self._points] + return result if not self.closed else result + [result[0]]
+ +
[docs] def xyz(self): + return zip(*[i.xyz() for i in self.points()])
+ +
[docs] def rotate_x(self, theta): + self._points = [point.rotate_x(theta) for point in self._points] + return self
+ +
[docs] def rotate_y(self, theta): + self._points = [point.rotate_y(theta) for point in self._points] + return self
+ +
[docs] def rotate_z(self, theta): + self._points = [point.rotate_z(theta) for point in self._points] + return self
+ +
[docs] def translate(self, tx, ty, tz): + self._points = [point.translate(tx, ty, tz) for point in self._points] + return self
+ +
[docs] def scale(self, sx, sy=None, sz=None): + if not sy: + sy = sx + sz = sx + self._points = [point.scale(sx, sy, sz) for point in self._points] + return self
+ +
[docs] def ch_cs(self, cs): + self._points = [point.ch_cs(cs) for point in self._points] + return self
+ +
[docs]class Line(Wireframe): + """Line a open wireframe object in local coordinate system""" + def __init__(self, point1=Point(-1, 0, 0), point2=Point(1, 0, 0)): + super().__init__(point1, point2)
+ +
[docs]class Polygon(Wireframe): + """Polygon as closed wireframe object in local coordinate system""" + def __init__(self, *points): + super().__init__(*points, closed=True)
+ +
[docs]class Circle(Polygon): + """Circle a closed wireframe object in local coordinate system""" + def __init__(self, radius=1, n=10): + points = [] + for i in range(n): + x = radius * math.sin(i*2*math.pi/n) + y = radius * math.cos(i*2*math.pi/n) + points.append(Point(x, y, 0)) + super().__init__(*points)
@@ -562,6 +276,10 @@

Navigation

+

Contents:

+

Related Topics

diff --git a/docs/build/html/_modules/geometry.html b/docs/build/html/_modules/pylib/geometry2d.html similarity index 90% rename from docs/build/html/_modules/geometry.html rename to docs/build/html/_modules/pylib/geometry2d.html index fcc5e19..7324af0 100644 --- a/docs/build/html/_modules/geometry.html +++ b/docs/build/html/_modules/pylib/geometry2d.html @@ -4,20 +4,20 @@ - geometry — pylib 2019.5.19 documentation - - - - - - - - + pylib.geometry2d — pylib 2019.12.21 documentation + + + + + + + + - - + + - + @@ -32,16 +32,16 @@
-

Source code for geometry

+  

Source code for pylib.geometry2d

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 """2D geometry objects.
 
 :Date: 2019-08-28
 
-.. module:: geometry
+.. module:: geometry2d
   :platform: *nix, Windows
-  :synopsis: Geometry objects.
+  :synopsis: 2D geometry objects.
 
 .. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
 """
@@ -49,7 +49,7 @@
 import numpy as np
 
 
-
[docs]def distance(point1, point2): +
[docs]def distance(point1, point2): """Distance between two points (or length of a straight line). :param point1: first point (first end point of straight line) @@ -63,7 +63,7 @@ return math.sqrt((point2[0]-point1[0])**2 + (point2[1]-point1[1])**2)
-
[docs]def angle(point1, point2=None): +
[docs]def angle(point1, point2=None): """Angle of point or between two points. :param point1: (first) point @@ -79,7 +79,7 @@ return math.atan2(point2[1]-point1[1], point2[0]-point1[0])
-
[docs]def translate(vec, *pts): +
[docs]def translate(vec, *pts): """Translate a point or polygon by a given vector. :param vec: translation vector @@ -96,7 +96,7 @@ return tuple([(x+vx, y+vy) for (x, y) in pts])
-
[docs]def translate_xy(vec, x, y): +
[docs]def translate_xy(vec, x, y): """Translate a point or polygon by a given vector. :param vec: translation vector @@ -130,7 +130,7 @@ return xp, yp
-
[docs]def rotate(origin, angle, *pts, **kwargs): +
[docs]def rotate(origin, angle, *pts, **kwargs): """Rotate a point or polygon counterclockwise by a given angle around a given origin. The angle should be given in radians. @@ -164,7 +164,7 @@ return result
-
[docs]def rotate_deg(origin, angle, *pts, **kwargs): +
[docs]def rotate_deg(origin, angle, *pts, **kwargs): """Rotate a point or polygon counterclockwise by a given angle around a given origin. The angle should be given in degrees. @@ -184,7 +184,7 @@ return rotate(origin, angle*math.pi/180, *pts, **kwargs)
-
[docs]def rotate_xy(origin, angle, x, y, **kwargs): +
[docs]def rotate_xy(origin, angle, x, y, **kwargs): """Rotate x and y coordinates counterclockwise by a given angle around a given origin. The angle should be given in radians. @@ -227,7 +227,7 @@ return x_result, y_result
-
[docs]def rectangle(width, height): +
[docs]def rectangle(width, height): """\ :param width: the width of the rectangle :type width: int or float @@ -244,7 +244,7 @@ return pt1, pt2, pt3, pt4, pt1
-
[docs]def square(width): +
[docs]def square(width): """\ :param width: the edge size of the square :type width: int or float @@ -258,7 +258,7 @@ return rectangle(width, width)
-
[docs]def lines(pts, **kwargs): +
[docs]def lines(pts, **kwargs): """Lines defined by a list of end points. :param pts: list of points in absolute global coordinate system. If @@ -300,7 +300,7 @@ return list(zip(pts[:-1], pts[1:]))
-
[docs]def cubics(pts, **kwargs): +
[docs]def cubics(pts, **kwargs): """Cubic lines defined by a list of two end points. The deformation as displacement and rotation (radians) is defined element wise as keyword argument deformation or global node wise as @@ -392,7 +392,7 @@ return list(zip(pts[:-1], pts[1:]))
-
[docs]def interpolate_hermite(lvd, lr, rvd, rr, lhd=0, rhd=0, scale_x=1, scale_y=1, samples=10): +
[docs]def interpolate_hermite(lvd, lr, rvd, rr, lhd=0, rhd=0, scale_x=1, scale_y=1, samples=10): r"""Interpolate cubic line with hermite boundary conditions. :param lvd: left vertcal deflection @@ -451,7 +451,7 @@ # matplotlib format, return lists for x and y # -
[docs]def line(point1, point2, samples=2): +
[docs]def line(point1, point2, samples=2): """Line defined by two end points. .. math:: @@ -489,7 +489,7 @@ return (p1x, p2x), (p1y, p2y) # matplotlib format
-
[docs]def cubic(point1, angle1, point2, angle2, samples=10): +
[docs]def cubic(point1, angle1, point2, angle2, samples=10): """Cubic line defined by two end points and the rotation in radians at the points. @@ -523,7 +523,7 @@ return x, y
-
[docs]def cubic_deg(point1, angle1, point2, angle2): +
[docs]def cubic_deg(point1, angle1, point2, angle2): """Cubic line defined by two end points and the roation in degree at the points. @@ -552,7 +552,7 @@
-
-static abs(a)[source]
+
+static abs(a)[source]

Return modulus parts of a complex vector

-
-static ang(a, b)[source]
+
+static ang(a, b)[source]
-
-static arg(a)[source]
+
+static arg(a)[source]

Return phase parts of a complex vector

-
-ch_cs(cs)[source]
+
+ch_cs(cs)[source]

Transform this vector from its defined coordinate system to a new coordinate system, defined by the given coordinate system (u, v and w direction vectors).

@@ -383,16 +385,16 @@ v and w direction vectors).

-
-static conjugate(a)[source]
+
+static conjugate(a)[source]

New vector object

-
-static cross(a, b)[source]
+
+static cross(a, b)[source]

Cross product

@@ -403,8 +405,8 @@ The direction of c can be found with the right-hand rule.

-
-static full(length, fill_value)[source]
+
+static full(length, fill_value)[source]

Returns a vector of length m or matrix of size m rows, n columns filled with v.

@@ -428,16 +430,16 @@ columns filled with v.

-
-static im(a)[source]
+
+static im(a)[source]

Return the imaginary parts of a complex vector

-
-static normalize(a)[source]
+
+static normalize(a)[source]

Normalize a vector (i. e. the vector has a length of 1)

@@ -450,8 +452,8 @@ columns filled with v.

-
-static ones(length)[source]
+
+static ones(length)[source]

Returns a vector of length m or matrix of size rows, n columns filled with ones.

@@ -469,8 +471,8 @@ columns filled with ones.

-
-static random(shape, lmin=0.0, lmax=1.0)[source]
+
+static random(shape, lmin=0.0, lmax=1.0)[source]

Returns a random vector of length n or matrix of size m rows, n columns filled with random numbers.

@@ -488,16 +490,16 @@ columns filled with random numbers.

-
-static re(a)[source]
+
+static re(a)[source]

Return the real parts of a complex vector

-
-rotate_x(theta)[source]
+
+rotate_x(theta)[source]

Rotation about the x dirction.

\[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = @@ -511,8 +513,8 @@ columns filled with random numbers.

-
-rotate_y(theta)[source]
+
+rotate_y(theta)[source]

Rotation about the y dirction.

\[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = @@ -526,8 +528,8 @@ columns filled with random numbers.

-
-rotate_z(theta)[source]
+
+rotate_z(theta)[source]

Rotation about the z dirction.

\[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = @@ -541,8 +543,8 @@ columns filled with random numbers.

-
-scale(sx, sy=None, sz=None)[source]
+
+scale(sx, sy=None, sz=None)[source]

Scaling

uniform scaling if sx=sy=sz=s. Note that scaling happens around the origin, so objects not @@ -562,8 +564,8 @@ it should be.

-
-translate(tx, ty, tz)[source]
+
+translate(tx, ty, tz)[source]

Translation

\[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = @@ -577,13 +579,13 @@ it should be.

-
-xyz()[source]
+
+xyz()[source]
-
-static zeros(length)[source]
+
+static zeros(length)[source]

Returns a zero vector of length m or matrix of size rows, n columns filled with zeros.

@@ -621,11 +623,24 @@ columns filled with zeros.

Navigation

+

Contents:

+ @@ -659,7 +674,7 @@ columns filled with zeros.

& Alabaster 0.7.12 | - Page source
diff --git a/docs/build/html/pylib.numerical.fit.html b/docs/build/html/pylib.numerical.fit.html new file mode 100644 index 0000000..d765b81 --- /dev/null +++ b/docs/build/html/pylib.numerical.fit.html @@ -0,0 +1,189 @@ + + + + + + + pylib.numerical.fit module — pylib 2019.12.21 documentation + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+ +
+

pylib.numerical.fit module

+

Function and approximation.

+
+
Date
+

2019-10-15

+
+
+
+
+gauss(x, *p)[source]
+

Gauss distribution function.

+
+\[f(x)=ae^{-(x-b)^{2}/(2c^{2})}\]
+
+
Parameters
+
    +
  • x (int or float or list or numpy.ndarray) – positions where the gauss function will be calculated

  • +
  • p (list) –

    gauss parameters [a, b, c, d]:

    +
      +
    • a – amplitude (\(\int y \,\mathrm{d}x=1 \Leftrightarrow a=1/(c\sqrt{2\pi})\) )

    • +
    • b – expected value \(\mu\) (position of maximum, default = 0)

    • +
    • c – standard deviation \(\sigma\) (variance \(\sigma^2=c^2\))

    • +
    • d – vertical offset (default = 0)

    • +
    +

  • +
+
+
Returns
+

gauss values at given positions x

+
+
Return type
+

numpy.ndarray

+
+
+
+ +
+
+gauss_fit(x, y, e=None, x_fit=None, verbose=False)[source]
+

Fit Gauss distribution function to data.

+
+
Parameters
+
    +
  • x (int or float or list or numpy.ndarray) – positions

  • +
  • y (int or float or list or numpy.ndarray) – values

  • +
  • e (int or float or list or numpy.ndarray) – error values (default = None)

  • +
  • x_fit (int or float or list or numpy.ndarray) – positions of fitted function (default = None, if None then x +is used)

  • +
  • verbose (bool) – verbose information (default = False)

  • +
+
+
Returns
+

    +
  • numpy.ndarray – fitted values (y_fit)

  • +
  • numpy.ndarray – parameters of gauss distribution function (popt: +amplitude a, expected value \(\mu\), standard deviation +\(\sigma\), vertical offset d)

  • +
  • numpy.float64 – full width at half maximum (FWHM)

  • +
+

+
+
Return type
+

tuple

+
+
+
+

See also

+

gauss()

+
+
+ +
+ + +
+ +
+
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/docs/build/html/pylib.numerical.html b/docs/build/html/pylib.numerical.html index 5e80ba4..687cd80 100644 --- a/docs/build/html/pylib.numerical.html +++ b/docs/build/html/pylib.numerical.html @@ -4,7 +4,7 @@ - pylib.numerical package — pylib 2019.5.19 documentation + pylib.numerical package — pylib 2019.12.21 documentation @@ -16,6 +16,8 @@ + + @@ -32,494 +34,18 @@
-
-

pylib.numerical package

+
+

pylib.numerical package

Submodules

-
-
-

pylib.numerical.fit module

-

Function and approximation.

-
-
Date
-

2019-10-15

-
-
-
-
-gauss(x, *p)[source]
-

Gauss distribution function.

-
-\[f(x)=ae^{-(x-b)^{2}/(2c^{2})}\]
-
-
Parameters
-
-
-
Returns
-

gauss values at given positions x

-
-
Return type
-

numpy.ndarray

-
-
-
- -
-
-gauss_fit(x, y, e=None, x_fit=None, verbose=False)[source]
-

Fit Gauss distribution function to data.

-
-
Parameters
-
    -
  • x (int or float or list or numpy.ndarray) – positions

  • -
  • y (int or float or list or numpy.ndarray) – values

  • -
  • e (int or float or list or numpy.ndarray) – error values (default = None)

  • -
  • x_fit (int or float or list or numpy.ndarray) – positions of fitted function (default = None, if None then x -is used)

  • -
  • verbose (bool) – verbose information (default = False)

  • -
-
-
Returns
-

    -
  • numpy.ndarray – fitted values (y_fit)

  • -
  • numpy.ndarray – parameters of gauss distribution function (popt: -amplitude a, expected value \(\mu\), standard deviation -\(\sigma\), vertical offset d)

  • -
  • numpy.float64 – full width at half maximum (FWHM)

  • -
-

-
-
Return type
-

tuple

-
-
-
-

See also

-

gauss()

-
- -
-
-

pylib.numerical.integration module

-

Numerical integration, numerical quadrature.

-

de: numerische Integration, numerische Quadratur.

-
-
Date
-

2015-10-15

-
-
-
-
-trapez(f, a=0, b=1, N=10, x=None, verbose=False, save_values=False)[source]
-

Integration of \(f(x)\) using the trapezoidal rule -(Simpson’s rule, Kepler’s rule).

-

de: Trapezregel, Simpsonregel (Thomas Simpson), Keplersche -Fassregel (Johannes Kepler)

-
-
Parameters
-
    -
  • f (function or list) – function to integrate.

  • -
  • a (float) – lower limit of integration (default = 0).

  • -
  • b (float) – upper limit of integration (default = 1).

  • -
  • N (int) – specify the number of subintervals.

  • -
  • x (list) – variable of integration, necessary if f is a list -(default = None).

  • -
  • verbose (bool) – print information (default = False)

  • -
-
-
Returns
-

the definite integral as approximated by trapezoidal -rule.

-
-
Return type
-

float

-
-
-

The trapezoidal rule approximates the integral by the area of a -trapezoid with base h=b-a and sides equal to the values of the -integrand at the two end points.

-
-\[f_n(x) = f(a)+\frac{f(b)-f(a)}{b-a}(x-a)\]
-
-\[\begin{split}I &= \int\limits_a^b f(x) \,\mathrm{d}x \\ -I &\approx \int\limits_a^b f_n(x) \,\mathrm{d}x \\ - &= \int\limits_a^b - \left( f(a)+\frac{f(b)-f(a)}{b-a}(x-a) \right) - \mathrm{d}x \\ - &= \left.\left( f(a)-a\frac{f(b)-f(a)}{b-a} \right) - x \right\vert_a^b + - \left. \frac{f(b)-f(a)}{b-a} \frac{x^2}{2} - \right\vert_a^b \\ - &= \frac{b-a}{2}\left[f(a)+f(b)\right]\end{split}\]
-

The composite trapezium rule. If the interval is divided into n -segments (not necessarily equal)

-
-\[a = x_0 \leq x_1 \leq x_2 \leq \ldots \leq x_n = b\]
-
-\[\begin{split}I &\approx \sum\limits_{i=0}^{n-1} \frac{1}{2} (x_{i+1}-x_i) -\left[f(x_{i+1})+f(x_i)\right] \\\end{split}\]
-

Special Case (Equaliy spaced base points)

-
-\[x_{i+1}-x_i = h \quad \forall i\]
-
-\[I \approx h \left\{ \frac{1}{2} \left[f(x_0)+f(x_n)\right] + - \sum\limits_{i=1}^{n-1} f(x_i) \right\}\]
-

Example

-
-\[\begin{split}I &= \int\limits_a^b f(x) \,\mathrm{d}x \\ -f(x) &= x^2 \\ -a &= 0 \\ -b &= 1\end{split}\]
-

analytical solution

-
-\[I = \int\limits_{0}^{1} x^2 \,\mathrm{d}x - = \left. \frac{1}{3} x^3 \right\vert_0^1 - = \frac{1}{3}\]
-

numerical solution

-
>>> f = lambda(x): x**2
->>> trapez(f, 0, 1, 1)
-0.5
->>> trapez(f, 0, 1, 10)
-0.3350000000000001
->>> trapez(f, 0, 1, 100)
-0.33335000000000004
-
-
-
- -
-
-

pylib.numerical.ode module

-

Numerical solver of ordinary differential equations.

-

Solves the initial value problem for systems of first order -ordinary differential equations.

-
-
Date
-

2015-09-21

-
-
-
-
-e1(f, x0, t, *p, verbose=False)[source]
-

Explicit first-order method / -(standard, or forward) Euler method / -Runge-Kutta 1st order method.

-

de: -Euler’sche Polygonzugverfahren / explizite Euler-Verfahren / -Euler-Cauchy-Verfahren / Euler-vorwärts-Verfahren

-
-
Parameters
-
    -
  • f (function) – the function to solve

  • -
  • x0 (list) – initial condition

  • -
  • t (list) – time

  • -
  • *p – parameters of the function (thickness, diameter, -…)

  • -
  • verbose (bool) – print information (default = False)

  • -
-
-
-

Approximate the solution of the initial value problem

-
-\[\begin{split}\dot{x} &= f(t,x) \\ -x(t_0) &= x_0\end{split}\]
-

Choose a value h for the size of every step and set

-
-\[t_i = t_0 + i h ~,\quad i=1,2,\ldots,n\]
-

The derivative of the solution is approximated as the forward -difference equation

-
-\[\dot{x}_i = f(t_i, x_i) = \frac{x_{i+1} - x_i}{t_{i+1}-t_i}\]
-

Therefore one step \(h\) of the Euler method from -\(t_i\) to \(t_{i+1}\) is

-
-\[\begin{split}x_{i+1} &= x_i + (t_{i+1}-t_i) f(t_i, x_i) \\ -x_{i+1} &= x_i + h f(t_i, x_i) \\\end{split}\]
-

Example 1:

-
-\[\begin{split}m\ddot{u} + d\dot{u} + ku = f(t) \\ -\ddot{u} = m^{-1}(f(t) - d\dot{u} - ku) \\\end{split}\]
-

with

-
-\[\begin{split}x_1 &= u &\quad \dot{x}_1 = \dot{u} = x_2 \\ -x_2 &= \dot{u} &\quad \dot{x}_2 = \ddot{u} \\\end{split}\]
-

becomes

-
-\[\begin{split}\dot{x}_1 &= x_2 \\ -\dot{x}_2 &= m^{-1}(f(t) - d x_2 - k x_1) \\\end{split}\]
-

or

-
-\[\begin{split}\dot{x} &= f(t,x) \\ -\begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &= -\begin{bmatrix} x_2 \\ m^{-1}(f(t) - d x_2 - k x_1) -\end{bmatrix} \\ -&= -\begin{bmatrix} 0 \\ m^{-1} f(t) \end{bmatrix} + -\begin{bmatrix} 0 & 1 \\ -m^{-1} k & -m^{-1} d \end{bmatrix} -\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\end{split}\]
-

Example 2:

-
-\[\begin{split}m(u)\ddot{u} + d(u,\dot{u})\dot{u} + k(u)u = f(t) \\ -\ddot{u} = m^{-1}(u)(f(t) - d(u,\dot{u})\dot{u} - k(u)u) \\\end{split}\]
-

with

-
-\[\begin{split}x_1 &= u &\quad \dot{x}_1 = \dot{u} = x_2 \\ -x_2 &= \dot{u} &\quad \dot{x}_2 = \ddot{u} \\\end{split}\]
-

becomes

-
-\[\begin{split}\dot{x}_1 &= x_2 \\ -\dot{x}_2 &= - m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) \\\end{split}\]
-

or

-
-\[\begin{split}\dot{x} &= f(t,x) \\ -\begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &= -\begin{bmatrix} - x_2 \\ m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) - \end{bmatrix} \\ -&= -\begin{bmatrix} 0 \\ m^{-1}(x_1) f(t) \end{bmatrix} + -\begin{bmatrix} - 0 & 1 \\ -m^{-1}(x_1) k(x_1) & -m^{-1} d(x_1,x_2) - \end{bmatrix} -\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\end{split}\]
-

The Euler method is a first-order method, which means that the -local error (error per step) is proportional to the square of -the step size, and the global error (error at a given time) is -proportional to the step size.

-
- -
-
-e2(f, x0, t, *p, verbose=False)[source]
-

Explicit second-order method / Runge-Kutta 2nd order method.

-
-
Parameters
-
    -
  • f (function) – the function to solve

  • -
  • x0 (list) – initial condition

  • -
  • t (list) – time

  • -
  • *p – parameters of the function (thickness, diameter, -…)

  • -
  • verbose (bool) – print information (default = False)

  • -
-
-
-
- -
-
-e4(f, x0, t, *p, verbose=False)[source]
-

Explicit fourth-order method / Runge-Kutta 4th order method.

-
-
Parameters
-
    -
  • f (function) – the function to solve

  • -
  • x0 (list) – initial condition

  • -
  • t (list) – time

  • -
  • *p – parameters of the function (thickness, diameter, -…)

  • -
  • verbose (bool) – print information (default = False)

  • -
-
-
-
- -
-
-fpi(f, xi, ti, ti1, *p, max_iterations=1000, tol=1e-09, verbose=False)[source]
-

Fixed-point iteration.

-
-
Parameters
-
    -
  • f (function) – the function to iterate \(f = \dot{x}(x,t)\)

  • -
  • xi (list) – initial condition \(x_i\)

  • -
  • ti (float) – time \(t_i\)

  • -
  • ti1 (float) – time \(t_{i+1}\)

  • -
  • *p – parameters of the function (thickness, diameter, -…)

  • -
  • max_iterations (int) – maximum number of iterations

  • -
  • tol (float) – tolerance against residuum \(\varepsilon\) -(default = 1e-9)

  • -
  • verbose (bool) – print information (default = False)

  • -
-
-
Returns
-

\(x_{i}\)

-
-
-
-\[x_{i,j=0} = x_{i}\]
-
-\[x_{i,j+1} = x_i + \dot{x}(x_{i,j}, t_{i+1})\cdot(t_{i+1}-t_i)\]
-
-\[\text{residuum} = \frac{\lVert x_{i,j+1}-x_{i,j}\rVert} - {\lVert x_{i,j+1} \rVert} < \varepsilon\]
-
-\[x_{i} = x_{i,j=\text{end}}\]
-
- -
-
-i1(f, x0, t, *p, max_iterations=1000, tol=1e-09, verbose=False)[source]
-

Implicite first-order method / backward Euler method.

-
-
Parameters
-
    -
  • f (function) – the function to solve

  • -
  • x0 (list) – initial condition

  • -
  • t (list) – time

  • -
  • *p – parameters of the function (thickness, diameter, -…)

  • -
  • max_iterations (int) – maximum number of iterations

  • -
  • tol (float) – tolerance against residuum (default = 1e-9)

  • -
  • verbose (bool) – print information (default = False)

  • -
-
-
-

The backward Euler method has order one and is A-stable.

-
- -
-
-newmark_newtonraphson(f, x0, xp0, xpp0, t, *p, gamma=0.5, beta=0.25, max_iterations=1000, tol=1e-09, verbose=False)[source]
-

Newmark method.

-
-
Parameters
-
    -
  • f (function) – the function to solve

  • -
  • x0 (list) – initial condition

  • -
  • xp0 (list) – initial condition

  • -
  • xpp0 (list) – initial condition

  • -
  • t (list) – time

  • -
  • *p – parameters of the function (thickness, diameter, -…)

  • -
  • gamma (float) – newmark parameter for velocity (default = 0.5)

  • -
  • beta (float) – newmark parameter for displacement (default = 0.25)

  • -
  • max_iterations (int) – maximum number of iterations

  • -
  • tol (float) – tolerance against residuum (default = 1e-9)

  • -
  • verbose (bool) – print information (default = False)

  • -
-
-
-
- -
-
-newmark_newtonraphson_rdk(fnm, x0, xp0, xpp0, t, *p, gamma=0.5, beta=0.25, max_iterations=1000, tol=1e-09, verbose=False)[source]
-

Newmark method.

-
-
Parameters
-
    -
  • f (function) – the function to solve

  • -
  • x0 (list) – initial condition

  • -
  • xp0 (list) – initial condition

  • -
  • xpp0 (list) – initial condition

  • -
  • t (list) – time

  • -
  • *p – parameters of the function (thickness, diameter, -…)

  • -
  • gamma (float) – newmark parameter for velocity (default = 0.5)

  • -
  • beta (float) – newmark parameter for displacement (default = 0.25)

  • -
  • max_iterations (int) – maximum number of iterations

  • -
  • tol (float) – tolerance against residuum (default = 1e-9)

  • -
  • verbose (bool) – print information (default = False)

  • -
-
-
-
- -
-
-

pylib.numerical.ode_model module

-

Mathmatical models governed by ordinary differential equations.

-

Describes initial value problems as systems of first order ordinary differential -equations.

-
-
Date
-

2019-05-25

-
-
-
-
-disk(x, t, *p)[source]
-

Rotation of an eccentric disk.

-
-
Parameters
-
    -
  • x (list) – values of the function

  • -
  • t (list) – time

  • -
  • *p

    parameters of the function

    -
      -
    • diameter

    • -
    • eccentricity

    • -
    • torque

    • -
    -

  • -
-
-
-
- -
-
-disk_nm(xn, xpn, xppn, t, *p)[source]
-

Rotation of an eccentric disk.

-
-
Parameters
-
    -
  • xn (list) – values of the function

  • -
  • xpn (list) – first derivative values of the function

  • -
  • xppn (list) – second derivative values of the function

  • -
  • t (list) – time

  • -
  • *p

    parameters of the function

    -
      -
    • diameter

    • -
    • eccentricity

    • -
    • torque

    • -
    -

  • -
-
-
-
- -
-
-disk_nmmdk(xn, xpn, xppn, t, *p)[source]
-

Rotation of an eccentric disk.

-
-
Parameters
-
    -
  • xn (list) – values of the function

  • -
  • xpn (list) – derivative values of the function

  • -
  • xppn (list) – second derivative values of the function

  • -
  • t (list) – time

  • -
  • *p

    parameters of the function

    -
      -
    • diameter

    • -
    • eccentricity

    • -
    • torque

    • -
    -

  • -
-
-
-
- -
-
-

Module contents

@@ -540,11 +66,24 @@ equations.

Navigation

+

Contents:

+ diff --git a/docs/build/html/pylib.numerical.integration.html b/docs/build/html/pylib.numerical.integration.html new file mode 100644 index 0000000..bad7bc8 --- /dev/null +++ b/docs/build/html/pylib.numerical.integration.html @@ -0,0 +1,205 @@ + + + + + + + pylib.numerical.integration module — pylib 2019.12.21 documentation + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+ +
+

pylib.numerical.integration module

+

Numerical integration, numerical quadrature.

+

de: numerische Integration, numerische Quadratur.

+
+
Date
+

2015-10-15

+
+
+
+
+trapez(f, a=0, b=1, N=10, x=None, verbose=False, save_values=False)[source]
+

Integration of \(f(x)\) using the trapezoidal rule +(Simpson’s rule, Kepler’s rule).

+

de: Trapezregel, Simpsonregel (Thomas Simpson), Keplersche +Fassregel (Johannes Kepler)

+
+
Parameters
+
    +
  • f (function or list) – function to integrate.

  • +
  • a (float) – lower limit of integration (default = 0).

  • +
  • b (float) – upper limit of integration (default = 1).

  • +
  • N (int) – specify the number of subintervals.

  • +
  • x (list) – variable of integration, necessary if f is a list +(default = None).

  • +
  • verbose (bool) – print information (default = False)

  • +
+
+
Returns
+

the definite integral as approximated by trapezoidal +rule.

+
+
Return type
+

float

+
+
+

The trapezoidal rule approximates the integral by the area of a +trapezoid with base h=b-a and sides equal to the values of the +integrand at the two end points.

+
+\[f_n(x) = f(a)+\frac{f(b)-f(a)}{b-a}(x-a)\]
+
+\[\begin{split}I &= \int\limits_a^b f(x) \,\mathrm{d}x \\ +I &\approx \int\limits_a^b f_n(x) \,\mathrm{d}x \\ + &= \int\limits_a^b + \left( f(a)+\frac{f(b)-f(a)}{b-a}(x-a) \right) + \mathrm{d}x \\ + &= \left.\left( f(a)-a\frac{f(b)-f(a)}{b-a} \right) + x \right\vert_a^b + + \left. \frac{f(b)-f(a)}{b-a} \frac{x^2}{2} + \right\vert_a^b \\ + &= \frac{b-a}{2}\left[f(a)+f(b)\right]\end{split}\]
+

The composite trapezium rule. If the interval is divided into n +segments (not necessarily equal)

+
+\[a = x_0 \leq x_1 \leq x_2 \leq \ldots \leq x_n = b\]
+
+\[\begin{split}I &\approx \sum\limits_{i=0}^{n-1} \frac{1}{2} (x_{i+1}-x_i) +\left[f(x_{i+1})+f(x_i)\right] \\\end{split}\]
+

Special Case (Equaliy spaced base points)

+
+\[x_{i+1}-x_i = h \quad \forall i\]
+
+\[I \approx h \left\{ \frac{1}{2} \left[f(x_0)+f(x_n)\right] + + \sum\limits_{i=1}^{n-1} f(x_i) \right\}\]
+

Example

+
+\[\begin{split}I &= \int\limits_a^b f(x) \,\mathrm{d}x \\ +f(x) &= x^2 \\ +a &= 0 \\ +b &= 1\end{split}\]
+

analytical solution

+
+\[I = \int\limits_{0}^{1} x^2 \,\mathrm{d}x + = \left. \frac{1}{3} x^3 \right\vert_0^1 + = \frac{1}{3}\]
+

numerical solution

+
>>> f = lambda(x): x**2
+>>> trapez(f, 0, 1, 1)
+0.5
+>>> trapez(f, 0, 1, 10)
+0.3350000000000001
+>>> trapez(f, 0, 1, 100)
+0.33335000000000004
+
+
+
+ +
+ + +
+ +
+
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/docs/build/html/pylib.numerical.ode.html b/docs/build/html/pylib.numerical.ode.html new file mode 100644 index 0000000..93c6fa5 --- /dev/null +++ b/docs/build/html/pylib.numerical.ode.html @@ -0,0 +1,357 @@ + + + + + + + pylib.numerical.ode module — pylib 2019.12.21 documentation + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+ +
+

pylib.numerical.ode module

+

Numerical solver of ordinary differential equations.

+

Solves the initial value problem for systems of first order +ordinary differential equations.

+
+
Date
+

2015-09-21

+
+
+
+
+e1(f, x0, t, *p, verbose=False)[source]
+

Explicit first-order method / +(standard, or forward) Euler method / +Runge-Kutta 1st order method.

+

de: +Euler’sche Polygonzugverfahren / explizite Euler-Verfahren / +Euler-Cauchy-Verfahren / Euler-vorwärts-Verfahren

+
+
Parameters
+
    +
  • f (function) – the function to solve

  • +
  • x0 (list) – initial condition

  • +
  • t (list) – time

  • +
  • *p – parameters of the function (thickness, diameter, +…)

  • +
  • verbose (bool) – print information (default = False)

  • +
+
+
+

Approximate the solution of the initial value problem

+
+\[\begin{split}\dot{x} &= f(t,x) \\ +x(t_0) &= x_0\end{split}\]
+

Choose a value h for the size of every step and set

+
+\[t_i = t_0 + i h ~,\quad i=1,2,\ldots,n\]
+

The derivative of the solution is approximated as the forward +difference equation

+
+\[\dot{x}_i = f(t_i, x_i) = \frac{x_{i+1} - x_i}{t_{i+1}-t_i}\]
+

Therefore one step \(h\) of the Euler method from +\(t_i\) to \(t_{i+1}\) is

+
+\[\begin{split}x_{i+1} &= x_i + (t_{i+1}-t_i) f(t_i, x_i) \\ +x_{i+1} &= x_i + h f(t_i, x_i) \\\end{split}\]
+

Example 1:

+
+\[\begin{split}m\ddot{u} + d\dot{u} + ku = f(t) \\ +\ddot{u} = m^{-1}(f(t) - d\dot{u} - ku) \\\end{split}\]
+

with

+
+\[\begin{split}x_1 &= u &\quad \dot{x}_1 = \dot{u} = x_2 \\ +x_2 &= \dot{u} &\quad \dot{x}_2 = \ddot{u} \\\end{split}\]
+

becomes

+
+\[\begin{split}\dot{x}_1 &= x_2 \\ +\dot{x}_2 &= m^{-1}(f(t) - d x_2 - k x_1) \\\end{split}\]
+

or

+
+\[\begin{split}\dot{x} &= f(t,x) \\ +\begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &= +\begin{bmatrix} x_2 \\ m^{-1}(f(t) - d x_2 - k x_1) +\end{bmatrix} \\ +&= +\begin{bmatrix} 0 \\ m^{-1} f(t) \end{bmatrix} + +\begin{bmatrix} 0 & 1 \\ -m^{-1} k & -m^{-1} d \end{bmatrix} +\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\end{split}\]
+

Example 2:

+
+\[\begin{split}m(u)\ddot{u} + d(u,\dot{u})\dot{u} + k(u)u = f(t) \\ +\ddot{u} = m^{-1}(u)(f(t) - d(u,\dot{u})\dot{u} - k(u)u) \\\end{split}\]
+

with

+
+\[\begin{split}x_1 &= u &\quad \dot{x}_1 = \dot{u} = x_2 \\ +x_2 &= \dot{u} &\quad \dot{x}_2 = \ddot{u} \\\end{split}\]
+

becomes

+
+\[\begin{split}\dot{x}_1 &= x_2 \\ +\dot{x}_2 &= + m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) \\\end{split}\]
+

or

+
+\[\begin{split}\dot{x} &= f(t,x) \\ +\begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &= +\begin{bmatrix} + x_2 \\ m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) + \end{bmatrix} \\ +&= +\begin{bmatrix} 0 \\ m^{-1}(x_1) f(t) \end{bmatrix} + +\begin{bmatrix} + 0 & 1 \\ -m^{-1}(x_1) k(x_1) & -m^{-1} d(x_1,x_2) + \end{bmatrix} +\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\end{split}\]
+

The Euler method is a first-order method, which means that the +local error (error per step) is proportional to the square of +the step size, and the global error (error at a given time) is +proportional to the step size.

+
+ +
+
+e2(f, x0, t, *p, verbose=False)[source]
+

Explicit second-order method / Runge-Kutta 2nd order method.

+
+
Parameters
+
    +
  • f (function) – the function to solve

  • +
  • x0 (list) – initial condition

  • +
  • t (list) – time

  • +
  • *p – parameters of the function (thickness, diameter, +…)

  • +
  • verbose (bool) – print information (default = False)

  • +
+
+
+
+ +
+
+e4(f, x0, t, *p, verbose=False)[source]
+

Explicit fourth-order method / Runge-Kutta 4th order method.

+
+
Parameters
+
    +
  • f (function) – the function to solve

  • +
  • x0 (list) – initial condition

  • +
  • t (list) – time

  • +
  • *p – parameters of the function (thickness, diameter, +…)

  • +
  • verbose (bool) – print information (default = False)

  • +
+
+
+
+ +
+
+fpi(f, xi, ti, ti1, *p, max_iterations=1000, tol=1e-09, verbose=False)[source]
+

Fixed-point iteration.

+
+
Parameters
+
    +
  • f (function) – the function to iterate \(f = \dot{x}(x,t)\)

  • +
  • xi (list) – initial condition \(x_i\)

  • +
  • ti (float) – time \(t_i\)

  • +
  • ti1 (float) – time \(t_{i+1}\)

  • +
  • *p – parameters of the function (thickness, diameter, +…)

  • +
  • max_iterations (int) – maximum number of iterations

  • +
  • tol (float) – tolerance against residuum \(\varepsilon\) +(default = 1e-9)

  • +
  • verbose (bool) – print information (default = False)

  • +
+
+
Returns
+

\(x_{i}\)

+
+
+
+\[x_{i,j=0} = x_{i}\]
+
+\[x_{i,j+1} = x_i + \dot{x}(x_{i,j}, t_{i+1})\cdot(t_{i+1}-t_i)\]
+
+\[\text{residuum} = \frac{\lVert x_{i,j+1}-x_{i,j}\rVert} + {\lVert x_{i,j+1} \rVert} < \varepsilon\]
+
+\[x_{i} = x_{i,j=\text{end}}\]
+
+ +
+
+i1(f, x0, t, *p, max_iterations=1000, tol=1e-09, verbose=False)[source]
+

Implicite first-order method / backward Euler method.

+
+
Parameters
+
    +
  • f (function) – the function to solve

  • +
  • x0 (list) – initial condition

  • +
  • t (list) – time

  • +
  • *p – parameters of the function (thickness, diameter, +…)

  • +
  • max_iterations (int) – maximum number of iterations

  • +
  • tol (float) – tolerance against residuum (default = 1e-9)

  • +
  • verbose (bool) – print information (default = False)

  • +
+
+
+

The backward Euler method has order one and is A-stable.

+
+ +
+
+newmark_newtonraphson(f, x0, xp0, xpp0, t, *p, gamma=0.5, beta=0.25, max_iterations=1000, tol=1e-09, verbose=False)[source]
+

Newmark method.

+
+
Parameters
+
    +
  • f (function) – the function to solve

  • +
  • x0 (list) – initial condition

  • +
  • xp0 (list) – initial condition

  • +
  • xpp0 (list) – initial condition

  • +
  • t (list) – time

  • +
  • *p – parameters of the function (thickness, diameter, +…)

  • +
  • gamma (float) – newmark parameter for velocity (default = 0.5)

  • +
  • beta (float) – newmark parameter for displacement (default = 0.25)

  • +
  • max_iterations (int) – maximum number of iterations

  • +
  • tol (float) – tolerance against residuum (default = 1e-9)

  • +
  • verbose (bool) – print information (default = False)

  • +
+
+
+
+ +
+
+newmark_newtonraphson_rdk(fnm, x0, xp0, xpp0, t, *p, gamma=0.5, beta=0.25, max_iterations=1000, tol=1e-09, verbose=False)[source]
+

Newmark method.

+
+
Parameters
+
    +
  • f (function) – the function to solve

  • +
  • x0 (list) – initial condition

  • +
  • xp0 (list) – initial condition

  • +
  • xpp0 (list) – initial condition

  • +
  • t (list) – time

  • +
  • *p – parameters of the function (thickness, diameter, +…)

  • +
  • gamma (float) – newmark parameter for velocity (default = 0.5)

  • +
  • beta (float) – newmark parameter for displacement (default = 0.25)

  • +
  • max_iterations (int) – maximum number of iterations

  • +
  • tol (float) – tolerance against residuum (default = 1e-9)

  • +
  • verbose (bool) – print information (default = False)

  • +
+
+
+
+ +
+ + +
+ +
+
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/docs/build/html/pylib.numerical.ode_model.html b/docs/build/html/pylib.numerical.ode_model.html new file mode 100644 index 0000000..f03a722 --- /dev/null +++ b/docs/build/html/pylib.numerical.ode_model.html @@ -0,0 +1,194 @@ + + + + + + + pylib.numerical.ode_model module — pylib 2019.12.21 documentation + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+ +
+

pylib.numerical.ode_model module

+

Mathmatical models governed by ordinary differential equations.

+

Describes initial value problems as systems of first order ordinary differential +equations.

+
+
Date
+

2019-05-25

+
+
+
+
+disk(x, t, *p)[source]
+

Rotation of an eccentric disk.

+
+
Parameters
+
    +
  • x (list) – values of the function

  • +
  • t (list) – time

  • +
  • *p

    parameters of the function

    +
      +
    • diameter

    • +
    • eccentricity

    • +
    • torque

    • +
    +

  • +
+
+
+
+ +
+
+disk_nm(xn, xpn, xppn, t, *p)[source]
+

Rotation of an eccentric disk.

+
+
Parameters
+
    +
  • xn (list) – values of the function

  • +
  • xpn (list) – first derivative values of the function

  • +
  • xppn (list) – second derivative values of the function

  • +
  • t (list) – time

  • +
  • *p

    parameters of the function

    +
      +
    • diameter

    • +
    • eccentricity

    • +
    • torque

    • +
    +

  • +
+
+
+
+ +
+
+disk_nmmdk(xn, xpn, xppn, t, *p)[source]
+

Rotation of an eccentric disk.

+
+
Parameters
+
    +
  • xn (list) – values of the function

  • +
  • xpn (list) – derivative values of the function

  • +
  • xppn (list) – second derivative values of the function

  • +
  • t (list) – time

  • +
  • *p

    parameters of the function

    +
      +
    • diameter

    • +
    • eccentricity

    • +
    • torque

    • +
    +

  • +
+
+
+
+ +
+ + +
+ +
+
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/docs/build/html/time_of_day.html b/docs/build/html/pylib.time_of_day.html similarity index 70% rename from docs/build/html/time_of_day.html rename to docs/build/html/pylib.time_of_day.html index 2a512ed..cc3de20 100644 --- a/docs/build/html/time_of_day.html +++ b/docs/build/html/pylib.time_of_day.html @@ -4,7 +4,7 @@ - time_of_day module — pylib 2019.5.19 documentation + pylib.time_of_day module — pylib 2019.12.21 documentation @@ -16,6 +16,7 @@ + @@ -32,8 +33,8 @@
-
-

time_of_day module

+
+

pylib.time_of_day module

Calculate time.

Date
@@ -41,8 +42,8 @@
-
-days(time)[source]
+
+days(time)[source]

The days of the time (year).

Parameters
@@ -58,8 +59,8 @@
-
-days_norm(time)[source]
+
+days_norm(time)[source]

The days normalized to 365.2425 (Gregorian, on average) days.

Parameters
@@ -75,8 +76,8 @@
-
-hours(time)[source]
+
+hours(time)[source]

The hours of the time.

Parameters
@@ -92,8 +93,8 @@
-
-hours_norm(time)[source]
+
+hours_norm(time)[source]

The hours normalized to 24 hours.

Parameters
@@ -109,8 +110,8 @@
-
-in_seconds(time)[source]
+
+in_seconds(time)[source]

If time is time.struct_time convert to float seconds.

Parameters
@@ -126,8 +127,8 @@
-
-minutes(time)[source]
+
+minutes(time)[source]

The minutes of the time.

Parameters
@@ -143,8 +144,8 @@
-
-minutes_norm(time)[source]
+
+minutes_norm(time)[source]

The minutes normalized to 60 minutes.

Parameters
@@ -160,8 +161,8 @@
-
-seconds(time)[source]
+
+seconds(time)[source]

The seconds of the time.

Parameters
@@ -177,8 +178,8 @@
-
-seconds_norm(time)[source]
+
+seconds_norm(time)[source]

The seconds normalized to 60 seconds.

Parameters
@@ -194,8 +195,8 @@
-
-transform(time_norm, length, offset=0)[source]
+
+transform(time_norm, length, offset=0)[source]

Transform normalized time value to new length.

Parameters
@@ -233,11 +234,23 @@

Navigation

+

Contents:

+ @@ -271,7 +284,7 @@ & Alabaster 0.7.12 | - Page source
diff --git a/docs/build/html/search.html b/docs/build/html/search.html index c56b910..a611c20 100644 --- a/docs/build/html/search.html +++ b/docs/build/html/search.html @@ -4,7 +4,7 @@ - Search — pylib 2019.5.19 documentation + Search — pylib 2019.12.21 documentation @@ -77,6 +77,10 @@

Navigation

+

Contents:

+

Related Topics

diff --git a/docs/build/html/searchindex.js b/docs/build/html/searchindex.js index 0d71a9b..2fec14d 100644 --- a/docs/build/html/searchindex.js +++ b/docs/build/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["data","date","function","geometry","geometry_plot","index","mathematics","modules","numerical","pylib","pylib.numerical","time_of_day"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["data.rst","date.rst","function.rst","geometry.rst","geometry_plot.rst","index.rst","mathematics.rst","modules.rst","numerical.rst","pylib.rst","pylib.numerical.rst","time_of_day.rst"],objects:{"":{"function":[9,0,0,"-"],data:[9,0,0,"-"],date:[9,0,0,"-"],fit:[10,0,0,"-"],geometry:[9,0,0,"-"],geometry_plot:[9,0,0,"-"],integration:[10,0,0,"-"],mathematics:[9,0,0,"-"],numerical:[8,0,0,"-"],ode:[10,0,0,"-"],ode_model:[10,0,0,"-"],pylib:[9,0,0,"-"],time_of_day:[9,0,0,"-"]},"function":{cosine_wave:[2,1,1,""],epitrochoid:[2,1,1,""],hypotrochoid:[2,1,1,""],sine_wave:[2,1,1,""],to_str:[2,1,1,""],transformation:[2,1,1,""]},"mathematics.matrix":{rotate_x:[6,3,1,""],rotate_y:[6,3,1,""],rotate_z:[6,3,1,""],rx:[6,3,1,""],ry:[6,3,1,""],rz:[6,3,1,""],s:[6,3,1,""],scale:[6,3,1,""],t:[6,3,1,""],translate:[6,3,1,""]},"mathematics.vector":{abs:[6,3,1,""],ang:[6,3,1,""],arg:[6,3,1,""],ch_cs:[6,3,1,""],conjugate:[6,3,1,""],cross:[6,3,1,""],full:[6,3,1,""],im:[6,3,1,""],normalize:[6,3,1,""],ones:[6,3,1,""],random:[6,3,1,""],re:[6,3,1,""],rotate_x:[6,3,1,""],rotate_y:[6,3,1,""],rotate_z:[6,3,1,""],scale:[6,3,1,""],translate:[6,3,1,""],xyz:[6,3,1,""],zeros:[6,3,1,""]},"numerical.fit":{gauss:[8,1,1,""],gauss_fit:[8,1,1,""]},"numerical.integration":{trapez:[8,1,1,""]},"numerical.ode":{e1:[8,1,1,""],e2:[8,1,1,""],e4:[8,1,1,""],fpi:[8,1,1,""],i1:[8,1,1,""],newmark_newtonraphson:[8,1,1,""],newmark_newtonraphson_rdk:[8,1,1,""]},"numerical.ode_model":{disk:[8,1,1,""],disk_nm:[8,1,1,""],disk_nmmdk:[8,1,1,""]},"pylib.data":{fold_list:[9,1,1,""],get_id:[9,1,1,""],load:[9,1,1,""],read:[9,1,1,""],seq:[9,1,1,""],store:[9,1,1,""],unique_ending:[9,1,1,""],write:[9,1,1,""]},"pylib.date":{"gau\u00dfsche_osterformel":[9,1,1,""],ascension_of_jesus:[9,1,1,""],easter_friday:[9,1,1,""],easter_monday:[9,1,1,""],easter_sunday:[9,1,1,""],pentecost:[9,1,1,""]},"pylib.drawblock":{histogram:[9,1,1,""]},"pylib.function":{cosine_wave:[9,1,1,""],epitrochoid:[9,1,1,""],hypotrochoid:[9,1,1,""],sine_wave:[9,1,1,""],to_str:[9,1,1,""],transformation:[9,1,1,""]},"pylib.geometry":{angle:[9,1,1,""],cubic:[9,1,1,""],cubic_deg:[9,1,1,""],cubics:[9,1,1,""],distance:[9,1,1,""],interpolate_hermite:[9,1,1,""],line:[9,1,1,""],lines:[9,1,1,""],rectangle:[9,1,1,""],rotate:[9,1,1,""],rotate_deg:[9,1,1,""],rotate_xy:[9,1,1,""],square:[9,1,1,""],translate:[9,1,1,""],translate_xy:[9,1,1,""]},"pylib.geometry_plot":{plot_cubic_lines:[9,1,1,""],plot_lines:[9,1,1,""]},"pylib.mathematics":{lcm:[9,1,1,""],matrix:[9,2,1,""],vector:[9,2,1,""]},"pylib.mathematics.matrix":{rotate_x:[9,3,1,""],rotate_y:[9,3,1,""],rotate_z:[9,3,1,""],rx:[9,3,1,""],ry:[9,3,1,""],rz:[9,3,1,""],s:[9,3,1,""],scale:[9,3,1,""],t:[9,3,1,""],translate:[9,3,1,""]},"pylib.mathematics.vector":{abs:[9,3,1,""],ang:[9,3,1,""],arg:[9,3,1,""],ch_cs:[9,3,1,""],conjugate:[9,3,1,""],cross:[9,3,1,""],full:[9,3,1,""],im:[9,3,1,""],normalize:[9,3,1,""],ones:[9,3,1,""],random:[9,3,1,""],re:[9,3,1,""],rotate_x:[9,3,1,""],rotate_y:[9,3,1,""],rotate_z:[9,3,1,""],scale:[9,3,1,""],translate:[9,3,1,""],xyz:[9,3,1,""],zeros:[9,3,1,""]},"pylib.numerical":{fit:[10,0,0,"-"],integration:[10,0,0,"-"],ode:[10,0,0,"-"],ode_model:[10,0,0,"-"]},"pylib.numerical.fit":{gauss:[10,1,1,""],gauss_fit:[10,1,1,""]},"pylib.numerical.integration":{trapez:[10,1,1,""]},"pylib.numerical.ode":{e1:[10,1,1,""],e2:[10,1,1,""],e4:[10,1,1,""],fpi:[10,1,1,""],i1:[10,1,1,""],newmark_newtonraphson:[10,1,1,""],newmark_newtonraphson_rdk:[10,1,1,""]},"pylib.numerical.ode_model":{disk:[10,1,1,""],disk_nm:[10,1,1,""],disk_nmmdk:[10,1,1,""]},"pylib.time_of_day":{days:[9,1,1,""],days_norm:[9,1,1,""],hours:[9,1,1,""],hours_norm:[9,1,1,""],in_seconds:[9,1,1,""],minutes:[9,1,1,""],minutes_norm:[9,1,1,""],seconds:[9,1,1,""],seconds_norm:[9,1,1,""],transform:[9,1,1,""]},data:{fold_list:[0,1,1,""],get_id:[0,1,1,""],load:[0,1,1,""],read:[0,1,1,""],seq:[0,1,1,""],store:[0,1,1,""],unique_ending:[0,1,1,""],write:[0,1,1,""]},date:{"gau\u00dfsche_osterformel":[1,1,1,""],ascension_of_jesus:[1,1,1,""],easter_friday:[1,1,1,""],easter_monday:[1,1,1,""],easter_sunday:[1,1,1,""],pentecost:[1,1,1,""]},geometry:{angle:[3,1,1,""],cubic:[3,1,1,""],cubic_deg:[3,1,1,""],cubics:[3,1,1,""],distance:[3,1,1,""],interpolate_hermite:[3,1,1,""],line:[3,1,1,""],lines:[3,1,1,""],rectangle:[3,1,1,""],rotate:[3,1,1,""],rotate_deg:[3,1,1,""],rotate_xy:[3,1,1,""],square:[3,1,1,""],translate:[3,1,1,""],translate_xy:[3,1,1,""]},geometry_plot:{plot_cubic_lines:[4,1,1,""],plot_lines:[4,1,1,""]},mathematics:{lcm:[6,1,1,""],matrix:[6,2,1,""],vector:[6,2,1,""]},numerical:{fit:[8,0,0,"-"],integration:[8,0,0,"-"],ode:[8,0,0,"-"],ode_model:[8,0,0,"-"]},pylib:{"function":[9,0,0,"-"],data:[9,0,0,"-"],date:[9,0,0,"-"],drawblock:[9,0,0,"-"],geometry:[9,0,0,"-"],geometry_plot:[9,0,0,"-"],mathematics:[9,0,0,"-"],numerical:[10,0,0,"-"],time_of_day:[9,0,0,"-"]},time_of_day:{days:[11,1,1,""],days_norm:[11,1,1,""],hours:[11,1,1,""],hours_norm:[11,1,1,""],in_seconds:[11,1,1,""],minutes:[11,1,1,""],minutes_norm:[11,1,1,""],seconds:[11,1,1,""],seconds_norm:[11,1,1,""],transform:[11,1,1,""]}},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","class","Python class"],"3":["py","method","Python method"]},objtypes:{"0":"py:module","1":"py:function","2":"py:class","3":"py:method"},terms:{"1st":[8,10],"259f":[2,9],"28ff":[2,9],"2\u03c0f":[2,9],"2nd":[8,10],"4th":[8,10],"9fsche_osterformel":[1,9],"\u03bb":[2,9],"\u03bd":[2,9],"\u03c0":[2,9],"\u03c6":[2,9],"\u03c9":[2,9],"boolean":[2,9],"case":[2,8,9,10],"char":[0,2,9],"class":[6,9],"default":[0,2,3,8,9,10,11],"f\u00fcr":[1,9],"float":[0,2,3,8,9,10,11],"fr\u00fchling":[1,9],"function":[6,7,8,10],"gau\u00dfsch":[1,9],"gau\u00dfsche_osterformel":[1,9],"int":[0,1,2,3,6,8,9,10],"korrekturgr\u00f6\u00df":[1,9],"m\u00e4rz":[1,9],"m\u00e4rzdatum":[1,9],"new":[6,9,11],"return":[0,1,2,3,6,8,9,10,11],"s\u00e4kular":[1,9],"s\u00e4kularzahl":[1,9],"static":[6,9],"super":[6,9],"switch":[2,9],"true":[2,6,9],"vorw\u00e4rt":[8,10],Das:[1,9],The:[0,2,3,6,8,9,10,11],Use:[6,9],_____:[2,9],__contains__:[6,9],__eq__:[6,9],__ge__:[6,9],__gt__:[6,9],__imatmul__:[6,9],__imul__:[6,9],__isub__:[6,9],__iter__:[6,9],__le__:[6,9],__lt__:[6,9],__ne__:[6,9],__setitem__:[6,9],about:[6,9],abs:[6,9],absolut:[3,9],addit:[3,9],afterward:[6,9],against:[8,10],algorithmu:[1,9],alia:[2,9],als:[1,9],also:[2,9],amplitud:[2,8,9,10],analyt:[8,10],ang:[6,9],angl:[3,9],angle1:[3,9],angle2:[3,9],angular:[2,9],anim:[2,9],approx:[8,10],approxim:[8,10],april:[1,9],area:[8,10],arg:[6,9],argument:[2,3,9],arithmet:[0,9],around:[2,3,6,9],arrai:[0,9],ascens:[1,9],ascension_of_jesu:[1,9],ascii:[0,9],assum:[3,9],attach:[2,9],averag:[9,11],avoid:[6,9],axi:[2,9],back:[6,9],backward:[8,10],base:[6,8,9,10],becaus:[2,9],becom:[8,10],begin:[6,8,9,10],beta:[8,10],between:[0,2,3,9],binari:[0,9],block:[2,9],bmatrix:[6,8,9,10],bool:[0,2,8,9,10],both:[6,9],bottom:[2,3,9],bound:[0,9],boundari:[3,9],braill:[2,9],build:[3,9],calcul:[1,8,9,10,11],call:[2,9],can:[6,9],cauchi:[8,10],cdot:[8,10],center:[2,3,6,9],ch_c:[6,9],chang:[2,3,9],char_set:[2,9],charact:[2,9],characterist:[2,9],chart:[2,9],choos:[8,10],circl:[2,9],close:[0,9],column:[0,2,6,9],common:[0,6,9],complex:[6,9],composit:[8,10],comput:[6,9],condit:[3,8,9,10],conjug:[6,9],consecut:[0,9],constant:[0,9],constructor:[6,9],content:7,convert:[0,9,11],coordin:[3,6,9],cos:[2,6,9],cosin:[2,9],cosine_wav:[2,9],cosine_wave_degre:[],counterclockwis:[3,9],creat:[0,6,9],cross:[6,9],cubic:[3,9],cubic_deg:[3,9],cudb:[2,9],curv:[2,9],cycl:[2,9],dai:[1,9,11],data:[2,7,8,10],databas:[2,9],date:[0,2,3,4,6,7,8,10,11],datetim:[1,9],datum:[1,9],days_norm:[9,11],ddot:[8,10],decid:[3,9],defin:[3,6,9],definit:[8,10],deflect:[3,9],deform:[3,9],degener:[0,9],degre:[2,3,9],den:[1,9],densiti:[2,9],depend:[2,9],der:[1,9],derform:[3,9],deriv:[8,10],des:[1,9],describ:[2,8,9,10],deviat:[2,8,9,10],diamet:[8,10],die:[1,9],differ:[0,8,9,10],differenti:[8,10],dimens:[2,9],dimension:[0,9],dimenson:[0,9],dirction:[6,9],direct:[2,3,6,9],disk:[8,10],disk_nm:[8,10],disk_nmmdk:[8,10],displac:[3,8,9,10],distanc:[2,3,9],distribut:[8,10],divid:[8,10],doe:[2,3,9],dot:[2,6,8,9,10],down:[2,9],drawblock:7,drawil:[2,9],each:[2,3,9],easter:[1,9],easter_fridai:[1,9],easter_mondai:[1,9],easter_sundai:[1,9],eccentr:[8,10],edg:[3,9],either:[2,3,6,9],element:[0,2,3,9],empti:[0,9],emptyset:[0,9],end:[0,3,6,8,9,10],endpoint:[3,9],entfernung:[1,9],epitrochoid:[2,9],equal:[8,10],equalii:[8,10],equat:[2,8,9,10],error:[8,10],ersten:[1,9],euler:[8,10],everi:[8,10],exampl:[2,3,6,8,9,10],expect:[8,10],explicit:[8,10],explizit:[8,10],exterior:[2,9],f_n:[8,10],factor:[2,3,9],fail:[0,9],fals:[0,2,8,9,10],fassregel:[8,10],file:[0,9],file_nam:[0,9],filenam:[0,9],fill:[6,9],fill_valu:[6,9],first:[0,2,3,8,9,10],fisrt:[2,9],fit:[7,9],fix:[2,8,9,10],float64:[8,10],fnm:[8,10],fold_list:[0,9],follow:[0,9],foral:[8,10],forward:[8,10],found:[6,9],fourth:[8,10],fpi:[8,10],frac:[2,3,6,8,9,10],frame:[2,9],frequenc:[2,9],fridai:[1,9],from:[0,2,6,8,9,10],full:[0,6,8,9,10],function_cosine_wave_degre:[],function_sine_wave_degre:[],fwhm:[8,10],gamma:[8,10],gau:[1,9],gauss:[8,10],gauss_fit:[8,10],gener:[2,9],geometri:[4,7],geometry_plot:[3,7],get:[0,9],get_id:[0,9],gilt:[1,9],given:[0,3,6,8,9,10],global:[3,8,9,10],global_deform:[3,9],govern:[8,10],gregorian:[9,11],gregorianischen:[1,9],half:[8,10],hand:[6,9],happen:[6,9],has:[0,6,8,9,10],have:[2,6,9],head:[2,9],height:[3,9],hermit:[3,9],higher:[2,9],histogram:[2,9],horizont:[2,3,9],hour:[9,11],hours_norm:[9,11],http:[1,9],hyotrochoid:[2,9],hypotrochoid:[2,9],ids:[0,9],imaginari:[6,9],implicit:[8,10],in_second:[9,11],inc:[3,9],incid:[3,9],index:[0,2,3,5,9],index_offset:[3,9],inform:[0,8,9,10],initi:[8,10],insid:[2,9],integr:[7,9],integrand:[8,10],interior:[2,9],interpol:[3,9],interpolate_hermit:[3,9],interpret:[0,2,9],interv:[8,10],isinst:[6,9],iter:[8,10],its:[2,6,9],jahr:[1,9],jesu:[1,9],johann:[8,10],kalend:[1,9],kalendarisch:[1,9],keim:[1,9],kepler:[8,10],keplersch:[8,10],keyword:[3,9],kutta:[8,10],kwarg:[3,4,9],kx1:[0,9],lag:[2,9],lambda:[2,8,9,10],last:[2,9],lcm:[2,6,9],ldot:[8,10],lead:[2,9],left:[0,2,3,8,9,10],leftrightarrow:[8,10],len:[6,9],length:[0,3,6,9,11],leq:[8,10],lhape:[6,9],lhd:[3,9],like:[6,9],limit:[8,10],limits_:[8,10],limits_a:[8,10],line:[2,3,9],linear:[2,9],list:[0,2,3,6,8,9,10],lmax:[6,9],lmin:[6,9],lns:[4,9],load:[0,9],local:[8,10],locat:[6,9],lower:[0,8,9,10],lowest:[6,9],lst:[0,9],lvd:[3,9],lvert:[8,10],magnitud:[6,9],make:[2,9],manipul:[0,9],march:[1,9],mathemat:[2,7],mathmat:[8,10],mathrm:[2,8,9,10],matplotlib:[4,9],matrix:[6,9],max:[2,9],max_iter:[8,10],maximum:[8,10],mean:[2,8,9,10],method:[8,10],min:[2,9],minumum:[0,9],minut:[9,11],minutes_norm:[9,11],model:[8,10],modul:[5,7],modulu:[6,9],mondai:[1,9],mondparamet:[1,9],mondschaltung:[1,9],move:[2,6,9],multipl:[6,9],mxn:[0,9],ndarrai:[8,10],necessari:[8,10],necessarili:[8,10],newmark:[8,10],newmark_newtonraphson:[8,10],newmark_newtonraphson_rdk:[8,10],node:[3,9],non:[2,9],none:[0,2,3,6,8,9,10],norm:[2,6,9],normal:[2,6,9,11],note:[6,9],number:[2,3,6,8,9,10],numer:[7,9],numerisch:[8,10],numpi:[8,10],object:[0,3,6,9],object_data:[0,9],occur:[2,9],ode:[7,9],ode_model:[7,9],offset:[8,9,10,11],often:[2,9],omega:[2,9],one:[0,2,3,8,9,10],ones:[6,9],onli:[0,9],open:[0,9],option:[2,3,9],order:[3,8,9,10],ordinari:[2,8,9,10],org:[1,9],origin:[3,6,9],orthogon:[6,9],oscil:[2,9],osterentfernung:[1,9],osterformel:[1,9],ostergrenz:[1,9],ostersonntag:[1,9],other:[3,9],otherwis:[3,9],outer:[6,9],outsid:[2,9],over:[2,9],packag:7,page:5,paramet:[0,1,2,3,6,8,9,10,11],part:[2,6,9],pattern:[2,9],peak:[2,9],pentecost:[1,9],per:[2,8,9,10],perform:[6,9],period:[2,9],phase:[2,6,9],phi:[2,9],pixel:[2,9],plane:[3,9],plot:[2,3,9],plot_cubic_lin:[4,9],plot_lin:[3,4,9],plotter:[4,9],point1:[3,9],point1_i:[3,9],point1_x:[3,9],point2:[3,9],point2_i:[3,9],point2_x:[3,9],point3:[3,9],point4:[3,9],point:[2,3,8,9,10],point_i:[3,9],point_x:[3,9],points1_i:[3,9],polygon:[3,9],polygonzugverfahren:[8,10],popt:[8,10],posit:[2,8,9,10],position_norm:[9,11],print:[3,6,8,9,10],problem:[8,10],product:[6,9],program:[0,9],propag:[2,9],proport:[8,10],proportion:[2,9],pts:[3,9],pylab:[4,9],pylib:2,quad:[8,10],quadratur:[8,10],quasi:[2,9],radian:[2,3,9],radiu:[2,9],random:[6,9],rang:[2,9,11],rate:[2,9],read:[0,9],real:[6,9],rectangl:[3,9],refer:[2,9],relat:[2,9],repres:[2,9],residuum:[8,10],result:[2,9],rhd:[3,9],right:[0,2,3,6,8,9,10],roation:[3,9],roll:[2,9],rotat:[3,6,8,9,10],rotate_deg:[3,9],rotate_i:[6,9],rotate_x:[6,9],rotate_xi:[3,9],rotate_z:[6,9],rotation_plan:[3,9],row:[2,6,9],rule:[6,8,9,10],rung:[8,10],rvd:[3,9],rvert:[8,10],s_x:[6,9],s_y:[6,9],s_z:[6,9],said:[2,9],same:[0,9],sampl:[3,9],sample_point1_x:[3,9],sample_point2_i:[3,9],sample_point2_x:[3,9],sample_points1_i:[3,9],save_valu:[8,10],scalar:[6,9],scale:[2,6,9],scale_horizont:[2,9],scale_i:[3,9],scale_vert:[2,9],scale_x:[3,9],sche:[8,10],search:5,second:[0,2,3,8,9,10,11],seconds_norm:[9,11],segment:[8,10],seq:[0,9],sequenc:[0,9],set:[2,8,9,10],shape:[6,9],shift:[2,9],shift_horizont:[2,9],shift_vert:[2,9],should:[3,6,9],side:[8,10],sigma:[8,10],simpson:[8,10],simpsonregel:[8,10],sin:[2,6,9],sine:[2,9],sine_wav:[2,9],sine_wave_degre:[],sinusoid:[2,9],size:[0,3,6,8,9,10],slope:[3,9],smooth:[2,9],solid:[3,9],solut:[8,10],solv:[8,10],solver:[8,10],sonnenschaltung:[1,9],sonntag:[1,9],sourc:[0,1,2,3,4,6,8,9,10,11],space:[8,10],spacial:[1,9],spatial:[2,9],special:[8,10],specif:[2,9],specifi:[2,8,9,10],speed:[2,9],sqrt:[8,10],squar:[3,8,9,10],stabl:[8,10],standard:[8,10],start:[0,2,3,9],step:[0,8,9,10],stop:[0,9],store:[0,9],str:[0,2,9],straight:[3,9],string:[2,3,9],struct_tim:[9,11],structur:[0,9],subinterv:[8,10],submodul:7,subpackag:7,sum:[8,10],sundai:[1,9],symbol:9,system:[3,6,8,9,10],t_0:[8,10],t_i:[8,10],t_x:[6,9],t_y:[6,9],t_z:[6,9],tabl:[3,9],tagen:[1,9],term:[0,9],text:[8,10],than:[0,3,9],theata:[],therefor:[8,10],theta:[2,6,9],theta_end:[2,9],thi:[2,3,6,9],thick:[8,10],thicker:[2,9],thoma:[8,10],ti1:[8,10],time:[2,6,8,9,10,11],time_norm:[9,11],time_of_dai:7,to_str:[2,9],tol:[8,10],toler:[8,10],top:[3,9],torqu:[8,10],transform:[2,6,9,11],translat:[3,6,9],translate_xi:[3,9],trapez:[8,10],trapezium:[8,10],trapezoid:[8,10],trapezregel:[8,10],tupl:[0,2,3,8,9,10],two:[0,3,8,9,10],type:[0,1,2,3,6,8,9,10,11],typr:[2,9],u_i:[6,9],u_x:[6,9],u_z:[6,9],uid:[0,9],unicod:[2,9],uniform:[6,9],uniqu:[0,9],unique_end:[0,9],unit:[2,9],upper:[0,8,9,10],upsid:[2,9],usag:[2,9],use:[6,9],used:[8,10],uses:[2,9],using:[4,8,9,10],usw:[1,9],v_x:[6,9],v_y:[6,9],v_z:[6,9],valu:[2,6,8,9,10,11],varepsilon:[8,10],variabl:[1,2,8,9,10],varianc:[8,10],varphi:[2,9],vec:[3,6,9],vector:[3,6,9],veloc:[8,10],verbos:[0,8,9,10],verfahren:[8,10],vert_0:[8,10],vert_a:[8,10],vertcal:[3,9],vertic:[2,3,8,9,10],view:[2,9],vollmond:[1,9],von:[1,9],w_x:[6,9],w_y:[6,9],w_z:[6,9],wave:[2,9],wavelength:[2,9],wavenumb:[2,9],what:[3,9],when:[6,9],where:[2,6,8,9,10],which:[2,8,9,10],width:[2,3,8,9,10],wiki:[1,9],wikipedia:[1,9],window:[2,9],wise:[3,9],write:[0,9],x_0:[2,8,9,10],x_1:[2,3,8,9,10],x_2:[3,8,9,10],x_column:[0,9],x_fit:[8,10],x_i:[8,10],x_n:[8,10],xp0:[8,10],xpn:[8,10],xpp0:[8,10],xppn:[8,10],xyz:[6,9],y_1:[3,9],y_2:[3,9],y_column:[0,9],y_fit:[8,10],year:[1,9,11],zero:[2,6,9]},titles:["data module","date module","function module","geometry module","geometry_plot module","Welcome to pylib\u2019s documentation!","mathematics module","pylib","numerical package","pylib package","pylib.numerical package","time_of_day module"],titleterms:{"function":[2,9],content:[8,9,10],data:[0,9],date:[1,9],document:5,drawblock:9,fit:[8,10],geometri:[3,9],geometry_plot:[4,9],indic:5,integr:[8,10],mathemat:[6,9],modul:[0,1,2,3,4,6,8,9,10,11],numer:[8,10],ode:[8,10],ode_model:[8,10],packag:[8,9,10],pylib:[5,7,9,10],submodul:[8,9,10],subpackag:9,tabl:5,time_of_dai:[9,11],welcom:5}}) \ No newline at end of file +Search.setIndex({docnames:["index","modules","pylib","pylib.data","pylib.date","pylib.drawblock","pylib.function","pylib.geometry","pylib.geometry2d","pylib.geometry2d_plot","pylib.mathematics","pylib.numerical","pylib.numerical.fit","pylib.numerical.integration","pylib.numerical.ode","pylib.numerical.ode_model","pylib.time_of_day"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["index.rst","modules.rst","pylib.rst","pylib.data.rst","pylib.date.rst","pylib.drawblock.rst","pylib.function.rst","pylib.geometry.rst","pylib.geometry2d.rst","pylib.geometry2d_plot.rst","pylib.mathematics.rst","pylib.numerical.rst","pylib.numerical.fit.rst","pylib.numerical.integration.rst","pylib.numerical.ode.rst","pylib.numerical.ode_model.rst","pylib.time_of_day.rst"],objects:{"":{"function":[6,0,0,"-"],data:[3,0,0,"-"],date:[4,0,0,"-"],drawblock:[5,0,0,"-"],fit:[12,0,0,"-"],geometry2d:[8,0,0,"-"],geometry2d_plot:[9,0,0,"-"],geometry:[7,0,0,"-"],integration:[13,0,0,"-"],mathematics:[10,0,0,"-"],ode:[14,0,0,"-"],ode_model:[15,0,0,"-"],pylib:[2,0,0,"-"],time_of_day:[16,0,0,"-"]},"pylib.data":{fold_list:[3,1,1,""],get_id:[3,1,1,""],load:[3,1,1,""],read:[3,1,1,""],seq:[3,1,1,""],store:[3,1,1,""],unique_ending:[3,1,1,""],write:[3,1,1,""]},"pylib.date":{"gau\u00dfsche_osterformel":[4,1,1,""],ascension_of_jesus:[4,1,1,""],easter_friday:[4,1,1,""],easter_monday:[4,1,1,""],easter_sunday:[4,1,1,""],pentecost:[4,1,1,""]},"pylib.drawblock":{histogram:[5,1,1,""]},"pylib.function":{cosine_wave:[6,1,1,""],epitrochoid:[6,1,1,""],hypotrochoid:[6,1,1,""],sine_wave:[6,1,1,""],to_str:[6,1,1,""],transformation:[6,1,1,""]},"pylib.geometry":{CS:[7,2,1,""],Circle:[7,2,1,""],Direction:[7,2,1,""],Line:[7,2,1,""],Point:[7,2,1,""],Polygon:[7,2,1,""],Wireframe:[7,2,1,""],World:[7,2,1,""]},"pylib.geometry.CS":{get_coordinates:[7,3,1,""],x90:[7,3,1,""],xm90:[7,3,1,""],y90:[7,3,1,""],ym90:[7,3,1,""]},"pylib.geometry.Wireframe":{ch_cs:[7,3,1,""],points:[7,3,1,""],rotate_x:[7,3,1,""],rotate_y:[7,3,1,""],rotate_z:[7,3,1,""],scale:[7,3,1,""],translate:[7,3,1,""],xyz:[7,3,1,""]},"pylib.geometry.World":{add:[7,3,1,""],bounding_box:[7,3,1,""],center:[7,3,1,""],ch_cs:[7,3,1,""],cs:[7,3,1,""],objects:[7,3,1,""],rotate_x:[7,3,1,""],rotate_y:[7,3,1,""],rotate_z:[7,3,1,""],scale:[7,3,1,""],space_diagonal:[7,3,1,""],translate:[7,3,1,""]},"pylib.geometry2d":{angle:[8,1,1,""],cubic:[8,1,1,""],cubic_deg:[8,1,1,""],cubics:[8,1,1,""],distance:[8,1,1,""],interpolate_hermite:[8,1,1,""],line:[8,1,1,""],lines:[8,1,1,""],rectangle:[8,1,1,""],rotate:[8,1,1,""],rotate_deg:[8,1,1,""],rotate_xy:[8,1,1,""],square:[8,1,1,""],translate:[8,1,1,""],translate_xy:[8,1,1,""]},"pylib.geometry2d_plot":{plot_cubic_lines:[9,1,1,""],plot_lines:[9,1,1,""]},"pylib.mathematics":{lcm:[10,1,1,""],matrix:[10,2,1,""],vector:[10,2,1,""]},"pylib.mathematics.matrix":{rotate_x:[10,3,1,""],rotate_y:[10,3,1,""],rotate_z:[10,3,1,""],rx:[10,3,1,""],ry:[10,3,1,""],rz:[10,3,1,""],s:[10,3,1,""],scale:[10,3,1,""],t:[10,3,1,""],translate:[10,3,1,""]},"pylib.mathematics.vector":{abs:[10,3,1,""],ang:[10,3,1,""],arg:[10,3,1,""],ch_cs:[10,3,1,""],conjugate:[10,3,1,""],cross:[10,3,1,""],full:[10,3,1,""],im:[10,3,1,""],normalize:[10,3,1,""],ones:[10,3,1,""],random:[10,3,1,""],re:[10,3,1,""],rotate_x:[10,3,1,""],rotate_y:[10,3,1,""],rotate_z:[10,3,1,""],scale:[10,3,1,""],translate:[10,3,1,""],xyz:[10,3,1,""],zeros:[10,3,1,""]},"pylib.numerical":{fit:[12,0,0,"-"],integration:[13,0,0,"-"],ode:[14,0,0,"-"],ode_model:[15,0,0,"-"]},"pylib.numerical.fit":{gauss:[12,1,1,""],gauss_fit:[12,1,1,""]},"pylib.numerical.integration":{trapez:[13,1,1,""]},"pylib.numerical.ode":{e1:[14,1,1,""],e2:[14,1,1,""],e4:[14,1,1,""],fpi:[14,1,1,""],i1:[14,1,1,""],newmark_newtonraphson:[14,1,1,""],newmark_newtonraphson_rdk:[14,1,1,""]},"pylib.numerical.ode_model":{disk:[15,1,1,""],disk_nm:[15,1,1,""],disk_nmmdk:[15,1,1,""]},"pylib.time_of_day":{days:[16,1,1,""],days_norm:[16,1,1,""],hours:[16,1,1,""],hours_norm:[16,1,1,""],in_seconds:[16,1,1,""],minutes:[16,1,1,""],minutes_norm:[16,1,1,""],seconds:[16,1,1,""],seconds_norm:[16,1,1,""],transform:[16,1,1,""]},pylib:{"function":[6,0,0,"-"],data:[3,0,0,"-"],date:[4,0,0,"-"],drawblock:[5,0,0,"-"],geometry2d:[8,0,0,"-"],geometry2d_plot:[9,0,0,"-"],geometry:[7,0,0,"-"],mathematics:[10,0,0,"-"],numerical:[11,0,0,"-"],time_of_day:[16,0,0,"-"]}},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","class","Python class"],"3":["py","method","Python method"]},objtypes:{"0":"py:module","1":"py:function","2":"py:class","3":"py:method"},terms:{"1st":14,"259f":6,"28ff":6,"2\u03c0f":6,"2nd":14,"4th":14,"9fsche_osterformel":4,"\u03bb":6,"\u03bd":6,"\u03c0":6,"\u03c6":6,"\u03c9":6,"boolean":6,"case":[6,13],"char":[3,6],"class":[7,10],"default":[3,6,8,12,13,14,16],"f\u00fcr":4,"float":[3,6,8,12,13,14,16],"fr\u00fchling":4,"function":[1,2,10,12,13,14,15],"gau\u00dfsch":4,"gau\u00dfsche_osterformel":4,"int":[3,4,6,8,10,12,13,14],"korrekturgr\u00f6\u00df":4,"m\u00e4rz":4,"m\u00e4rzdatum":4,"new":[10,16],"return":[3,4,6,8,10,12,13,14,16],"s\u00e4kular":4,"s\u00e4kularzahl":4,"static":[7,10],"super":10,"switch":6,"true":[6,10],"vorw\u00e4rt":14,Das:4,The:[3,6,8,10,13,14,16],Use:10,_____:6,__contains__:10,__eq__:10,__ge__:10,__gt__:10,__imatmul__:10,__imul__:10,__isub__:10,__iter__:10,__le__:10,__lt__:10,__ne__:10,__setitem__:10,about:10,abs:10,absolut:8,add:7,addit:8,afterward:10,against:14,algorithmu:4,alia:6,als:4,also:6,amplitud:[6,12],analyt:13,ang:10,angl:8,angle1:8,angle2:8,angular:6,anim:6,approx:13,approxim:[12,13,14],april:4,area:13,arg:10,argument:[6,8],arithmet:3,around:[6,8,10],arrai:3,ascens:4,ascension_of_jesu:4,ascii:3,assum:8,attach:6,averag:16,avoid:10,axi:6,back:10,backward:14,base:[7,10,13],becaus:6,becom:14,begin:[10,14],beta:14,between:[3,6,8],binari:3,block:[5,6],bmatrix:[10,14],bool:[3,6,12,13,14],both:10,bottom:[6,8],bound:3,boundari:8,bounding_box:7,braill:6,build:8,calcul:[4,12,16],call:6,can:10,cauchi:14,cdot:14,center:[6,7,8,10],ch_c:[7,10],chang:[6,8],char_set:6,charact:[5,6],characterist:6,chart:[5,6],choos:14,circl:[6,7],close:[3,7],column:[3,6,10],common:[3,10],complex:10,composit:13,comput:10,condit:[8,14],conjug:10,consecut:3,constant:3,constructor:10,content:0,convert:[3,16],coordin:[7,8,10],copi:7,cos:[6,10],cosin:6,cosine_wav:6,counterclockwis:8,creat:[3,7,10],cross:10,cubic:8,cubic_deg:8,cudb:6,curv:6,cycl:6,dai:[4,16],data:[1,2,6,12],databas:6,date:[1,2,3,5,6,7,8,9,10,12,13,14,15,16],datetim:4,datum:4,days_norm:16,ddot:14,decid:8,defin:[8,10],definit:13,deflect:8,deform:8,degener:3,degre:[6,8],den:4,densiti:6,depend:6,der:4,derform:8,deriv:[14,15],des:4,describ:[6,15],deviat:[6,12],diamet:[14,15],die:4,differ:[3,14],differenti:[14,15],dimens:6,dimension:3,dimenson:3,dirction:10,direct:[6,7,8,10],disk:15,disk_nm:15,disk_nmmdk:15,displac:[8,14],distanc:[6,8],distribut:12,divid:13,doe:[6,8],dot:[5,6,10,14],down:6,draw:5,drawblock:[1,2],drawil:6,each:[6,8],easter:4,easter_fridai:4,easter_mondai:4,easter_sundai:4,eccentr:15,edg:8,either:[6,8,10],element:[3,6,8],empti:3,emptyset:3,end:[3,8,10,13,14],endpoint:8,entfernung:4,epitrochoid:6,equal:13,equalii:13,equat:[6,14,15],error:[12,14],ersten:4,euler:14,everi:14,exampl:[6,8,10,13,14],expect:12,explicit:14,explizit:14,exterior:6,f_n:13,factor:[6,8],fail:3,fals:[3,6,7,12,13,14],fassregel:13,file:3,file_nam:3,filenam:3,fill:10,fill_valu:10,first:[3,6,8,14,15],fisrt:6,fit:[2,11],fix:[6,14],float64:12,fnm:14,fold_list:3,follow:3,foral:13,forward:14,found:10,fourth:14,fpi:14,frac:[6,8,10,13,14],frame:6,frequenc:6,fridai:4,from:[3,6,10,14],full:[3,10,12],fwhm:12,gamma:14,gau:4,gauss:12,gauss_fit:12,gener:6,geometri:[1,2,8,9],geometry2d:[1,2],geometry2d_plot:[1,2],geometry_plot:8,get:[3,7],get_coordin:7,get_id:3,gilt:4,given:[3,8,10,12,14],global:[8,14],global_deform:8,govern:15,gregorian:16,gregorianischen:4,half:12,hand:10,happen:10,has:[3,10,14],have:[6,10],head:6,height:8,hermit:8,higher:6,histogram:[5,6],horizont:[6,8],hour:16,hours_norm:16,http:4,hyotrochoid:6,hypotrochoid:6,ids:3,imaginari:10,implicit:14,in_second:16,inc:8,incid:8,index:[0,3,6,8],index_offset:8,inform:[3,12,13,14],initi:[14,15],insid:6,integr:[2,11],integrand:13,interior:6,interpol:8,interpolate_hermit:8,interpret:[3,6],interv:13,isinst:10,iter:14,its:[6,7,10],jahr:4,jesu:4,johann:13,kalend:4,kalendarisch:4,keim:4,kepler:13,keplersch:13,keyword:8,kutta:14,kwarg:[8,9],kx1:3,lag:6,lambda:[6,13],last:6,lcm:[6,10],ldot:[13,14],lead:6,left:[3,6,8,13],leftrightarrow:12,len:10,length:[3,8,10,16],leq:13,lhape:10,lhd:8,like:10,limit:13,limits_:13,limits_a:13,line:[6,7,8],linear:6,list:[3,6,8,10,12,13,14,15],lmax:10,lmin:10,lns:9,load:3,local:[7,14],locat:10,lower:[3,13],lowest:10,lst:3,lvd:8,lvert:14,magnitud:10,make:6,manipul:3,march:4,mathemat:[1,2,6,7],mathmat:15,mathrm:[6,12,13],matplotlib:9,matrix:[7,10],max:6,max_iter:14,maximum:[12,14],mean:[6,14],method:14,min:6,minumum:3,minut:16,minutes_norm:16,model:15,modul:[0,1,2,11],modulu:10,mondai:4,mondparamet:4,mondschaltung:4,move:[6,10],multipl:10,mxn:3,ndarrai:12,necessari:13,necessarili:13,newmark:14,newmark_newtonraphson:14,newmark_newtonraphson_rdk:14,node:8,non:6,none:[3,5,6,7,8,10,12,13],norm:[6,10],normal:[6,10,16],note:10,number:[6,8,10,13,14],numer:[1,2],numerisch:13,numpi:12,object:[3,7,8,10],object_data:3,occur:6,ode:[2,11],ode_model:[2,11],offset:[12,16],often:6,omega:6,one:[3,6,8,14],ones:10,onli:3,open:[3,7],option:[6,8],order:[8,14,15],ordinari:[6,14,15],org:4,origin:[8,10],orthogon:10,oscil:6,osterentfernung:4,osterformel:4,ostergrenz:4,ostersonntag:4,other:8,otherwis:8,outer:10,outsid:6,over:6,own:7,packag:[0,1],page:0,paramet:[3,4,6,8,10,12,13,14,15,16],part:[6,10],pattern:6,peak:6,pentecost:4,per:[6,14],perform:10,period:6,phase:[6,10],phi:6,pixel:6,plane:8,plot:[6,8],plot_cubic_lin:9,plot_lin:[8,9],plotter:9,point1:[7,8],point1_i:8,point1_x:8,point2:[7,8],point2_i:8,point2_x:8,point3:8,point4:8,point:[6,7,8,13,14],point_i:8,point_x:8,points1_i:8,polygon:[7,8],polygonzugverfahren:14,popt:12,posit:[6,12],position_norm:16,print:[8,10,13,14],problem:[14,15],product:10,program:3,propag:6,proport:14,proportion:6,pts:8,pylab:9,quad:[13,14],quadratur:13,quasi:6,radian:[6,8],radiu:[6,7],random:10,rang:[6,16],rate:6,read:3,real:10,rectangl:8,refer:6,relat:6,repres:6,residuum:14,result:6,rhd:8,right:[3,6,8,10,13],roation:8,roll:6,rotat:[8,10,15],rotate_deg:8,rotate_i:[7,10],rotate_x:[7,10],rotate_xi:8,rotate_z:[7,10],rotation_plan:8,row:[6,10],rule:[10,13],rung:14,rvd:8,rvert:14,s_x:10,s_y:10,s_z:10,said:6,same:3,sampl:8,sample_point1_x:8,sample_point2_i:8,sample_point2_x:8,sample_points1_i:8,save_valu:13,scalar:10,scale:[6,7,10],scale_horizont:6,scale_i:8,scale_vert:6,scale_x:8,sche:14,search:0,second:[3,6,8,14,15,16],seconds_norm:16,segment:13,seq:3,sequenc:3,set:[6,14],shape:10,shift:6,shift_horizont:6,shift_vert:6,should:[8,10],side:13,sigma:12,simpson:13,simpsonregel:13,sin:[6,10],sine:6,sine_wav:6,sinusoid:6,size:[3,8,10,14],slope:8,smooth:6,solid:8,solut:[13,14],solv:14,solver:14,sonnenschaltung:4,sonntag:4,sourc:[3,4,5,6,7,8,9,10,12,13,14,15,16],space:[7,13],space_diagon:7,spacial:4,spatial:6,special:13,specif:6,specifi:[6,13],speed:6,sqrt:12,squar:[8,14],stabl:14,standard:[12,14],start:[3,6,8],step:[3,14],stop:3,store:3,str:[3,6],straight:8,string:[6,8],struct_tim:16,structur:3,subinterv:13,submodul:1,subpackag:1,sum:13,sundai:4,symbol:5,system:[7,8,10,14,15],t_0:14,t_i:14,t_x:10,t_y:10,t_z:10,tabl:8,tagen:4,term:3,text:14,than:[3,8],therefor:14,theta:[6,7,10],theta_end:6,thi:[6,7,8,10],thick:14,thicker:6,thoma:13,ti1:14,time:[6,10,14,15,16],time_norm:16,time_of_dai:[1,2],to_str:6,tol:14,toler:14,top:8,torqu:15,transform:[6,10,16],translat:[7,8,10],translate_xi:8,trapez:13,trapezium:13,trapezoid:13,trapezregel:13,tupl:[3,6,8,12],two:[3,8,13],type:[3,4,6,8,10,12,13,16],typr:6,u_i:10,u_x:10,u_z:10,uid:3,unicod:6,uniform:10,uniqu:3,unique_end:3,unit:6,upper:[3,13],upsid:6,usag:6,use:10,used:12,uses:6,using:[9,13],usw:4,v_x:10,v_y:10,v_z:10,valu:[6,10,12,13,14,15,16],varepsilon:14,variabl:[4,6,13],varianc:12,varphi:6,vec:[8,10],vector:[7,8,10],veloc:14,verbos:[3,12,13,14],verfahren:14,vert_0:13,vert_a:13,vertcal:8,vertic:[6,8,12],view:6,vollmond:4,von:4,w_x:10,w_y:10,w_z:10,wave:6,wavelength:6,wavenumb:6,what:8,when:10,where:[6,10,12],which:[6,14],width:[6,8,12],wiki:4,wikipedia:4,window:6,wirefram:7,wise:8,world:7,write:3,x90:7,x_0:[6,13,14],x_1:[6,8,13,14],x_2:[8,13,14],x_column:3,x_fit:12,x_i:[13,14],x_n:13,xm90:7,xp0:14,xpn:15,xpp0:14,xppn:15,xyz:[7,10],y90:7,y_1:8,y_2:8,y_column:3,y_fit:12,year:[4,16],ym90:7,zero:[6,10]},titles:["Welcome to pylib\u2019s documentation!","pylib","pylib package","pylib.data module","pylib.date module","pylib.drawblock module","pylib.function module","pylib.geometry module","pylib.geometry2d module","pylib.geometry2d_plot module","pylib.mathematics module","pylib.numerical package","pylib.numerical.fit module","pylib.numerical.integration module","pylib.numerical.ode module","pylib.numerical.ode_model module","pylib.time_of_day module"],titleterms:{"function":6,data:3,date:4,document:0,drawblock:5,fit:12,geometri:7,geometry2d:8,geometry2d_plot:9,indic:0,integr:13,mathemat:10,modul:[3,4,5,6,7,8,9,10,12,13,14,15,16],numer:[11,12,13,14,15],ode:14,ode_model:15,packag:[2,11],pylib:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],submodul:[2,11],subpackag:2,tabl:0,time_of_dai:16,welcom:0}}) \ No newline at end of file diff --git a/docs/source/conf.py b/docs/source/conf.py index 6f2afd2..77c126e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -25,7 +25,7 @@ copyright = '2019, Daniel Weschke' author = 'Daniel Weschke' # The full version, including alpha/beta/rc tags -release = '2019.5.19' +release = '2019.12.21' # -- General configuration --------------------------------------------------- diff --git a/docs/source/data.rst b/docs/source/data.rst deleted file mode 100644 index a5dfafd..0000000 --- a/docs/source/data.rst +++ /dev/null @@ -1,7 +0,0 @@ -data module -=========== - -.. automodule:: data - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/date.rst b/docs/source/date.rst deleted file mode 100644 index 67ad670..0000000 --- a/docs/source/date.rst +++ /dev/null @@ -1,7 +0,0 @@ -date module -=========== - -.. automodule:: date - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/function.rst b/docs/source/function.rst deleted file mode 100644 index 0e0123f..0000000 --- a/docs/source/function.rst +++ /dev/null @@ -1,7 +0,0 @@ -function module -=============== - -.. automodule:: function - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/geometry.rst b/docs/source/geometry.rst deleted file mode 100644 index 88d7478..0000000 --- a/docs/source/geometry.rst +++ /dev/null @@ -1,7 +0,0 @@ -geometry module -=============== - -.. automodule:: geometry - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/index.rst b/docs/source/index.rst index df4eb59..e0ae45b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -10,6 +10,8 @@ Welcome to pylib's documentation! :maxdepth: 2 :caption: Contents: + modules + Indices and tables diff --git a/docs/source/mathematics.rst b/docs/source/mathematics.rst deleted file mode 100644 index 8447d59..0000000 --- a/docs/source/mathematics.rst +++ /dev/null @@ -1,7 +0,0 @@ -mathematics module -================== - -.. automodule:: mathematics - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/numerical.rst b/docs/source/numerical.rst deleted file mode 100644 index bdde3b2..0000000 --- a/docs/source/numerical.rst +++ /dev/null @@ -1,46 +0,0 @@ -numerical package -================= - -Submodules ----------- - -numerical.fit module --------------------- - -.. automodule:: numerical.fit - :members: - :undoc-members: - :show-inheritance: - -numerical.integration module ----------------------------- - -.. automodule:: numerical.integration - :members: - :undoc-members: - :show-inheritance: - -numerical.ode module --------------------- - -.. automodule:: numerical.ode - :members: - :undoc-members: - :show-inheritance: - -numerical.ode\_model module ---------------------------- - -.. automodule:: numerical.ode_model - :members: - :undoc-members: - :show-inheritance: - - -Module contents ---------------- - -.. automodule:: numerical - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/pylib.data.rst b/docs/source/pylib.data.rst new file mode 100644 index 0000000..c742b93 --- /dev/null +++ b/docs/source/pylib.data.rst @@ -0,0 +1,7 @@ +pylib.data module +================= + +.. automodule:: pylib.data + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.date.rst b/docs/source/pylib.date.rst new file mode 100644 index 0000000..df3342e --- /dev/null +++ b/docs/source/pylib.date.rst @@ -0,0 +1,7 @@ +pylib.date module +================= + +.. automodule:: pylib.date + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.drawblock.rst b/docs/source/pylib.drawblock.rst new file mode 100644 index 0000000..9c98daf --- /dev/null +++ b/docs/source/pylib.drawblock.rst @@ -0,0 +1,7 @@ +pylib.drawblock module +====================== + +.. automodule:: pylib.drawblock + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.function.rst b/docs/source/pylib.function.rst new file mode 100644 index 0000000..b29f9f3 --- /dev/null +++ b/docs/source/pylib.function.rst @@ -0,0 +1,7 @@ +pylib.function module +===================== + +.. automodule:: pylib.function + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.geometry.rst b/docs/source/pylib.geometry.rst new file mode 100644 index 0000000..2914b7f --- /dev/null +++ b/docs/source/pylib.geometry.rst @@ -0,0 +1,7 @@ +pylib.geometry module +===================== + +.. automodule:: pylib.geometry + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.geometry2d.rst b/docs/source/pylib.geometry2d.rst new file mode 100644 index 0000000..c356c63 --- /dev/null +++ b/docs/source/pylib.geometry2d.rst @@ -0,0 +1,7 @@ +pylib.geometry2d module +======================= + +.. automodule:: pylib.geometry2d + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.geometry2d_plot.rst b/docs/source/pylib.geometry2d_plot.rst new file mode 100644 index 0000000..53dd963 --- /dev/null +++ b/docs/source/pylib.geometry2d_plot.rst @@ -0,0 +1,7 @@ +pylib.geometry2d\_plot module +============================= + +.. automodule:: pylib.geometry2d_plot + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.mathematics.rst b/docs/source/pylib.mathematics.rst new file mode 100644 index 0000000..07741ee --- /dev/null +++ b/docs/source/pylib.mathematics.rst @@ -0,0 +1,7 @@ +pylib.mathematics module +======================== + +.. automodule:: pylib.mathematics + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.numerical.fit.rst b/docs/source/pylib.numerical.fit.rst new file mode 100644 index 0000000..df29399 --- /dev/null +++ b/docs/source/pylib.numerical.fit.rst @@ -0,0 +1,7 @@ +pylib.numerical.fit module +========================== + +.. automodule:: pylib.numerical.fit + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.numerical.integration.rst b/docs/source/pylib.numerical.integration.rst new file mode 100644 index 0000000..98c1f0e --- /dev/null +++ b/docs/source/pylib.numerical.integration.rst @@ -0,0 +1,7 @@ +pylib.numerical.integration module +================================== + +.. automodule:: pylib.numerical.integration + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.numerical.ode.rst b/docs/source/pylib.numerical.ode.rst new file mode 100644 index 0000000..d4512f2 --- /dev/null +++ b/docs/source/pylib.numerical.ode.rst @@ -0,0 +1,7 @@ +pylib.numerical.ode module +========================== + +.. automodule:: pylib.numerical.ode + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.numerical.ode_model.rst b/docs/source/pylib.numerical.ode_model.rst new file mode 100644 index 0000000..7926ffa --- /dev/null +++ b/docs/source/pylib.numerical.ode_model.rst @@ -0,0 +1,7 @@ +pylib.numerical.ode\_model module +================================= + +.. automodule:: pylib.numerical.ode_model + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.numerical.rst b/docs/source/pylib.numerical.rst index 2222ee7..cb41396 100644 --- a/docs/source/pylib.numerical.rst +++ b/docs/source/pylib.numerical.rst @@ -1,46 +1,17 @@ pylib.numerical package ======================= -Submodules ----------- - -pylib.numerical.fit module --------------------------- - -.. automodule:: pylib.numerical.fit - :members: - :undoc-members: - :show-inheritance: - -pylib.numerical.integration module ----------------------------------- - -.. automodule:: pylib.numerical.integration - :members: - :undoc-members: - :show-inheritance: - -pylib.numerical.ode module --------------------------- - -.. automodule:: pylib.numerical.ode - :members: - :undoc-members: - :show-inheritance: - -pylib.numerical.ode\_model module ---------------------------------- - -.. automodule:: pylib.numerical.ode_model - :members: - :undoc-members: - :show-inheritance: - - -Module contents ---------------- - .. automodule:: pylib.numerical :members: :undoc-members: :show-inheritance: + +Submodules +---------- + +.. toctree:: + + pylib.numerical.fit + pylib.numerical.integration + pylib.numerical.ode + pylib.numerical.ode_model diff --git a/docs/source/pylib.rst b/docs/source/pylib.rst index af4bdd2..b66d511 100644 --- a/docs/source/pylib.rst +++ b/docs/source/pylib.rst @@ -1,6 +1,11 @@ pylib package ============= +.. automodule:: pylib + :members: + :undoc-members: + :show-inheritance: + Subpackages ----------- @@ -11,75 +16,14 @@ Subpackages Submodules ---------- -pylib.data module ------------------ +.. toctree:: -.. automodule:: pylib.data - :members: - :undoc-members: - :show-inheritance: - -pylib.date module ------------------ - -.. automodule:: pylib.date - :members: - :undoc-members: - :show-inheritance: - -pylib.drawblock module ----------------------- - -.. automodule:: pylib.drawblock - :members: - :undoc-members: - :show-inheritance: - -pylib.function module ---------------------- - -.. automodule:: pylib.function - :members: - :undoc-members: - :show-inheritance: - -pylib.geometry module ---------------------- - -.. automodule:: pylib.geometry - :members: - :undoc-members: - :show-inheritance: - -pylib.geometry\_plot module ---------------------------- - -.. automodule:: pylib.geometry_plot - :members: - :undoc-members: - :show-inheritance: - -pylib.mathematics module ------------------------- - -.. automodule:: pylib.mathematics - :members: - :undoc-members: - :show-inheritance: - -pylib.time\_of\_day module --------------------------- - -.. automodule:: pylib.time_of_day - :members: - :undoc-members: - :show-inheritance: - - -Module contents ---------------- - -.. automodule:: pylib - :members: - :undoc-members: - :show-inheritance: + pylib.data + pylib.date + pylib.drawblock + pylib.function + pylib.geometry + pylib.geometry2d + pylib.geometry2d_plot + pylib.mathematics + pylib.time_of_day diff --git a/docs/source/pylib.time_of_day.rst b/docs/source/pylib.time_of_day.rst new file mode 100644 index 0000000..a886eca --- /dev/null +++ b/docs/source/pylib.time_of_day.rst @@ -0,0 +1,7 @@ +pylib.time\_of\_day module +========================== + +.. automodule:: pylib.time_of_day + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/time_of_day.rst b/docs/source/time_of_day.rst deleted file mode 100644 index 2b8922a..0000000 --- a/docs/source/time_of_day.rst +++ /dev/null @@ -1,7 +0,0 @@ -time\_of\_day module -==================== - -.. automodule:: time_of_day - :members: - :undoc-members: - :show-inheritance: diff --git a/pylib/drawblock.py b/pylib/drawblock.py index 30c0def..6146980 100644 --- a/pylib/drawblock.py +++ b/pylib/drawblock.py @@ -1,11 +1,22 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +"""Draw with block characters. +:Date: 2019-11-15 + +.. module:: drawblock + :platform: *nix, Windows + :synopsis: Draw with block characters. + +.. moduleauthor:: Daniel Weschke +""" def histogram(f, x=None): """Histogram chart with block symbols. - dots: + :: + + dots ,_, |8| |7| @@ -17,8 +28,8 @@ def histogram(f, x=None): |1| ``` - ▁▂▃▄▅▆▇█ - 12345678 + ▁▂▃▄▅▆▇█ + 12345678 """ from collections import defaultdict chars = defaultdict(lambda: defaultdict(int)) diff --git a/pylib/geometry.py b/pylib/geometry.py index ff457d7..41f1be8 100644 --- a/pylib/geometry.py +++ b/pylib/geometry.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """2D geometry objects. -:Date: 2019-08-28 +:Date: 2019-12-21 .. module:: geometry :platform: *nix, Windows @@ -11,501 +11,215 @@ .. moduleauthor:: Daniel Weschke """ import math -import numpy as np +import copy +from mathematics import vector, matrix +class Direction(vector): + """Direction in local coordinate system""" + def __init__(self, x=1, y=0, z=0): + super().__init__([x, y, z, 0]) -def distance(point1, point2): - """Distance between two points (or length of a straight line). + def __str__(self): + return str(self.xyz()) - :param point1: first point (first end point of straight line) - :type point1: tuple - :param point2: second point (second end point of straight line) - :type point2: tuple +class Point(vector): + """Point in local coordinate system""" + def __init__(self, x=0, y=0, z=0): + super().__init__([x, y, z, 1]) - :returns: distance between the two points - :rtype: float + def __str__(self): + return str(self.xyz()) + +class CS(matrix): + """Coordinate system """ - return math.sqrt((point2[0]-point1[0])**2 + (point2[1]-point1[1])**2) + def __init__(self, x=[1, 0, 0], y=[0, 1, 0], z=[0, 0, 1]): + super().__init__([[*x, 0], [*y, 0], [*z, 0], [0, 0, 0, 1]]) + def __str__(self): + return '[' + ', '.join([str(i) for i in self.get_coordinates()]) + ']' -def angle(point1, point2=None): - """Angle of point or between two points. + @staticmethod + def x90(): + return CS((1, 0, 0), (0, 0, -1), (0, 1, 0)) - :param point1: (first) point - :type point1: tuple - :param point2: second point (default = None) - :type point2: tuple + @staticmethod + def xm90(): + return CS((1, 0, 0), (0, 0, 1), (0, -1, 0)) - :returns: angle of point or between two points - :rtype: float + @staticmethod + def y90(): + return CS((0, 0, 1), (0, 1, 0), (-1, 0, 0)) + + @staticmethod + def ym90(): + return CS((0, 0, -1), (0, 1, 0), (1, 0, 0)) + + def get_coordinates(self): + """Get coordinates in 3d space""" + return self[:3,:3] + +class World(): + """World-space with world-space coordinates """ - if point2 is None: - return math.atan2(point1[1], point1[0]) - return math.atan2(point2[1]-point1[1], point2[0]-point1[0]) + def __init__(self): + self._cs = CS() # Camera + self._objects = [] + self._store_init() + def __iter__(self): + """Returns the Iterator object""" + return iter(self.objects()) -def translate(vec, *pts): - """Translate a point or polygon by a given vector. + def _store_init(self): + """Initialize or reset calculated values, because a new object was added. + """ + self._bb = None + self._sd = None - :param vec: translation vector - :type vec: tuple - :param `*pts`: points to translate + def cs(self, cs=None): + if cs: + self._cs = cs + return self._cs - :returns: (point_x, point_y) or (point1, point2, ...) - :rtype: tuple + def ch_cs(self, cs): + self._cs = self._cs * cs + return self - .. seealso:: - :meth:`translate_xy` + def rotate_x(self, theta): + self._cs.rotate_x(theta) + return self + + def rotate_y(self, theta): + self._cs.rotate_y(theta) + return self + + def rotate_z(self, theta): + self._cs.rotate_z(theta) + return self + + def translate(self, tx, ty, tz): + self._cs.translate(tx, ty, tz) + return self + + def scale(self, sx, sy=None, sz=None): + self._cs.scale(sx, sy, sz) + return self + + def objects(self): + return [copy.deepcopy(i).ch_cs(self._cs) for i in self._objects] + + def add(self, *objects): + self._store_init() # calculated values are not correct anymore + [self._objects.append(i) for i in objects] + return self + + def bounding_box(self): + if self._bb is not None: + return self._bb + + xmin = math.inf + ymin = math.inf + zmin = math.inf + xmax = -math.inf + ymax = -math.inf + zmax = -math.inf + for i in self._objects: + xi, yi, zi = map(min, i.xyz()) + xs, ys, zs = map(max, i.xyz()) + #xmax = x if x > xmax: xmax = x + xmin = xi if xi < xmin else xmin + ymin = yi if yi < ymin else ymin + zmin = zi if zi < zmin else zmin + xmax = xs if xs > xmax else xmax + ymax = ys if ys > ymax else ymax + zmax = zs if zs > zmax else zmax + + self._bb = xmin, xmax, ymin, ymax, zmin, zmax + return self._bb + + def space_diagonal(self): + if self._sd is not None: + return self._sd + + bb = self.bounding_box() + a, b, c = bb[1]-bb[0], bb[3]-bb[2], bb[5]-bb[4] + return math.sqrt(a**2+b**2+c**2) + + def center(self): + bb = self.bounding_box() + self.ch_cs([[1,0,0,-(bb[1]-bb[0])/2],[0,1,0,-(bb[3]-bb[2])/2],[0,0,1,-(bb[5]-bb[4])/2],[0,0,0,1]]) + return self + +# TODO: Wireframe(list) or Wireframe(matrix) ? +# list of Points +class Wireframe(): + """Open and closed wireframe object in local coordinate system + + This class create its own points (copy). """ - vx, vy = vec - return tuple([(x+vx, y+vy) for (x, y) in pts]) - - -def translate_xy(vec, x, y): - """Translate a point or polygon by a given vector. - - :param vec: translation vector - :type vec: tuple - :param x: points to translate - :type x: int or float or list - :param y: points to translate - :type y: int or float or list - - :returns: (x', y') - :rtype: tuple - - .. seealso:: - :meth:`translate` - """ - vx, vy = vec - - if not hasattr(x, "__len__"): - x = [x] - - if not hasattr(y, "__len__"): - y = [y] - - xp = [xi+vx for xi in x] - yp = [yi+vy for yi in y] - - # no list if it is only one value - if len(xp) == 1: - return xp[0], yp[0] - - return xp, yp - - -def rotate(origin, angle, *pts, **kwargs): - """Rotate a point or polygon counterclockwise by a given angle - around a given origin. The angle should be given in radians. - - :param origin: the center of rotation - :type origin: tuple - :param angle: the rotation angle - :type angle: int or float - :param `*pts`: points to rotate - :param `**kwargs`: options - - :returns: (point_x, point_y) or (point1, point2, ...) - :rtype: tuple - - .. seealso:: - :meth:`rotate_xy` - """ - ox, oy = origin - - # add first point to the end - if "closed" in kwargs and kwargs["closed"] is True: - pts += (pts[0],) - - result = tuple([(ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy), - oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy)) - for (px, py) in pts]) - - # no tuple in tuple if it is only one point - if len(pts) == 1: - return result[0][0], result[0][1] - - return result - - -def rotate_deg(origin, angle, *pts, **kwargs): - """Rotate a point or polygon counterclockwise by a given angle - around a given origin. The angle should be given in degrees. - - :param origin: the center of rotation - :type origin: tuple - :param angle: the rotation angle - :type angle: int or float - :param `*pts`: points to rotate - :param `**kwargs`: options - - :returns: (point_x, point_y) or (point1, point2, ...) - :rtype: tuple - - .. seealso:: - :meth:`rotate` - """ - return rotate(origin, angle*math.pi/180, *pts, **kwargs) - - -def rotate_xy(origin, angle, x, y, **kwargs): - """Rotate x and y coordinates counterclockwise by a given angle - around a given origin. The angle should be given in radians. - - :param origin: the center of rotation - :type origin: tuple - :param angle: the rotation angle - :type angle: int or float - :param x: x coordinates - :type x: int or float or list - :param y: y coordinates - :type y: int or float or list - :param `**kwargs`: options - - .. seealso:: - :meth:`rotate` - """ - ox, oy = origin - - if not hasattr(x, "__len__"): - x = [x] - - if not hasattr(y, "__len__"): - y = [y] - - # add first point to the end - if "closed" in kwargs and kwargs["closed"] is True: - x.append(x[0]) - y.append(y[0]) - - x_result = [ox + math.cos(angle) * (xi - ox) - math.sin(angle) * (yi - oy) - for xi, yi in zip(x, y)] - - y_result = [oy + math.sin(angle) * (xi - ox) + math.cos(angle) * (yi - oy) - for xi, yi in zip(x, y)] - - # no list if it is only one value - if len(x_result) == 1: - return x_result[0], y_result[0] - - return x_result, y_result - - -def rectangle(width, height): - """\ - :param width: the width of the rectangle - :type width: int or float - :param height: the height of the rectangle - :type height: int or float - - :returns: (point1, point2, point3, point4) - :rtype: tuple - """ - pt1 = (-width/2, -height/2) - pt2 = (width/2, -height/2) - pt3 = (width/2, height/2) - pt4 = (-width/2, height/2) - return pt1, pt2, pt3, pt4, pt1 - - -def square(width): - """\ - :param width: the edge size of the square - :type width: int or float - - :returns: (point1, point2, point3, point4) - :rtype: tuple - - .. seealso:: - :meth:`rectangle` - """ - return rectangle(width, width) - - -def lines(pts, **kwargs): - """Lines defined by a list of end points. - - :param pts: list of points in absolute global coordinate system. If - keyword inc is given than the inc decides what the left and the - right end point of the line is, otherwise it is assumed that the - points build a solid line, that is lines between the given points - in given order. - :type pts: list - - :param `**kwargs`: options: - - * deformation -- list of points. Additional deformation - (translation) at point. - * factor -- factor of the deformation (default = 1). - * inc -- the incidence table, a list of 2 element lists. The inc - decides what the left and the right end point of the line is. - * index_offset -- starting index of lists (default = 0). - - :returns: list of endpoints for each line; - [((point1_x, point1_y), (point2_x, point2_y)), - (p1, p2), - ...] - :rtype: list - - .. seealso:: - :meth:`~geometry_plot.plot_lines` of the :mod:`geometry_plot` - module to plot the lines - """ - if 'index_offset' not in kwargs: - kwargs['index_offset'] = 0 - if 'deformation' in kwargs: - if 'factor' not in kwargs: - kwargs['factor'] = 1 - pts = [(p[0]+d[0]*kwargs['factor'], p[1]+d[1]*kwargs['factor']) for - p, d in zip(pts, kwargs['deformation'])] - if 'inc' in kwargs: - return [(pts[l-kwargs['index_offset']], - pts[r-kwargs['index_offset']]) for l, r in kwargs['inc']] - return list(zip(pts[:-1], pts[1:])) - - -def cubics(pts, **kwargs): - """Cubic lines defined by a list of two end points. The deformation - as displacement and rotation (radians) is defined element wise as - keyword argument deformation or global node wise as - global_deformation. The global coordinate system is xy. x in the - right direction and y in the top direction. - - :param pts: list of points in absolute global coordinate system. If - keyword inc is given than the inc decides what the left and the - right end point of the line is, otherwise it is assumed that the - points build a solid line, that is lines between the given points - in given order. - :type pts_rot: list - - :param `**kwargs`: options: - - * deformation -- list of deformation element wise. Additional - deformation (translation and rotation in radians) at element - left and right node. - * rotation_plane -- rotation plane of the element wise - deformation defined by a string; either 'xy' or 'xz' (default - = 'xy'). x in the right direction and y in the top direction - or z in the bottom direction. - * global_deformation -- list of deformation global node wise. - Additional deformation (horizontal translation, vertical - translation and rotation in radians) at node. - * factor -- factor of the derformation (default = 1). - * inc -- the incidence table, a list of 2 element lists. The inc - decides what the left and the right end point of the line is. - * index_offset -- starting index of lists (default = 0). - - :returns: list of endpoints for each line; - [(((point1_x, point1_y) angle1), ((point2_x, point2_y), angle2), - (p1, angle1, p2, angle2), - ...] - :rtype: list - """ - if 'index_offset' not in kwargs: - kwargs['index_offset'] = 0 - if 'deformation' in kwargs or 'global_deformation' in kwargs: - if 'factor' not in kwargs: - kwargs['factor'] = 1 - if 'inc' in kwargs: - if 'global_deformation' in kwargs: - lr = [(pts[l-kwargs['index_offset']], - pts[r-kwargs['index_offset']]) for l, r in kwargs['inc']] - ang = [angle(l, r) for l, r in lr] - # system deformation - U = kwargs['global_deformation'] - if 'rotation_plane' in kwargs and 'xz' == kwargs['rotation_plane']: - # system deformation left X Z RY right X Z RY element wise - # Z downwards -> convert to X Y RZ - Ue = [[ U[(l-kwargs['index_offset'])][0], - -U[(l-kwargs['index_offset'])][1], - U[(l-kwargs['index_offset'])][2], - U[(r-kwargs['index_offset'])][0], - -U[(r-kwargs['index_offset'])][1], - U[(r-kwargs['index_offset'])][2]] for l, r in kwargs['inc']] - else: - # system deformation left X Y RZ right X Y RZ element wise - Ue = [[U[(l-kwargs['index_offset'])][0], - U[(l-kwargs['index_offset'])][1], - U[(l-kwargs['index_offset'])][2], - U[(r-kwargs['index_offset'])][0], - U[(r-kwargs['index_offset'])][1], - U[(r-kwargs['index_offset'])][2]] for l, r in kwargs['inc']] - # element deformation, X Y RZ to x r rz - # back transformation T^T = [[c, s, 0], [-s, c, 0], [0, 0, 1]] - u = [[( math.cos(angi)*Uei[0]+math.sin(angi)*Uei[1])*kwargs['factor'], - (-math.sin(angi)*Uei[0]+math.cos(angi)*Uei[1])*kwargs['factor'], - Uei[2] *kwargs['factor'], - ( math.cos(angi)*Uei[3]+math.sin(angi)*Uei[4])*kwargs['factor'], - (-math.sin(angi)*Uei[3]+math.cos(angi)*Uei[4])*kwargs['factor'], - Uei[5] *kwargs['factor']] - for Uei, angi in zip(Ue, ang)] - else: # deformation - # the deformation is in element coordinate system, therefore the angle is needed - if 'rotation_plane' in kwargs and 'xz' == kwargs['rotation_plane']: - u = [[ ue[0]*kwargs['factor'], - -ue[1]*kwargs['factor'], - ue[2]*kwargs['factor'], - ue[3]*kwargs['factor'], - -ue[4]*kwargs['factor'], - ue[5]*kwargs['factor']] for ue in kwargs['deformation']] - else: - u = [[ui*kwargs['factor'] for ui in ue] for ue in kwargs['deformation']] - return [(pts[l-kwargs['index_offset']], - pts[r-kwargs['index_offset']], - d) for (l, r), d in zip(kwargs['inc'], u)] - return list(zip(pts[:-1], pts[1:])) - - -def interpolate_hermite(lvd, lr, rvd, rr, lhd=0, rhd=0, scale_x=1, scale_y=1, samples=10): - r"""Interpolate cubic line with hermite boundary conditions. - - :param lvd: left vertcal deflection - :type lvd: int or float - :param lr: left rotation - :type lr: int or float - :param rvd: right vertical deflection - :type rvd: int or float - :param rr: right rotation - :type rr: int or float - :param lhd: left horizontal deformation (default = 0) - :type lhd: int or float - :param rhd: right horizontal deformation (default = 0) - :type rhd: int or float - :param scale_x: length of element (default = 1) - :type scale_x: int or float - :param scale_y: factor of the deformation (default = 1). - This does not change the length. - :type scale_y: int or float - :param samples: number of sampling points (default = 10) - :type samples: int - - .. math:: - s = \frac{x - x_1}{L} \\ - x = s\,L + x_1 - - """ - L = scale_x - Lp = L + rhd - lhd - - # x=[0,1] in non-dimensional coordinates - x = np.linspace(0, 1, num=samples) - N1 = 1 - 3*x**2 + 2*x**3 - N2 = ( x - 2*x**2 + x**3)*Lp - N3 = 3*x**2 - 2*x**3 - N4 = ( - x**2 + x**3)*Lp - x = x*Lp - - - # x=[0,L] in global coordinates - x = np.linspace(0, Lp, num=samples) - N1 = 1 - 3*x**2/Lp**2 + 2*x**3/Lp**3 - N2 = x - 2*x**2/Lp + x**3/Lp**2 - N3 = 3*x**2/Lp**2 - 2*x**3/Lp**3 - N4 = - x**2/Lp + x**3/Lp**2 - - - v = N1*lvd + N2*lr + N3*rvd + N4*rr - x = x + lhd - y = v*scale_y - - return x, y - - -# -# matplotlib format, return lists for x and y -# - -def line(point1, point2, samples=2): - """Line defined by two end points. - - .. math:: - y = \\frac{y_2-y_1}{x_2-x_1}(x-x_1) + y_1 - - :param point1: one end point - :type point1: tuple - :param point2: other end point - :type point2: tuple - :param samples: number of sampling points (default = 2) - :type samples: int - - :returns: ((point1_x, point2_x), (points1_y, point2_y)) or - ([sample_point1_x, sample_point2_x, ...], - [sample_points1_y, sample_point2_y, ...]) - :rtype: tuple - - :Example: - - >>> x, y = line((0, 0), (1, 0)) - >>> print(x, y) - ((0, 1), (0, 0)) - """ - p1x, p1y = point1 - p2x, p2y = point2 - - denominator = (p1x - p2x) - - if samples > 2 and denominator > 0: - x = np.linspace(p1x, p2x, samples) - a = (p1y - p2y) / denominator - b = (p1x*p2y - p2x*p1y) / denominator - y = a*x + b - return x, y - return (p1x, p2x), (p1y, p2y) # matplotlib format - - -def cubic(point1, angle1, point2, angle2, samples=10): - """Cubic line defined by two end points and the rotation in radians - at the points. - - :param point1: one end point - :type point1: tuple - :param angle1: the slope at the one end point - :type angle1: int or float - :param point2: other end point - :type point2: tuple - :param angle2: the slope at the other end point - :type angle2: int or float - :param samples: number of sampling points (default = 10) - :type samples: int - - :returns: ([sample_point1_x, sample_point2_x, ...], - [sample_points1_y, sample_point2_y, ...]) - :rtype: tuple - """ - p1x, p1y = point1 - p2x, p2y = point2 - - x = np.linspace(p1x, p2x, num=samples) - - p1ys = math.tan(angle1) - p2ys = math.tan(angle2) - a = (p1x*p1ys + p1x*p2ys - p2x*p1ys - p2x*p2ys - 2*p1y + 2*p2y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) - b = (- p1x**2*p1ys - 2*p1x**2*p2ys - p1x*p2x*p1ys + p1x*p2x*p2ys + 3*p1x*p1y - 3*p1x*p2y + 2*p2x**2*p1ys + p2x**2*p2ys + 3*p2x*p1y - 3*p2x*p2y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) - c = (p1x**3*p2ys + 2*p1x**2*p2x*p1ys + p1x**2*p2x*p2ys - p1x*p2x**2*p1ys - 2*p1x*p2x**2*p2ys - 6*p1x*p2x*p1y + 6*p1x*p2x*p2y - p2x**3*p1ys)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) - d = (- p1x**3*p2x*p2ys + p1x**3*p2y - p1x**2*p2x**2*p1ys + p1x**2*p2x**2*p2ys - 3*p1x**2*p2x*p2y + p1x*p2x**3*p1ys + 3*p1x*p2x**2*p1y - p2x**3*p1y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) - y = a*x**3 + b*x**2 + c*x + d - return x, y - - -def cubic_deg(point1, angle1, point2, angle2): - """Cubic line defined by two end points and the roation in degree - at the points. - - :param point1: one end point - :type point1: tuple - :param angle1: the slope at the one end point - :type angle1: int or float - :param point2: other end point - :type point2: tuple - :param angle2: the slope at the other end point - :type angle2: int or float - - :returns: ([sample_point1_x, sample_point2_x, ...], - [sample_points1_y, sample_point2_y, ...]) - :rtype: tuple - - .. seealso:: - :meth:`cubic` - """ - return cubic(point1, angle1 * math.pi/180, point2, angle2 * math.pi/180) + def __init__(self, *points, closed=False): + self._points = [copy.copy(i) for i in points] + self.closed = closed + + def __str__(self): + return '[' + ', '.join([str(point) for point in self._points]) + ']' + + def __iter__(self): + """Returns the Iterator object""" + return iter(self.points()) + + def points(self): + """Get coordinates in 3d space""" + result = [i for i in self._points] + return result if not self.closed else result + [result[0]] + + def xyz(self): + return zip(*[i.xyz() for i in self.points()]) + + def rotate_x(self, theta): + self._points = [point.rotate_x(theta) for point in self._points] + return self + + def rotate_y(self, theta): + self._points = [point.rotate_y(theta) for point in self._points] + return self + + def rotate_z(self, theta): + self._points = [point.rotate_z(theta) for point in self._points] + return self + + def translate(self, tx, ty, tz): + self._points = [point.translate(tx, ty, tz) for point in self._points] + return self + + def scale(self, sx, sy=None, sz=None): + if not sy: + sy = sx + sz = sx + self._points = [point.scale(sx, sy, sz) for point in self._points] + return self + + def ch_cs(self, cs): + self._points = [point.ch_cs(cs) for point in self._points] + return self + +class Line(Wireframe): + """Line a open wireframe object in local coordinate system""" + def __init__(self, point1=Point(-1, 0, 0), point2=Point(1, 0, 0)): + super().__init__(point1, point2) + +class Polygon(Wireframe): + """Polygon as closed wireframe object in local coordinate system""" + def __init__(self, *points): + super().__init__(*points, closed=True) + +class Circle(Polygon): + """Circle a closed wireframe object in local coordinate system""" + def __init__(self, radius=1, n=10): + points = [] + for i in range(n): + x = radius * math.sin(i*2*math.pi/n) + y = radius * math.cos(i*2*math.pi/n) + points.append(Point(x, y, 0)) + super().__init__(*points) diff --git a/pylib/geometry2d.py b/pylib/geometry2d.py new file mode 100644 index 0000000..7c733a9 --- /dev/null +++ b/pylib/geometry2d.py @@ -0,0 +1,511 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""2D geometry objects. + +:Date: 2019-08-28 + +.. module:: geometry2d + :platform: *nix, Windows + :synopsis: 2D geometry objects. + +.. moduleauthor:: Daniel Weschke +""" +import math +import numpy as np + + +def distance(point1, point2): + """Distance between two points (or length of a straight line). + + :param point1: first point (first end point of straight line) + :type point1: tuple + :param point2: second point (second end point of straight line) + :type point2: tuple + + :returns: distance between the two points + :rtype: float + """ + return math.sqrt((point2[0]-point1[0])**2 + (point2[1]-point1[1])**2) + + +def angle(point1, point2=None): + """Angle of point or between two points. + + :param point1: (first) point + :type point1: tuple + :param point2: second point (default = None) + :type point2: tuple + + :returns: angle of point or between two points + :rtype: float + """ + if point2 is None: + return math.atan2(point1[1], point1[0]) + return math.atan2(point2[1]-point1[1], point2[0]-point1[0]) + + +def translate(vec, *pts): + """Translate a point or polygon by a given vector. + + :param vec: translation vector + :type vec: tuple + :param `*pts`: points to translate + + :returns: (point_x, point_y) or (point1, point2, ...) + :rtype: tuple + + .. seealso:: + :meth:`translate_xy` + """ + vx, vy = vec + return tuple([(x+vx, y+vy) for (x, y) in pts]) + + +def translate_xy(vec, x, y): + """Translate a point or polygon by a given vector. + + :param vec: translation vector + :type vec: tuple + :param x: points to translate + :type x: int or float or list + :param y: points to translate + :type y: int or float or list + + :returns: (x', y') + :rtype: tuple + + .. seealso:: + :meth:`translate` + """ + vx, vy = vec + + if not hasattr(x, "__len__"): + x = [x] + + if not hasattr(y, "__len__"): + y = [y] + + xp = [xi+vx for xi in x] + yp = [yi+vy for yi in y] + + # no list if it is only one value + if len(xp) == 1: + return xp[0], yp[0] + + return xp, yp + + +def rotate(origin, angle, *pts, **kwargs): + """Rotate a point or polygon counterclockwise by a given angle + around a given origin. The angle should be given in radians. + + :param origin: the center of rotation + :type origin: tuple + :param angle: the rotation angle + :type angle: int or float + :param `*pts`: points to rotate + :param `**kwargs`: options + + :returns: (point_x, point_y) or (point1, point2, ...) + :rtype: tuple + + .. seealso:: + :meth:`rotate_xy` + """ + ox, oy = origin + + # add first point to the end + if "closed" in kwargs and kwargs["closed"] is True: + pts += (pts[0],) + + result = tuple([(ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy), + oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy)) + for (px, py) in pts]) + + # no tuple in tuple if it is only one point + if len(pts) == 1: + return result[0][0], result[0][1] + + return result + + +def rotate_deg(origin, angle, *pts, **kwargs): + """Rotate a point or polygon counterclockwise by a given angle + around a given origin. The angle should be given in degrees. + + :param origin: the center of rotation + :type origin: tuple + :param angle: the rotation angle + :type angle: int or float + :param `*pts`: points to rotate + :param `**kwargs`: options + + :returns: (point_x, point_y) or (point1, point2, ...) + :rtype: tuple + + .. seealso:: + :meth:`rotate` + """ + return rotate(origin, angle*math.pi/180, *pts, **kwargs) + + +def rotate_xy(origin, angle, x, y, **kwargs): + """Rotate x and y coordinates counterclockwise by a given angle + around a given origin. The angle should be given in radians. + + :param origin: the center of rotation + :type origin: tuple + :param angle: the rotation angle + :type angle: int or float + :param x: x coordinates + :type x: int or float or list + :param y: y coordinates + :type y: int or float or list + :param `**kwargs`: options + + .. seealso:: + :meth:`rotate` + """ + ox, oy = origin + + if not hasattr(x, "__len__"): + x = [x] + + if not hasattr(y, "__len__"): + y = [y] + + # add first point to the end + if "closed" in kwargs and kwargs["closed"] is True: + x.append(x[0]) + y.append(y[0]) + + x_result = [ox + math.cos(angle) * (xi - ox) - math.sin(angle) * (yi - oy) + for xi, yi in zip(x, y)] + + y_result = [oy + math.sin(angle) * (xi - ox) + math.cos(angle) * (yi - oy) + for xi, yi in zip(x, y)] + + # no list if it is only one value + if len(x_result) == 1: + return x_result[0], y_result[0] + + return x_result, y_result + + +def rectangle(width, height): + """\ + :param width: the width of the rectangle + :type width: int or float + :param height: the height of the rectangle + :type height: int or float + + :returns: (point1, point2, point3, point4) + :rtype: tuple + """ + pt1 = (-width/2, -height/2) + pt2 = (width/2, -height/2) + pt3 = (width/2, height/2) + pt4 = (-width/2, height/2) + return pt1, pt2, pt3, pt4, pt1 + + +def square(width): + """\ + :param width: the edge size of the square + :type width: int or float + + :returns: (point1, point2, point3, point4) + :rtype: tuple + + .. seealso:: + :meth:`rectangle` + """ + return rectangle(width, width) + + +def lines(pts, **kwargs): + """Lines defined by a list of end points. + + :param pts: list of points in absolute global coordinate system. If + keyword inc is given than the inc decides what the left and the + right end point of the line is, otherwise it is assumed that the + points build a solid line, that is lines between the given points + in given order. + :type pts: list + + :param `**kwargs`: options: + + * deformation -- list of points. Additional deformation + (translation) at point. + * factor -- factor of the deformation (default = 1). + * inc -- the incidence table, a list of 2 element lists. The inc + decides what the left and the right end point of the line is. + * index_offset -- starting index of lists (default = 0). + + :returns: list of endpoints for each line; + [((point1_x, point1_y), (point2_x, point2_y)), + (p1, p2), + ...] + :rtype: list + + .. seealso:: + :meth:`~geometry_plot.plot_lines` of the :mod:`geometry_plot` + module to plot the lines + """ + if 'index_offset' not in kwargs: + kwargs['index_offset'] = 0 + if 'deformation' in kwargs: + if 'factor' not in kwargs: + kwargs['factor'] = 1 + pts = [(p[0]+d[0]*kwargs['factor'], p[1]+d[1]*kwargs['factor']) for + p, d in zip(pts, kwargs['deformation'])] + if 'inc' in kwargs: + return [(pts[l-kwargs['index_offset']], + pts[r-kwargs['index_offset']]) for l, r in kwargs['inc']] + return list(zip(pts[:-1], pts[1:])) + + +def cubics(pts, **kwargs): + """Cubic lines defined by a list of two end points. The deformation + as displacement and rotation (radians) is defined element wise as + keyword argument deformation or global node wise as + global_deformation. The global coordinate system is xy. x in the + right direction and y in the top direction. + + :param pts: list of points in absolute global coordinate system. If + keyword inc is given than the inc decides what the left and the + right end point of the line is, otherwise it is assumed that the + points build a solid line, that is lines between the given points + in given order. + :type pts_rot: list + + :param `**kwargs`: options: + + * deformation -- list of deformation element wise. Additional + deformation (translation and rotation in radians) at element + left and right node. + * rotation_plane -- rotation plane of the element wise + deformation defined by a string; either 'xy' or 'xz' (default + = 'xy'). x in the right direction and y in the top direction + or z in the bottom direction. + * global_deformation -- list of deformation global node wise. + Additional deformation (horizontal translation, vertical + translation and rotation in radians) at node. + * factor -- factor of the derformation (default = 1). + * inc -- the incidence table, a list of 2 element lists. The inc + decides what the left and the right end point of the line is. + * index_offset -- starting index of lists (default = 0). + + :returns: list of endpoints for each line; + [(((point1_x, point1_y) angle1), ((point2_x, point2_y), angle2), + (p1, angle1, p2, angle2), + ...] + :rtype: list + """ + if 'index_offset' not in kwargs: + kwargs['index_offset'] = 0 + if 'deformation' in kwargs or 'global_deformation' in kwargs: + if 'factor' not in kwargs: + kwargs['factor'] = 1 + if 'inc' in kwargs: + if 'global_deformation' in kwargs: + lr = [(pts[l-kwargs['index_offset']], + pts[r-kwargs['index_offset']]) for l, r in kwargs['inc']] + ang = [angle(l, r) for l, r in lr] + # system deformation + U = kwargs['global_deformation'] + if 'rotation_plane' in kwargs and 'xz' == kwargs['rotation_plane']: + # system deformation left X Z RY right X Z RY element wise + # Z downwards -> convert to X Y RZ + Ue = [[ U[(l-kwargs['index_offset'])][0], + -U[(l-kwargs['index_offset'])][1], + U[(l-kwargs['index_offset'])][2], + U[(r-kwargs['index_offset'])][0], + -U[(r-kwargs['index_offset'])][1], + U[(r-kwargs['index_offset'])][2]] for l, r in kwargs['inc']] + else: + # system deformation left X Y RZ right X Y RZ element wise + Ue = [[U[(l-kwargs['index_offset'])][0], + U[(l-kwargs['index_offset'])][1], + U[(l-kwargs['index_offset'])][2], + U[(r-kwargs['index_offset'])][0], + U[(r-kwargs['index_offset'])][1], + U[(r-kwargs['index_offset'])][2]] for l, r in kwargs['inc']] + # element deformation, X Y RZ to x r rz + # back transformation T^T = [[c, s, 0], [-s, c, 0], [0, 0, 1]] + u = [[( math.cos(angi)*Uei[0]+math.sin(angi)*Uei[1])*kwargs['factor'], + (-math.sin(angi)*Uei[0]+math.cos(angi)*Uei[1])*kwargs['factor'], + Uei[2] *kwargs['factor'], + ( math.cos(angi)*Uei[3]+math.sin(angi)*Uei[4])*kwargs['factor'], + (-math.sin(angi)*Uei[3]+math.cos(angi)*Uei[4])*kwargs['factor'], + Uei[5] *kwargs['factor']] + for Uei, angi in zip(Ue, ang)] + else: # deformation + # the deformation is in element coordinate system, therefore the angle is needed + if 'rotation_plane' in kwargs and 'xz' == kwargs['rotation_plane']: + u = [[ ue[0]*kwargs['factor'], + -ue[1]*kwargs['factor'], + ue[2]*kwargs['factor'], + ue[3]*kwargs['factor'], + -ue[4]*kwargs['factor'], + ue[5]*kwargs['factor']] for ue in kwargs['deformation']] + else: + u = [[ui*kwargs['factor'] for ui in ue] for ue in kwargs['deformation']] + return [(pts[l-kwargs['index_offset']], + pts[r-kwargs['index_offset']], + d) for (l, r), d in zip(kwargs['inc'], u)] + return list(zip(pts[:-1], pts[1:])) + + +def interpolate_hermite(lvd, lr, rvd, rr, lhd=0, rhd=0, scale_x=1, scale_y=1, samples=10): + r"""Interpolate cubic line with hermite boundary conditions. + + :param lvd: left vertcal deflection + :type lvd: int or float + :param lr: left rotation + :type lr: int or float + :param rvd: right vertical deflection + :type rvd: int or float + :param rr: right rotation + :type rr: int or float + :param lhd: left horizontal deformation (default = 0) + :type lhd: int or float + :param rhd: right horizontal deformation (default = 0) + :type rhd: int or float + :param scale_x: length of element (default = 1) + :type scale_x: int or float + :param scale_y: factor of the deformation (default = 1). + This does not change the length. + :type scale_y: int or float + :param samples: number of sampling points (default = 10) + :type samples: int + + .. math:: + s = \frac{x - x_1}{L} \\ + x = s\,L + x_1 + + """ + L = scale_x + Lp = L + rhd - lhd + + # x=[0,1] in non-dimensional coordinates + x = np.linspace(0, 1, num=samples) + N1 = 1 - 3*x**2 + 2*x**3 + N2 = ( x - 2*x**2 + x**3)*Lp + N3 = 3*x**2 - 2*x**3 + N4 = ( - x**2 + x**3)*Lp + x = x*Lp + + + # x=[0,L] in global coordinates + x = np.linspace(0, Lp, num=samples) + N1 = 1 - 3*x**2/Lp**2 + 2*x**3/Lp**3 + N2 = x - 2*x**2/Lp + x**3/Lp**2 + N3 = 3*x**2/Lp**2 - 2*x**3/Lp**3 + N4 = - x**2/Lp + x**3/Lp**2 + + + v = N1*lvd + N2*lr + N3*rvd + N4*rr + x = x + lhd + y = v*scale_y + + return x, y + + +# +# matplotlib format, return lists for x and y +# + +def line(point1, point2, samples=2): + """Line defined by two end points. + + .. math:: + y = \\frac{y_2-y_1}{x_2-x_1}(x-x_1) + y_1 + + :param point1: one end point + :type point1: tuple + :param point2: other end point + :type point2: tuple + :param samples: number of sampling points (default = 2) + :type samples: int + + :returns: ((point1_x, point2_x), (points1_y, point2_y)) or + ([sample_point1_x, sample_point2_x, ...], + [sample_points1_y, sample_point2_y, ...]) + :rtype: tuple + + :Example: + + >>> x, y = line((0, 0), (1, 0)) + >>> print(x, y) + ((0, 1), (0, 0)) + """ + p1x, p1y = point1 + p2x, p2y = point2 + + denominator = (p1x - p2x) + + if samples > 2 and denominator > 0: + x = np.linspace(p1x, p2x, samples) + a = (p1y - p2y) / denominator + b = (p1x*p2y - p2x*p1y) / denominator + y = a*x + b + return x, y + return (p1x, p2x), (p1y, p2y) # matplotlib format + + +def cubic(point1, angle1, point2, angle2, samples=10): + """Cubic line defined by two end points and the rotation in radians + at the points. + + :param point1: one end point + :type point1: tuple + :param angle1: the slope at the one end point + :type angle1: int or float + :param point2: other end point + :type point2: tuple + :param angle2: the slope at the other end point + :type angle2: int or float + :param samples: number of sampling points (default = 10) + :type samples: int + + :returns: ([sample_point1_x, sample_point2_x, ...], + [sample_points1_y, sample_point2_y, ...]) + :rtype: tuple + """ + p1x, p1y = point1 + p2x, p2y = point2 + + x = np.linspace(p1x, p2x, num=samples) + + p1ys = math.tan(angle1) + p2ys = math.tan(angle2) + a = (p1x*p1ys + p1x*p2ys - p2x*p1ys - p2x*p2ys - 2*p1y + 2*p2y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) + b = (- p1x**2*p1ys - 2*p1x**2*p2ys - p1x*p2x*p1ys + p1x*p2x*p2ys + 3*p1x*p1y - 3*p1x*p2y + 2*p2x**2*p1ys + p2x**2*p2ys + 3*p2x*p1y - 3*p2x*p2y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) + c = (p1x**3*p2ys + 2*p1x**2*p2x*p1ys + p1x**2*p2x*p2ys - p1x*p2x**2*p1ys - 2*p1x*p2x**2*p2ys - 6*p1x*p2x*p1y + 6*p1x*p2x*p2y - p2x**3*p1ys)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) + d = (- p1x**3*p2x*p2ys + p1x**3*p2y - p1x**2*p2x**2*p1ys + p1x**2*p2x**2*p2ys - 3*p1x**2*p2x*p2y + p1x*p2x**3*p1ys + 3*p1x*p2x**2*p1y - p2x**3*p1y)/(p1x**3 - 3*p1x**2*p2x + 3*p1x*p2x**2 - p2x**3) + y = a*x**3 + b*x**2 + c*x + d + return x, y + + +def cubic_deg(point1, angle1, point2, angle2): + """Cubic line defined by two end points and the roation in degree + at the points. + + :param point1: one end point + :type point1: tuple + :param angle1: the slope at the one end point + :type angle1: int or float + :param point2: other end point + :type point2: tuple + :param angle2: the slope at the other end point + :type angle2: int or float + + :returns: ([sample_point1_x, sample_point2_x, ...], + [sample_points1_y, sample_point2_y, ...]) + :rtype: tuple + + .. seealso:: + :meth:`cubic` + """ + return cubic(point1, angle1 * math.pi/180, point2, angle2 * math.pi/180) diff --git a/pylib/geometry_plot.py b/pylib/geometry2d_plot.py similarity index 96% rename from pylib/geometry_plot.py rename to pylib/geometry2d_plot.py index 11c81bb..7f5aa65 100644 --- a/pylib/geometry_plot.py +++ b/pylib/geometry2d_plot.py @@ -4,15 +4,14 @@ :Date: 2019-08-20 -.. module:: geometry_plot +.. module:: geometry2d_plot :platform: *nix, Windows - :synopsis: Geometry plotting. + :synopsis: 2D geometry plotting. .. moduleauthor:: Daniel Weschke """ -import math import pylab -from geometry import ( +from geometry2d import ( distance, angle, line, interpolate_hermite, rotate_xy, translate_xy ) diff --git a/tests/test_geometry.py b/tests/test_geometry.py index d73c1da..df9cf09 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -1,6 +1,6 @@ """Test of geometry module. -:Date: 2019-08-20 +:Date: 2019-12-21 .. module:: test_geometry :platform: *nix, Windows @@ -13,247 +13,95 @@ import unittest import os import sys import math -from numpy import allclose sys.path.insert(0, os.path.abspath('../pylib')) -from data import fold_list -from geometry import translate_xy, rotate_xy, interpolate_hermite, lines, cubics -from geometry_plot import plot_lines, plot_cubic_lines - +from mathematics import vector +from geometry import Direction, Point, CS, Wireframe, Polygon class TestGeometry(unittest.TestCase): - global_points = [(0, 0), - (0, 3), - (3, 3), - (3, 0), - (3, 6), - (5, 6), - (5, 3), - (5, 0), - (7, 0)] - inc = [[1, 2], - [2, 3], - [4, 3], - [3, 5], - [5, 6], - [6, 7], - [7, 8], - [9, 7]] - # global deformation, horizontal right, vertical down, rotation - U = [ - 0.00000, 0.00000, -5.02012, - 12.77012, 0.06333, -2.72988, - 12.69350, 0.08599, 3.14685, - 0.00000, 0.00000, -7.92017, - -12.39817, 0.17450, 4.14446, - -12.43490, 0.32001, -3.10697, - -26.77684, 0.16528, 2.98214, - 0.00000, 0.00000, 0.00000, - -26.50991, 0.00000, -1.36053, - ] - U = [Ui/1000 for Ui in U] + def test_Direction(self): + p = Direction() + self.assertIsInstance( + p, list) + self.assertEqual( + p, [1, 0, 0, 0]) + self.assertEqual( + Direction(2, 3, 4), [2, 3, 4, 0]) - # global deformation, only horizontal right and vertical down - U2 = [ui for i, ui in enumerate(U) if i%3 != 2] + self.assertIsInstance( + p, vector) + self.assertEqual( + p, vector([1, 0, 0, 0])) + self.assertEqual( + Direction(2, 3, 4), vector([2, 3, 4, 0])) - # global deformation, horizontal right, vertical up, rotation - UN = [Ui if i%3 != 1 else -Ui for i, Ui in enumerate(U)] + def test_Direction_xyz(self): + self.assertEqual( + Direction().xyz(), [1, 0, 0]) + self.assertEqual( + Direction(1, -1, 1).xyz(), [1, -1, 1]) - # local deformation, horizontal right, vertical down, rotation - u = [ - [ 0.000000, 0.000000, -0.005020, -0.000063, 0.012770, -0.002730], - [ 0.012770, 0.000063, -0.002730, 0.012693, 0.000086, 0.003147], - [ 0.000000, 0.000000, -0.007920, -0.000086, 0.012693, 0.003147], - [-0.000086, 0.012693, 0.003147, -0.000175, -0.012398, 0.004144], - [-0.012398, 0.000175, 0.004144, -0.012435, 0.000320, -0.003107], - [ 0.000320, 0.012435, -0.003107, 0.000165, 0.026777, 0.002982], - [ 0.000165, 0.026777, 0.002982, 0.000000, 0.000000, 0.000000], - [ 0.014705, -0.022058, -0.001361, 0.014716, -0.022371, 0.002982], - ] + def test_Point(self): + p = Point() + self.assertIsInstance( + p, list) + self.assertEqual( + p, [0, 0, 0, 1]) + self.assertEqual( + Point(2, 3, 4), [2, 3, 4, 1]) - # local deformation, horizontal right, vertical up, rotation - uN = [[uii if i%3 != 1 else -uii for i, uii in enumerate(ui)] for ui in u] + self.assertIsInstance( + p, vector) + self.assertEqual( + p, vector([0, 0, 0, 1])) + self.assertEqual( + Point(2, 3, 4), vector([2, 3, 4, 1])) - # exaggeration factor for the deformation - factor = 20 + def test_Point_xyz(self): + self.assertEqual( + Point().xyz(), [0, 0, 0]) + self.assertEqual( + Point(1, -1, 1).xyz(), [1, -1, 1]) - # test of cubic lines - test_lns_l = [((0, 0), (0, 3), [0.0, -0.0, -0.1004, -0.00126, -0.2554, -0.0546]), - ((0, 3), (3, 3), [0.2554, -0.00126, -0.0546, 0.25386, -0.00172, 0.06294]), - ((3, 0), (3, 3), [0.0, -0.0, -0.1584, -0.00172, -0.25386, 0.06294]), - ((3, 3), (3, 6), [-0.00172, -0.25386, 0.06294, -0.0035, 0.24796, 0.08288]), - ((3, 6), (5, 6), [-0.24796, -0.0035, 0.08288, -0.2487, -0.0064, -0.06214]), - ((5, 6), (5, 3), [0.0064, -0.2487, -0.06214, 0.0033, -0.53554, 0.05964]), - ((5, 3), (5, 0), [0.0033, -0.53554, 0.05964, 0.0, -0.0, 0.0]), - ((7, 0), (5, 3), [0.2941, 0.44116, -0.02722, 0.29432, 0.44742, 0.05964])] - test_lns_g = [((0, 0), (0, 3), [0.0, -0.0, -0.1004024, -0.0012666, -0.2554024, -0.0545976]), - ((0, 3), (3, 3), [0.2554024, -0.0012666, -0.0545976, 0.25387, -0.0017198, 0.062937]), - ((3, 0), (3, 3), [0.0, -0.0, -0.1584034, -0.0017198, -0.25387, 0.062937]), - ((3, 3), (3, 6), [-0.0017198, -0.25387, 0.062937, -0.00349, 0.2479634, 0.0828892]), - ((3, 6), (5, 6), [-0.2479634, -0.00349, 0.0828892, -0.248698, -0.0064002, -0.0621394]), - ((5, 6), (5, 3), [0.0064002, -0.248698, -0.0621394, 0.0033056, -0.5355368, 0.0596428]), - ((5, 3), (5, 0), [0.0033056, -0.5355368, 0.0596428, 0.0, 0.0, 0.0]), - ((7, 0), (5, 3), [0.2941010455782632, 0.441151568367395, -0.0272106, 0.29431194259286797, 0.4474271690373891, 0.0596428])] + def test_Wireframe(self): + self.assertEqual( + Wireframe().points(), []) - def test_lines(self): - """test lines function (undeformed structure)""" - lns = lines(self.global_points, inc=self.inc, index_offset=1) - test = [((0, 0), (0, 3)), ((0, 3), (3, 3)), ((3, 0), (3, 3)), - ((3, 3), (3, 6)), ((3, 6), (5, 6)), ((5, 6), (5, 3)), - ((5, 3), (5, 0)), ((7, 0), (5, 3))] + # it is possible to assign other objects then Points but/and the + # class will not test if Points are used, this is just assumed + self.assertEqual( + Wireframe([]).points(), [[]]) - self.assertEqual(lns, test) - plot_lines(lns, linestyle=':') + self.assertEqual( + Wireframe(Point()).points(), [[0, 0, 0, 1]]) + self.assertEqual( + Wireframe(Point()).points(), [vector([0, 0, 0, 1])]) - def test_lines_deformation(self): - """test lines function with deformation (deformed structure)""" - lns = lines(self.global_points, deformation=fold_list(self.U2, 2), factor=self.factor, inc=self.inc, index_offset=1) - test = [((0.0, 0.0), (0.25540240000000003, 3.0012666)), ((0.25540240000000003, 3.0012666), (3.25387, 3.0017198)), ((3.0, 0.0), (3.25387, 3.0017198)), ((3.25387, 3.0017198), (2.7520366, 6.00349)), ((2.7520366, 6.00349), (4.751302, 6.0064002)), ((4.751302, 6.0064002), (4.4644632, 3.0033056)), ((4.4644632, 3.0033056), (5.0, 0.0)), ((6.4698018, 0.0), (4.4644632, 3.0033056))] - self.assertEqual(lns, test) - plot_lines(lns, color='C2') + def test_Polygon(self): + p0 = Point() + p1 = Point(1, 0, 0) + p2 = Point(1, 1, 1) + p3 = Point(0, 1, 1) + pg = Polygon(p0, p1, p2, p3) + self.assertEqual( + pg.points(), + [[0, 0, 0, 1], [1, 0 , 0, 1], [1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1]]) - def test_translate_xy(self): - """test translate_xy function with single values""" - x = 2 - y = 4 - xp, yp = translate_xy((0.5, 1), x, y) - xt = 2.5 - yt = 5 - self.assertEqual(xp, xt) - self.assertEqual(yp, yt) - - def test_translate_xy_list(self): - """test translate_xy function""" - x = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333, - 1.66666667, 2. , 2.33333333, 2.66666667, 3. ] - y = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03, - -1.84370370e-03, -2.08691495e-03, -2.11741838e-03, - -1.92529630e-03, -1.50063100e-03, -8.33504801e-04, - 8.60000000e-05] - xp, yp = translate_xy((1, 0.001), x, y) - xt = [1.0, - 1.3333333333333333, - 1.6666666666666665, - 2.0, - 2.333333333333333, - 2.666666666666667, - 3.0, - 3.333333333333333, - 3.6666666666666665, - 4.0] - yt = [0.0010629999999999999, - 0.00024117146776406044, - -0.00039770233196159102, - -0.0008437037037037035, - -0.0010869149519890263, - -0.0011174183813443071, - -0.00092529629629629624, - -0.00050063100137174286, - 0.0001664951989026062, - 0.0010859999999999999] - self.assertTrue(allclose(xp, xt)) - self.assertTrue(allclose(yp, yt)) - - def test_rotate_xy(self): - """test translate_xy function with single values""" - x = 2 - y = 4 - xp, yp = rotate_xy((0.5, 1), math.pi/2, x, y) - xt = -2.5 - yt = 2.5 - self.assertEqual(xp, xt) - self.assertEqual(yp, yt) - - def test_rotate_xy_list(self): - """test translate_xy function""" - x = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333, - 1.66666667, 2. , 2.33333333, 2.66666667, 3. ] - y = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03, - -1.84370370e-03, -2.08691495e-03, -2.11741838e-03, - -1.92529630e-03, -1.50063100e-03, -8.33504801e-04, - 8.60000000e-05] - xp, yp = rotate_xy((0, 0), math.pi/2, x, y) - xt = [-6.3e-05, - 0.00075882853223595997, - 0.0013977023319616318, - 0.0018437037037037647, - 0.0020869149519891078, - 0.002117418381344409, - 0.0019252962962964188, - 0.0015006310013718858, - 0.0008335048010975571, - -8.5999999999816312e-05] - yt = [3.8576374173141622e-21, - 0.33333333333333331, - 0.66666666666666663, - 1.0, - 1.3333333333333333, - 1.6666666666666667, - 2.0, - 2.333333333333333, - 2.6666666666666665, - 3.0] - self.assertTrue(allclose(xp, xt)) - self.assertTrue(allclose(yp, yt)) - - def test_interpolate_hermite(self): - """test translate_xy function""" - # u: - # - left side displacement to right - # - left side rotation counterclockwise - # - right side displacement to right - # - right side rotation counterclockwise - u = [ 0.012770, 0.000063, -0.002730, 0.012693, 0.000086, 0.003147] - x, y = interpolate_hermite(u[1], u[2], u[4], u[5], scale_x=3) - xt = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333, - 1.66666667, 2. , 2.33333333, 2.66666667, 3. ] - yt = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03, - -1.84370370e-03, -2.08691495e-03, -2.11741838e-03, - -1.92529630e-03, -1.50063100e-03, -8.33504801e-04, - 8.60000000e-05] - self.assertTrue(allclose(x, xt)) - self.assertTrue(allclose(y, yt)) - - def test_cubics_deformation_xz(self): - """test cubics function with (local) deformation""" - lns = cubics(self.global_points, deformation=self.u, rotation_plane='xz', factor=self.factor, inc=self.inc, index_offset=1) - for l, t in zip(lns, self.test_lns_l): - self.assertEqual(l[0], t[0]) # left point - self.assertEqual(l[1], t[1]) # right point - #self.assertEqual(l[2], t[2]) # deformation - self.assertTrue(allclose(l[2], t[2])) - plot_cubic_lines(lns, color='C3', samples=40) - - def test_cubics_deformation_xy(self): - """test cubics function with (local) deformation""" - lns = cubics(self.global_points, deformation=self.uN, rotation_plane='xy', factor=self.factor, inc=self.inc, index_offset=1) - for l, t in zip(lns, self.test_lns_l): - self.assertEqual(l[0], t[0]) # left point - self.assertEqual(l[1], t[1]) # right point - #self.assertEqual(l[2], t[2]) # deformation - self.assertTrue(allclose(l[2], t[2])) - plot_cubic_lines(lns, color='C3', samples=40) - - def test_cubics_global_deformation_xz(self): - """test cubics function with global_deformation""" - lns = cubics(self.global_points, global_deformation=fold_list(self.U, 3), rotation_plane='xz', factor=self.factor, inc=self.inc, index_offset=1) - for l, t in zip(lns, self.test_lns_g): - self.assertEqual(l[0], t[0]) # left point - self.assertEqual(l[1], t[1]) # right point - #self.assertEqual(l[2], t[2]) # deformation - self.assertTrue(allclose(l[2], t[2])) - plot_cubic_lines(lns, color='C4', samples=40) - - def test_cubics_global_deformation_xy(self): - """test cubics function with global_deformation""" - lns = cubics(self.global_points, global_deformation=fold_list(self.UN, 3), rotation_plane='xy', factor=self.factor, inc=self.inc, index_offset=1) - for l, t in zip(lns, self.test_lns_g): - self.assertEqual(l[0], t[0]) # left point - self.assertEqual(l[1], t[1]) # right point - #self.assertEqual(l[2], t[2]) # deformation - self.assertTrue(allclose(l[2], t[2])) - plot_cubic_lines(lns, color='C4', samples=40) + def test_Polygon_ch_cs(self): + # example object to rotate + p0 = Point() + p1 = Point(1, 0, 0) + p2 = Point(1, 1, 1) + p3 = Point(0, 1, 1) + theta = math.pi/2 + test = [[0.0, 0.0, 0.0, 1], [0, 0.0, -1.0, 1], [1.0, 1.0, -1, 1], + [1.0, 1.0, 0, 1], [0.0, 0.0, 0.0, 1]] + # using a coordinate system object + pg = Polygon(p0, p1, p2, p3) + cs = CS().rotate_y(theta) + pg.ch_cs(cs) + [self.assertAlmostEqual(i, j) for i, j in zip(pg.points(), test)] if __name__ == '__main__': - unittest.main() + unittest.main(verbosity=2) diff --git a/tests/test_geometry2d.py b/tests/test_geometry2d.py new file mode 100644 index 0000000..444c289 --- /dev/null +++ b/tests/test_geometry2d.py @@ -0,0 +1,259 @@ +"""Test of geometry2d module. + +:Date: 2019-08-20 + +.. module:: test_geometry2d + :platform: *nix, Windows + :synopsis: Test of geometry2d module. + +.. moduleauthor:: Daniel Weschke +""" +import unittest + +import os +import sys +import math +from numpy import allclose +sys.path.insert(0, os.path.abspath('../pylib')) +from data import fold_list +from geometry2d import translate_xy, rotate_xy, interpolate_hermite, lines, cubics +from geometry2d_plot import plot_lines, plot_cubic_lines + + +class TestGeometry2d(unittest.TestCase): + global_points = [(0, 0), + (0, 3), + (3, 3), + (3, 0), + (3, 6), + (5, 6), + (5, 3), + (5, 0), + (7, 0)] + inc = [[1, 2], + [2, 3], + [4, 3], + [3, 5], + [5, 6], + [6, 7], + [7, 8], + [9, 7]] + + # global deformation, horizontal right, vertical down, rotation + U = [ + 0.00000, 0.00000, -5.02012, + 12.77012, 0.06333, -2.72988, + 12.69350, 0.08599, 3.14685, + 0.00000, 0.00000, -7.92017, + -12.39817, 0.17450, 4.14446, + -12.43490, 0.32001, -3.10697, + -26.77684, 0.16528, 2.98214, + 0.00000, 0.00000, 0.00000, + -26.50991, 0.00000, -1.36053, + ] + U = [Ui/1000 for Ui in U] + + # global deformation, only horizontal right and vertical down + U2 = [ui for i, ui in enumerate(U) if i%3 != 2] + + # global deformation, horizontal right, vertical up, rotation + UN = [Ui if i%3 != 1 else -Ui for i, Ui in enumerate(U)] + + # local deformation, horizontal right, vertical down, rotation + u = [ + [ 0.000000, 0.000000, -0.005020, -0.000063, 0.012770, -0.002730], + [ 0.012770, 0.000063, -0.002730, 0.012693, 0.000086, 0.003147], + [ 0.000000, 0.000000, -0.007920, -0.000086, 0.012693, 0.003147], + [-0.000086, 0.012693, 0.003147, -0.000175, -0.012398, 0.004144], + [-0.012398, 0.000175, 0.004144, -0.012435, 0.000320, -0.003107], + [ 0.000320, 0.012435, -0.003107, 0.000165, 0.026777, 0.002982], + [ 0.000165, 0.026777, 0.002982, 0.000000, 0.000000, 0.000000], + [ 0.014705, -0.022058, -0.001361, 0.014716, -0.022371, 0.002982], + ] + + # local deformation, horizontal right, vertical up, rotation + uN = [[uii if i%3 != 1 else -uii for i, uii in enumerate(ui)] for ui in u] + + # exaggeration factor for the deformation + factor = 20 + + # test of cubic lines + test_lns_l = [((0, 0), (0, 3), [0.0, -0.0, -0.1004, -0.00126, -0.2554, -0.0546]), + ((0, 3), (3, 3), [0.2554, -0.00126, -0.0546, 0.25386, -0.00172, 0.06294]), + ((3, 0), (3, 3), [0.0, -0.0, -0.1584, -0.00172, -0.25386, 0.06294]), + ((3, 3), (3, 6), [-0.00172, -0.25386, 0.06294, -0.0035, 0.24796, 0.08288]), + ((3, 6), (5, 6), [-0.24796, -0.0035, 0.08288, -0.2487, -0.0064, -0.06214]), + ((5, 6), (5, 3), [0.0064, -0.2487, -0.06214, 0.0033, -0.53554, 0.05964]), + ((5, 3), (5, 0), [0.0033, -0.53554, 0.05964, 0.0, -0.0, 0.0]), + ((7, 0), (5, 3), [0.2941, 0.44116, -0.02722, 0.29432, 0.44742, 0.05964])] + test_lns_g = [((0, 0), (0, 3), [0.0, -0.0, -0.1004024, -0.0012666, -0.2554024, -0.0545976]), + ((0, 3), (3, 3), [0.2554024, -0.0012666, -0.0545976, 0.25387, -0.0017198, 0.062937]), + ((3, 0), (3, 3), [0.0, -0.0, -0.1584034, -0.0017198, -0.25387, 0.062937]), + ((3, 3), (3, 6), [-0.0017198, -0.25387, 0.062937, -0.00349, 0.2479634, 0.0828892]), + ((3, 6), (5, 6), [-0.2479634, -0.00349, 0.0828892, -0.248698, -0.0064002, -0.0621394]), + ((5, 6), (5, 3), [0.0064002, -0.248698, -0.0621394, 0.0033056, -0.5355368, 0.0596428]), + ((5, 3), (5, 0), [0.0033056, -0.5355368, 0.0596428, 0.0, 0.0, 0.0]), + ((7, 0), (5, 3), [0.2941010455782632, 0.441151568367395, -0.0272106, 0.29431194259286797, 0.4474271690373891, 0.0596428])] + + def test_lines(self): + """test lines function (undeformed structure)""" + lns = lines(self.global_points, inc=self.inc, index_offset=1) + test = [((0, 0), (0, 3)), ((0, 3), (3, 3)), ((3, 0), (3, 3)), + ((3, 3), (3, 6)), ((3, 6), (5, 6)), ((5, 6), (5, 3)), + ((5, 3), (5, 0)), ((7, 0), (5, 3))] + + self.assertEqual(lns, test) + plot_lines(lns, linestyle=':') + + def test_lines_deformation(self): + """test lines function with deformation (deformed structure)""" + lns = lines(self.global_points, deformation=fold_list(self.U2, 2), factor=self.factor, inc=self.inc, index_offset=1) + test = [((0.0, 0.0), (0.25540240000000003, 3.0012666)), ((0.25540240000000003, 3.0012666), (3.25387, 3.0017198)), ((3.0, 0.0), (3.25387, 3.0017198)), ((3.25387, 3.0017198), (2.7520366, 6.00349)), ((2.7520366, 6.00349), (4.751302, 6.0064002)), ((4.751302, 6.0064002), (4.4644632, 3.0033056)), ((4.4644632, 3.0033056), (5.0, 0.0)), ((6.4698018, 0.0), (4.4644632, 3.0033056))] + self.assertEqual(lns, test) + plot_lines(lns, color='C2') + + def test_translate_xy(self): + """test translate_xy function with single values""" + x = 2 + y = 4 + xp, yp = translate_xy((0.5, 1), x, y) + xt = 2.5 + yt = 5 + self.assertEqual(xp, xt) + self.assertEqual(yp, yt) + + def test_translate_xy_list(self): + """test translate_xy function""" + x = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333, + 1.66666667, 2. , 2.33333333, 2.66666667, 3. ] + y = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03, + -1.84370370e-03, -2.08691495e-03, -2.11741838e-03, + -1.92529630e-03, -1.50063100e-03, -8.33504801e-04, + 8.60000000e-05] + xp, yp = translate_xy((1, 0.001), x, y) + xt = [1.0, + 1.3333333333333333, + 1.6666666666666665, + 2.0, + 2.333333333333333, + 2.666666666666667, + 3.0, + 3.333333333333333, + 3.6666666666666665, + 4.0] + yt = [0.0010629999999999999, + 0.00024117146776406044, + -0.00039770233196159102, + -0.0008437037037037035, + -0.0010869149519890263, + -0.0011174183813443071, + -0.00092529629629629624, + -0.00050063100137174286, + 0.0001664951989026062, + 0.0010859999999999999] + self.assertTrue(allclose(xp, xt)) + self.assertTrue(allclose(yp, yt)) + + def test_rotate_xy(self): + """test translate_xy function with single values""" + x = 2 + y = 4 + xp, yp = rotate_xy((0.5, 1), math.pi/2, x, y) + xt = -2.5 + yt = 2.5 + self.assertEqual(xp, xt) + self.assertEqual(yp, yt) + + def test_rotate_xy_list(self): + """test translate_xy function""" + x = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333, + 1.66666667, 2. , 2.33333333, 2.66666667, 3. ] + y = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03, + -1.84370370e-03, -2.08691495e-03, -2.11741838e-03, + -1.92529630e-03, -1.50063100e-03, -8.33504801e-04, + 8.60000000e-05] + xp, yp = rotate_xy((0, 0), math.pi/2, x, y) + xt = [-6.3e-05, + 0.00075882853223595997, + 0.0013977023319616318, + 0.0018437037037037647, + 0.0020869149519891078, + 0.002117418381344409, + 0.0019252962962964188, + 0.0015006310013718858, + 0.0008335048010975571, + -8.5999999999816312e-05] + yt = [3.8576374173141622e-21, + 0.33333333333333331, + 0.66666666666666663, + 1.0, + 1.3333333333333333, + 1.6666666666666667, + 2.0, + 2.333333333333333, + 2.6666666666666665, + 3.0] + self.assertTrue(allclose(xp, xt)) + self.assertTrue(allclose(yp, yt)) + + def test_interpolate_hermite(self): + """test translate_xy function""" + # u: + # - left side displacement to right + # - left side rotation counterclockwise + # - right side displacement to right + # - right side rotation counterclockwise + u = [ 0.012770, 0.000063, -0.002730, 0.012693, 0.000086, 0.003147] + x, y = interpolate_hermite(u[1], u[2], u[4], u[5], scale_x=3) + xt = [ 0. , 0.33333333, 0.66666667, 1. , 1.33333333, + 1.66666667, 2. , 2.33333333, 2.66666667, 3. ] + yt = [ 6.30000000e-05, -7.58828532e-04, -1.39770233e-03, + -1.84370370e-03, -2.08691495e-03, -2.11741838e-03, + -1.92529630e-03, -1.50063100e-03, -8.33504801e-04, + 8.60000000e-05] + self.assertTrue(allclose(x, xt)) + self.assertTrue(allclose(y, yt)) + + def test_cubics_deformation_xz(self): + """test cubics function with (local) deformation""" + lns = cubics(self.global_points, deformation=self.u, rotation_plane='xz', factor=self.factor, inc=self.inc, index_offset=1) + for l, t in zip(lns, self.test_lns_l): + self.assertEqual(l[0], t[0]) # left point + self.assertEqual(l[1], t[1]) # right point + #self.assertEqual(l[2], t[2]) # deformation + self.assertTrue(allclose(l[2], t[2])) + plot_cubic_lines(lns, color='C3', samples=40) + + def test_cubics_deformation_xy(self): + """test cubics function with (local) deformation""" + lns = cubics(self.global_points, deformation=self.uN, rotation_plane='xy', factor=self.factor, inc=self.inc, index_offset=1) + for l, t in zip(lns, self.test_lns_l): + self.assertEqual(l[0], t[0]) # left point + self.assertEqual(l[1], t[1]) # right point + #self.assertEqual(l[2], t[2]) # deformation + self.assertTrue(allclose(l[2], t[2])) + plot_cubic_lines(lns, color='C3', samples=40) + + def test_cubics_global_deformation_xz(self): + """test cubics function with global_deformation""" + lns = cubics(self.global_points, global_deformation=fold_list(self.U, 3), rotation_plane='xz', factor=self.factor, inc=self.inc, index_offset=1) + for l, t in zip(lns, self.test_lns_g): + self.assertEqual(l[0], t[0]) # left point + self.assertEqual(l[1], t[1]) # right point + #self.assertEqual(l[2], t[2]) # deformation + self.assertTrue(allclose(l[2], t[2])) + plot_cubic_lines(lns, color='C4', samples=40) + + def test_cubics_global_deformation_xy(self): + """test cubics function with global_deformation""" + lns = cubics(self.global_points, global_deformation=fold_list(self.UN, 3), rotation_plane='xy', factor=self.factor, inc=self.inc, index_offset=1) + for l, t in zip(lns, self.test_lns_g): + self.assertEqual(l[0], t[0]) # left point + self.assertEqual(l[1], t[1]) # right point + #self.assertEqual(l[2], t[2]) # deformation + self.assertTrue(allclose(l[2], t[2])) + plot_cubic_lines(lns, color='C4', samples=40) + + +if __name__ == '__main__': + unittest.main()