diff --git a/docs/build/html/.buildinfo b/docs/build/html/.buildinfo index 85ac018..591ca50 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: 2cbc17343901b023dfef01a2244f3120 +config: caf5792fd17da2c604992977d35f1f60 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/build/html/_modules/index.html b/docs/build/html/_modules/index.html index 34e9952..bca247e 100644 --- a/docs/build/html/_modules/index.html +++ b/docs/build/html/_modules/index.html @@ -40,6 +40,7 @@
  • pylib.geometry
  • pylib.geometry2d
  • pylib.geometry2d_plot
  • +
  • pylib.geometry_plot_pylab
  • pylib.mathematics
  • pylib.numerical.fit
  • pylib.numerical.integration
  • diff --git a/docs/build/html/_modules/pylib/data.html b/docs/build/html/_modules/pylib/data.html index 4c0b454..03efec6 100644 --- a/docs/build/html/_modules/pylib/data.html +++ b/docs/build/html/_modules/pylib/data.html @@ -47,6 +47,36 @@ """ import math import pickle +import collections + +
    [docs]def issequence(obj): + """ + True for tuple, list, str + False for int, dict, set + + :Example: + + >>> issequence(()) + True + >>> issequence((3, )) + True + >>> issequence([]) + True + >>> issequence([1]) + True + >>> issequence([1, 2]) + True + >>> issequence('') + True + + >>> issequence((3)) + False + >>> issequence({}) + False + >>> issequence(set()) + False + """ + return isinstance(obj, collections.abc.Sequence)
    [docs]def read(file_name, x_column, y_column, default=None, verbose=False): """Read ascii data file. diff --git a/docs/build/html/_modules/pylib/function.html b/docs/build/html/_modules/pylib/function.html index 028da16..df3b3a9 100644 --- a/docs/build/html/_modules/pylib/function.html +++ b/docs/build/html/_modules/pylib/function.html @@ -235,7 +235,7 @@ >>> x, y, theta_end = hyotrochoid(20, 6, 6) .. seealso:: - :meth:`mathematics.lcm` + :meth:`pylib.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) @@ -412,7 +412,7 @@ .. seealso:: - :meth:`pylib.function.transformation` + :meth:`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] @@ -437,7 +437,7 @@ #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 + from .drawblock import histogram pixels_horizontal = 1 pixels_vertical = 8 @@ -447,7 +447,7 @@ 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) + frame = histogram(f, x) return frame
    diff --git a/docs/build/html/_modules/pylib/geometry.html b/docs/build/html/_modules/pylib/geometry.html index c32d4c7..e4a975f 100644 --- a/docs/build/html/_modules/pylib/geometry.html +++ b/docs/build/html/_modules/pylib/geometry.html @@ -35,7 +35,7 @@

    Source code for pylib.geometry

     #!/usr/bin/env python
     # -*- coding: utf-8 -*-
    -"""2D geometry objects.
    +"""Geometry objects.
     
     :Date: 2019-12-21
     
    @@ -44,26 +44,37 @@
       :synopsis: Geometry objects.
     
     .. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
    +
    +Affine transforms
    +-----------------
    +
    +Functions in augmented space, in homogenous coordinates.
    +Points are augment to 4 dimensions, by adding a dummy coordinate.
    +For points the dummy coordinate is always normalized to 1.
    +With homogenous coordinates translation of points is repesentable
    +as a linear transformation.
     """
     import math
     import copy
    -from mathematics import vector, matrix
    +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]) - - def __str__(self): - return str(self.xyz())
    + super().__init__([x, y, z, 0])
    [docs]class Point(vector): """Point in local coordinate system""" def __init__(self, x=0, y=0, z=0): super().__init__([x, y, z, 1]) - def __str__(self): - return str(self.xyz())
    + # TODO +
    [docs] def projection(self): + """Orthographic projection to the xy-plane + """ + # P = matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) + #return (P*self)[:2] + return self[:2]
    [docs]class CS(matrix): """Coordinate system @@ -71,9 +82,6 @@ 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] @staticmethod def x90(): return CS((1, 0, 0), (0, 0, -1), (0, 1, 0))
    @@ -94,7 +102,133 @@ """Get coordinates in 3d space""" return self[:3,:3]
    -
    [docs]class World(): +# 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). + """ + def __init__(self, *points, closed=False): + self._points = [copy.copy(i) for i in points] + self.closed = closed + +
    [docs] def __str__(self): + return '[' + ', '.join([str(point) for point in self._points]) + ']'
    + +
    [docs] 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 xy(self): + """Get coordinates in 3d space""" + return list(zip(*[i[:2] for i in self.points()]))
    + +
    [docs] def xyz(self): + """Get coordinates in 3d space""" + return list(zip(*[i[:3] 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 is not suitable because 0 is also false + if sy is None: + 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.cos(i*2*math.pi/n) + y = radius * math.sin(i*2*math.pi/n) + points.append(Point(x, y, 0)) + super().__init__(*points)
    + +
    [docs]class Solid: + """Solid object in local coordinate system + + This class lists Wireframe objects. + The Wireframe class create its own points (copy). + """ + def __init__(self, *wireframes): + self._wireframes = wireframes + +
    [docs] def wireframes(self): + return self._wireframes
    + +
    [docs] def translate(self, tx, ty, tz): + self._wireframes = [wireframe.translate(tx, ty, tz) for + wireframe in self._wireframes] + return self
    + +
    [docs] def scale(self, sx, sy=None, sz=None): + # if not sy is not suitable because 0 is also false + if sy is None: + sy = sx + sz = sx + self._wireframes = [wireframe.scale(sx, sy, sz) for + wireframe in self._wireframes] + return self
    + +
    [docs] def ch_cs(self, cs): + self._wireframes = [wireframe.ch_cs(cs) for + wireframe in self._wireframes] + return self
    + +
    [docs]class Hexahedron(Solid): + """Line a open wireframe object in local coordinate system""" + def __init__(self, + point1=Point(-1, -1, -1), point2=Point(1, -1, -1), + point3=Point(1, 1, -1), point4=Point(-1, 1, -1), + point5=Point(-1, -1, 1), point6=Point(1, -1, 1), + point7=Point(1, 1, 1), point8=Point(-1, 1, 1)): + super().__init__( + Polygon(point1, point2, point3, point4), + Polygon(point5, point6, point7, point8), + Polygon(point1, point2, point6, point5), + Polygon(point3, point4, point8, point7) + )
    + +
    [docs]class World: """World-space with world-space coordinates """ def __init__(self): @@ -102,12 +236,13 @@ self._objects = [] self._store_init() - def __iter__(self): +
    [docs] def __iter__(self): """Returns the Iterator object""" - return iter(self.objects()) + return iter(self.objects())
    def _store_init(self): - """Initialize or reset calculated values, because a new object was added. + """Initialize or reset calculated values, because a new object + was added. """ self._bb = None self._sd = None @@ -141,6 +276,33 @@ self._cs.scale(sx, sy, sz) return self
    +
    [docs] def wireframes(self): + result = [] + for i in self.objects(): + if isinstance(i, Wireframe): + result.append(i.points()) + elif isinstance(i, Solid): + [result.append(j.points()) for j in i.wireframes()] + return result
    + +
    [docs] def wireframes_xy(self): + result = [] + for i in self.objects(): + if isinstance(i, Wireframe): + result.append(i.xy()) + elif isinstance(i, Solid): + [result.append(j.xy()) for j in i.wireframes()] + return result
    + +
    [docs] def wireframes_xyz(self): + result = [] + for i in self.objects(): + if isinstance(i, Wireframe): + result.append(i.xyz()) + elif isinstance(i, Solid): + [result.append(j.xyz()) for j in i.wireframes()] + return result
    +
    [docs] def objects(self): return [copy.deepcopy(i).ch_cs(self._cs) for i in self._objects]
    @@ -159,10 +321,9 @@ 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 + for i in self.wireframes_xyz(): + xi, yi, zi = map(min, i) + xs, ys, zs = map(max, i) xmin = xi if xi < xmin else xmin ymin = yi if yi < ymin else ymin zmin = zi if zi < zmin else zmin @@ -183,81 +344,11 @@
    [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]]) + self.ch_cs([[1, 0, 0, -(bb[0]+bb[1])/2], + [0, 1, 0, -(bb[2]+bb[3])/2], + [0, 0, 1, -(bb[4]+bb[5])/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). - """ - 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)
    diff --git a/docs/build/html/_modules/pylib/geometry2d_plot.html b/docs/build/html/_modules/pylib/geometry2d_plot.html index d184dc8..3a99df1 100644 --- a/docs/build/html/_modules/pylib/geometry2d_plot.html +++ b/docs/build/html/_modules/pylib/geometry2d_plot.html @@ -46,7 +46,7 @@ .. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de> """ import pylab -from geometry2d import ( +from .geometry2d import ( distance, angle, line, interpolate_hermite, rotate_xy, translate_xy ) diff --git a/docs/build/html/_modules/pylib/geometry_plot_pylab.html b/docs/build/html/_modules/pylib/geometry_plot_pylab.html new file mode 100644 index 0000000..c02e772 --- /dev/null +++ b/docs/build/html/_modules/pylib/geometry_plot_pylab.html @@ -0,0 +1,346 @@ + + + + + + + pylib.geometry_plot_pylab — pylib 2019.12.21 documentation + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + + +
    + +

    Source code for pylib.geometry_plot_pylab

    +#!/usr/bin/env python
    +# -*- coding: utf-8 -*-
    +"""Geometry plotter using pylab (matplotlib).
    +
    +:Date: 2019-12-23
    +
    +.. module:: geometry_plot_pylab
    +  :platform: *nix, Windows
    +  :synopsis: Geometry plotting (pylab).
    +
    +.. moduleauthor:: Daniel Weschke <daniel.weschke@directbox.de>
    +"""
    +import math
    +# This import registers the 3D projection, but is otherwise unused.
    +from mpl_toolkits.mplot3d import Axes3D
    +assert Axes3D  # silence pyflakes
    +import pylab
    +pylab.style.use('dark_background')
    +pylab.rcParams['text.color'] = 'grey'      # lightgrey
    +pylab.rcParams['axes.edgecolor'] = 'grey'  # lightgrey
    +pylab.rcParams['grid.color'] = 'grey'      # lightgrey
    +pylab.rcParams['xtick.color'] = 'grey'     # lightgrey
    +pylab.rcParams['ytick.color'] = 'grey'     # lightgrey
    +pylab.rcParams['axes3d.grid'] = False
    +# default for dark_background cycler(
    +# 'color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd',
    +#           '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'])
    +pylab.rcParams['axes.prop_cycle'] = pylab.cycler(
    +  "color", ['#3498DB', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd',
    +            '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'])
    +
    +# remove f for fullscreen toggle, default ['f', 'ctrl+f']
    +pylab.rcParams['keymap.fullscreen'] = ['ctrl+f']
    +# remove L for log/lin toggle, default ['k', 'L']
    +pylab.rcParams['keymap.xscale'] = ['k']
    +# remove l for log/lin toggle, default ['l']
    +pylab.rcParams['keymap.yscale'] = []
    +
    +from pylab import mean
    +from .geometry import CS
    +
    +# type of ax
    +# - matplotlib.axes._subplots.Axes3DSubplot)
    +# - matplotlib.axes.Axes
    +# - pylab.Axes
    +
    +
    [docs]def set_aspect_equal(ax): + '''Make axes of 3D plot have equal scale so that spheres appear as + spheres, cubes as cubes, etc.. This is one possible solution to + Matplotlib's ax.set_aspect('equal') and ax.axis('equal') not + working for 3D. + + :param ax: a pylab axis + :type ax: pylab.Axes + + Source: https://stackoverflow.com/a/35126679 + ''' + if ax.name == '3d': + + xlim = ax.get_xlim3d() + ylim = ax.get_ylim3d() + zlim = ax.get_zlim3d() + + xmean = mean(xlim) + ymean = mean(ylim) + zmean = mean(zlim) + + plot_radius = max([abs(lim - mean_) + for lims, mean_ in ((xlim, xmean), + (ylim, ymean), + (zlim, zmean)) + for lim in lims]) + + ax.set_xlim3d([xmean - plot_radius, xmean + plot_radius]) + ax.set_ylim3d([ymean - plot_radius, ymean + plot_radius]) + ax.set_zlim3d([zmean - plot_radius, zmean + plot_radius]) + else: + ax.axis('equal')
    + +
    [docs]def plot_post(ax): + if isinstance(ax, pylab.Axes): + ax = [ax] + for axi in ax: + if axi.name == '3d': + #axi.w_xaxis.set_pane_color((0, 0, 0, 0)) + #axi.w_yaxis.set_pane_color((0, 0, 0, 0)) + #axi.w_zaxis.set_pane_color((0, 0, 0, 0)) + axi.w_xaxis.pane.fill = False + axi.w_yaxis.pane.fill = False + axi.w_zaxis.pane.fill = False + set_aspect_equal(axi)
    + +
    [docs]def wireframe3d(world): + fig = pylab.figure() + ax = fig.add_subplot(111, projection='3d') + [ax.plot(*i, 'C0') for i in world.wireframes_xyz()] + plot_post(ax)
    + +
    [docs]def cad_wireframe(world, centering=True): + """ + Graphical projections + + * Parallel projections + + * Orthographic + + * Multiview + + * \* First-angle + * Third-angle + * Plan Elevation + + * Axonometric + + * \* Isometric + * Dimetric + * Trimetri + + * Oblique + + * Carbinet + * Cavalier + * Military + * Top-down + + * Perspective projections + + * 1-point + * 2-point + * 3-point + * Curvilinear + + """ + if centering: + world.center() + + fig = pylab.figure('geometry-cad') + fig.clf() + ax = fig.add_subplot(111) + + pylab.axis('off') + pylab.subplots_adjust(left=0, right=1, top=1, bottom=0) + + lps = [ax.plot(*i, 'C0')[0] for i in world.wireframes_xy()] + + plot_post(ax) + + def press(event, world, lps): + #print('key pressed:', event.key) + #sys.stdout.flush() + if event.key in [ + 'left', 'right', 'up', 'down', + 'f', 't', 'b', 'l', 'r', 'i', 'd', + 'shift+left', 'shift+right', 'shift+up', 'shift+down', + 'ctrl+up', 'ctrl+down', 'ctrl+left', 'ctrl+right']: + d = world.space_diagonal() + if event.key == 'left': + world.rotate_y(-math.pi/180*10) + elif event.key == 'right': + world.rotate_y(+math.pi/180*10) + elif event.key == 'up': + world.rotate_x(-math.pi/180*10) + elif event.key == 'down': + world.rotate_x(+math.pi/180*10) + elif event.key == 'f': + world.cs(CS()) + if centering: + world.center() + elif event.key == 't': + world.cs(CS.x90()) + if centering: + world.center() + elif event.key == 'b': + world.cs(CS.xm90()) + if centering: + world.center() + elif event.key == 'l': + world.cs(CS.y90()) + if centering: + world.center() + elif event.key == 'r': + world.cs(CS.ym90()) + if centering: + world.center() + elif event.key == 'i': + #theta_y = -math.pi/2/3 + #theta_x = math.pi/2/3 + theta_y = -math.pi/2/2 + theta_x = math.asin(math.tan(math.pi/2/3)) + world.cs(CS().rotate_y(theta_y).rotate_x(theta_x)) + if centering: + world.center() + elif event.key == 'd': + #theta_x = math.asin(math.tan(math.pi/2/3/2)) + theta_y = -math.pi/2/2 + theta_x = math.atan(1/2) + world.cs(CS().rotate_y(theta_y).rotate_x(theta_x)) + if centering: + world.center() + elif event.key == 'shift+left': + world.translate(-0.1*d, 0, 0) + elif event.key == 'shift+right': + world.translate(0.1*d, 0, 0) + elif event.key == 'shift+up': + world.translate(0, 0.1*d, 0) + elif event.key == 'shift+down': + world.translate(0, -0.1*d, 0) + elif event.key == 'ctrl+left': + world.rotate_z(+math.pi/180*10) + elif event.key == 'ctrl+right': + world.rotate_z(-math.pi/180*10) + elif event.key == 'ctrl+up': + world.scale(1.1) + elif event.key == 'ctrl+down': + world.scale(0.9) + for i, j in zip(lps, world.wireframes_xy()): + i.set_data(j) + fig.canvas.draw() + + def onresize(event, w): + r = 2 * w.space_diagonal()/2 + pylab.xlim((-r, r)) + pylab.ylim((-r, r)) + + fig.canvas.mpl_connect('key_press_event', + lambda event: press(event, world, lps)) + fig.canvas.mpl_connect('resize_event', + lambda event: onresize(event, world)) + + pylab.text( + 0+.01, 1-.015, + 'rotate: left, right, up, down, ctrl+left, ctrl+right\n' + + 'pan: shift+left, shift+right, shift+up, shift+down\n' + + 'zoom: ctrl+up, ctrl+down\n' + + 'view: f (front), l (left), r (right), t (top), b (bottom)\n' + + ' i (isometric), d (dimetric)', + horizontalalignment='left', + verticalalignment='top', + transform=fig.transFigure, + bbox=dict(facecolor='black', alpha=0.5), + family='monospace' + ) + pylab.show()
    +
    + +
    + +
    +
    + +
    +
    + + + + + + + \ No newline at end of file diff --git a/docs/build/html/_modules/pylib/mathematics.html b/docs/build/html/_modules/pylib/mathematics.html index 5295b0e..c8f333e 100644 --- a/docs/build/html/_modules/pylib/mathematics.html +++ b/docs/build/html/_modules/pylib/mathematics.html @@ -56,69 +56,68 @@
    [docs]class vector(list): """Use/create vector like lists - * size -> len(a) - * abs -> abs(a) - * dot -> a * b - * outer -> a @ b + * size, length of a vector use len(a) + * absolute, magntude, norm of a vector use abs(a), see + :meth:`__abs__` + * dot product use a * b, see :meth:`__mul__` and :meth:`__rmul__` + * outer product use a @ b, see :meth:`__matmul__` - use super constructor + :__iter__: - use super __iter__ + >>> [i*2 for i in vector([1, 2, 3])] + [2, 4, 6] - use super __setitem__ + :__setitem__: - >>> v = vector([1,2,3,4,5]) - >>> v[3:5] = [1,2] + >>> 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) + :__eq__(a, b): - use super __le__(a, b) + >>> vector([1, 2, 3, 1, 2]) == vector([1, 2, 3, 1, 2]) + True + >>> vector([1, 2, 3, 1, 2]) == vector([1, 2, 3, 2, 1]) + False - use super __eq__(a, b) + :__ne__(a, b): - >>> v = vector([1,2,3,1,2]) - >>> v2 = vector([1,2,3,1,2]) - >>> v == v2 + >>> vector([1, 2, 3, 1, 2]) != vector([1, 2, 3, 1, 2]) + False + >>> vector([1, 2, 3, 1, 2]) != vector([1, 2, 3, 2, 1]) True - use super __ne__(a, b) + :__contains__: - use super __ge__(a, b) - - use super __gt__(a, b) - - use super __contains__ - - >>> 2 in vector([1,2,3]) + >>> 2 in vector([1, 2, 3]) True - __isub__ + :__isub__: - >>> v = vector([1,2,3]) - >>> v -= vector([3,3,3]) + >>> v = vector([1, 2, 3]) + >>> v -= vector([3, 3, 3]) >>> print(v) [-2, -1, 0] - __imul__ + :__imul__: - >>> v = vector([1,2,3]) - >>> v *= vector([3,3,3]) + >>> v = vector([1, 2, 3]) + >>> v *= vector([3, 3, 3]) >>> print(v) 18 - __imatmul__ + :__imatmul__: - >>> m = vector([1,2,3]) - >>> m *= vector([3,3,3]) + >>> 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): +
    [docs] def __getitem__(self, index): """ For index return value, for range return new vector object. @@ -133,57 +132,68 @@ """ # use the list.__getslice__ method and convert result to vector item = super().__getitem__(index) - return vector(item) if isinstance(item, list) else item + return vector(item) if isinstance(item, list) else item
    - def __pos__(self): - """+ a (new object) +
    [docs] def __pos__(self): + """\+ a (new object) + + .. math:: + \mathbf{b} = +\mathbf{a} """ - return vector([*self]) + return vector([*self])
    - def __neg__(self): - """- a (new object) +
    [docs] def __neg__(self): + """\- a (new object) + + .. math:: + \mathbf{b} = -\mathbf{a} """ - return vector([-i for i in self]) + return vector([-i for i in self])
    - def __add__(self, other): +
    [docs] def __add__(self, other): """a + b (new object) + .. math:: + \mathbf{c} = \mathbf{a} + \mathbf{b} + :Example: - >>> v = vector([1,2,3]) + vector([1,2,3]) + >>> 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)]) + return vector([i+j for i, j in zip(self, other)])
    - def __iadd__(self, other): + # overwrite because [1, 2] + [5, 8] = [1, 2, 5, 8] +
    [docs] def __iadd__(self, other): """a += b (new object) :Example: - >>> v = vector([1,2,3]) - >>> v += vector([3,3,3]) + >>> 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)]) + return vector([i+j for i, j in zip(self, other)])
    - def __sub__(self, other): +
    [docs] def __sub__(self, other): """a - b (new object) + .. math:: + \mathbf{c} = \mathbf{a} - \mathbf{b} + :Example: - >>> v = vector([1,2,3]) - vector([1,2,3]) + >>> 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)]) + return vector([i-j for i, j in zip(self, other)])
    - def __mul__(self, other): +
    [docs] def __mul__(self, other): r"""Scalar multiplication, dot product (inner product) or - vector-matrix multiplication. - - a * b (new object) + vector-matrix multiplication. (new object) :type other: scalar, vector (or 1d list), matrix (or 2d list) @@ -193,18 +203,18 @@ \mathbf{c} &= \mathbf{a} \cdot \mathbf{B} .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). + 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 + >>> v = vector([1, 2, 3, 4, 5]) * 3 >>> print(v) [3, 6, 9, 12, 15] - >>> v = vector([1,2,3,4,5])*3. + >>> 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]) + >>> s = vector([1, 2, 3]) * vector([1, 2, 3]) >>> print(s) 14 @@ -215,15 +225,14 @@ 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)]) + 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]) + return vector([i*other for i in self])
    - def __rmul__(self, other): +
    [docs] def __rmul__(self, other): r"""Scalar multiplication, dot product (inner product) or - matrix-vector multiplication. - - a * b (new object) + matrix-vector multiplication. (new object) :type other: scalar (or 1d list and 2d list) @@ -233,32 +242,32 @@ \mathbf{c} &= \mathbf{A} \cdot \mathbf{b} .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). + 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]) + >>> v = 3 * vector([1, 2, 3, 4, 5]) >>> print(v) [3, 6, 9, 12, 15] - >>> v = 3.*vector([1,2,3,4,5]) + >>> 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 + :meth:`__mul__` and :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]) + return vector([sum(c*d for c, d in zip(a_row, self)) for + a_row in other]) except: # scalar * vector - return self*other + return self*other
    - def __matmul__(self, other): +
    [docs] def __matmul__(self, other): r"""Outer product a @ b (new object) .. math:: - \vec{a} \otimes \vec{b} + \mathbf{c} = \mathbf{a} \otimes \mathbf{b} = \begin{pmatrix} a_{1}\\ @@ -281,35 +290,98 @@ :Example: - >>> m = vector([1,2,3]) @ vector([1,2,4]) + >>> 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 + return self*other
    - def __abs__(self): +
    [docs] def __abs__(self): r"""Magnitude / norm of a vector .. math:: - b = \sqrt{\sum a_i^2} + b = |\mathbf{a}| = \sqrt{\sum a_i^2} = + \sqrt{\mathbf{a} \cdot \mathbf{a}} :Example: - >>> norm([3, 4]) - 5 - >>> norm(vector([3, 4])) - 5 + >>> v = vector([3, 4]) + >>> abs(v) + 5.0 """ - return math.sqrt(self * self) + return math.sqrt(self * self)
    - def __str__(self): - return str([*self]) +
    [docs] def __lt__(self, other): + """Test if this object is lower (smaller) than the other object. - def __repr__(self): - return "vector(" + str(self) + ")" + .. math:: + |\mathbf{a}| \lt |\mathbf{b}| + + :Example: + + >>> vector([3, 2, 1]) < vector([1, 2, 3]) + False + >>> vector([3, 2, 1]) < vector([1, 2, 4]) + True + """ + return abs(self) < abs(other)
    + +
    [docs] def __le__(self, other): + """Test if this object is lower (smaller) than or equal the + other object. + + .. math:: + |\mathbf{a}| \le |\mathbf{b}| + + :Example: + + >>> vector([3, 2, 1]) <= vector([1, 2, 3]) + True + >>> vector([3, 2, 1]) <= vector([1, 2, 2]) + False + """ + return abs(self) <= abs(other)
    + +
    [docs] def __gt__(self, other): + """Test if this object is greater (larger) than the other + object. + + .. math:: + |\mathbf{a}| \gt |\mathbf{b}| + + :Example: + + >>> vector([1, 2, 3]) > vector([3, 2, 1]) + False + >>> vector([1, 2, 3]) > vector([2, 2, 1]) + True + """ + return abs(self) > abs(other)
    + +
    [docs] def __ge__(self, other): + """Test if this object is greater (larger) than or equal the + other object. + + .. math:: + |\mathbf{a}| \ge |\mathbf{b}| + + :Example: + + >>> vector([1, 2, 3]) >= vector([3, 2, 1]) + True + >>> vector([1, 2, 3]) >= vector([4, 2, 1]) + False + """ + return abs(self) >= abs(other)
    + +
    [docs] def __str__(self): + return str([*self])
    + +
    [docs] def __repr__(self): + return "vector(" + str(self) + ")"
    [docs] @staticmethod def full(length, fill_value): @@ -363,8 +435,8 @@
    [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. + """Returns a random vector of length n or matrix of size m rows, + n columns filled with random numbers. :Example: @@ -386,10 +458,10 @@ :type a: vector .. math:: - \vec{e}_a = \frac{\vec{a}}{|\vec{a}|} + \mathbf{\hat{a}} = \frac{\mathbf{a}}{|\mathbf{a}|} .. seealso:: - :meth:`norm` for a norm (magnitude) of a vector + :meth:`__abs__` for a norm (magnitude) of a vector """ a_mag = abs(a) return vector([i/a_mag for i in a])
    @@ -450,15 +522,12 @@ The direction of c can be found with the right-hand rule. .. math:: - \vec{c} = \vec{a} \times \vec{b} + \mathbf{c} = \mathbf{a} \times \mathbf{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. @@ -528,10 +597,10 @@ 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. + 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} = @@ -543,16 +612,17 @@ \end{bmatrix} \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix} """ - if not sy: + # if not sy is not suitable because 0 is also false + if sy is None: 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). + 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} = @@ -571,30 +641,32 @@ """Use/create matrix like list of lists """ - def __getitem__(self, index): +
    [docs] 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]]) + >>> 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]) + >>> print(m[:, 1:3]) [[2, 3], [5, 6], [8, 9], [0, 0]] - >>> print(m[0:2,1:3]) + >>> print(m[0:2, 1:3]) [[2, 3], [5, 6]] - >>> print(m[::2,::2]) + >>> 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)) + # for 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])] + 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 + return matrix(item) if isinstance(item, list) else item
    [docs] @staticmethod def rx(theta): @@ -603,7 +675,7 @@ Rotates the coordinate system of vectors .. math:: - R_{x}(\theta) = + \mathbf{R}_{x}(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta & 0 \\ @@ -626,7 +698,7 @@ Rotates the coordinate system of vectors .. math:: - R_{y}(\theta) = + \mathbf{R}_{y}(\theta) = \begin{bmatrix} \cos \theta & 0 & \sin \theta & 0 \\ 0 & 1 & 0 & 0 \\ @@ -649,7 +721,7 @@ Rotates the coordinate system of vectors .. math:: - R_{z}(\theta) = + \mathbf{R}_{z}(\theta) = \begin{bmatrix} \cos \theta & -\sin \theta & 0 & 0 \\ \sin \theta & \cos \theta & 0 & 0 \\ @@ -660,14 +732,17 @@ :Example: .. math:: - R_{z}(\theta) \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = + \mathbf{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}1 \\ 0 \\ 0 \\ 1\end{bmatrix} \\ + &= \begin{bmatrix} 0 & -1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ @@ -690,7 +765,7 @@ r"""Translation matrix .. math:: - T = + \mathbf{T} = \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ @@ -710,13 +785,13 @@ 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. + 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 = + \mathbf{S} = \begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ @@ -724,7 +799,8 @@ 0 & 0 & 0 & 1 \end{bmatrix} """ - if not sy: + # if not sy is not suitable because 0 is also false + if sy is None: sy = sx sz = sx T = matrix([[sx, 0, 0, 0], @@ -733,11 +809,9 @@ [ 0, 0, 0, 1]]) return T
    - def __mul__(self, other): +
    [docs] def __mul__(self, other): r"""Scalar multiplication, dot product (inner product) or - matrix-vector multiplication. - - a * b (new object) + matrix-vector multiplication. (new object) :type other: scalar, vector (or 1d list), matrix (or 2d list) @@ -747,21 +821,25 @@ \mathbf{C} &= \mathbf{A} \cdot \mathbf{B} .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). + 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 + >>> 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. + >>> 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]) + >>> 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]]) + >>> 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]] @@ -769,18 +847,18 @@ :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]) + 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]) + 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]) + return matrix([[a*other for a in a_row] for a_row in self])
    - def __rmul__(self, other): +
    [docs] def __rmul__(self, other): r"""Scalar multiplication, dot product (inner product) or - vector-matrix multiplication. - - a * b (new object) + vector-matrix multiplication. (new object) :type other: scalar (or 1d list and 2d list) @@ -790,35 +868,38 @@ \mathbf{C} &= \mathbf{A} \cdot \mathbf{B} .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). + 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 + >>> m = 5 * matrix([[1, 2, 3, 4], [5, 6, 7, 8], \ + [9, 10, 11, 12], [0, 0, 0, 1]]) >>> 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]]) + >>> 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 + :meth:`__mul__` and :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]) + 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)]) + 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 + return self*other
    - def __str__(self): - return str([*self]) +
    [docs] def __str__(self): + return str([*self])
    - def __repr__(self): - return "matrix(" + str(self) + ")" +
    [docs] def __repr__(self): + return "matrix(" + str(self) + ")"
    [docs] def rotate_x(self, theta): r"""Rotation about the x dirction. @@ -929,10 +1010,10 @@ 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. + 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} @@ -954,7 +1035,8 @@ 0 & 0 & 0 & h \end{bmatrix} """ - if not sy: + # if not sy is not suitable because 0 is also false + if sy is None: sy = sx sz = sx self[:] = matrix.s(sx, sy, sz) * self diff --git a/docs/build/html/_sources/pylib.geometry_plot.rst.txt b/docs/build/html/_sources/pylib.geometry_plot.rst.txt new file mode 100644 index 0000000..9b86fbc --- /dev/null +++ b/docs/build/html/_sources/pylib.geometry_plot.rst.txt @@ -0,0 +1,7 @@ +pylib.geometry\_plot module +=========================== + +.. automodule:: pylib.geometry_plot + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/build/html/_sources/pylib.geometry_plot_pylab.rst.txt b/docs/build/html/_sources/pylib.geometry_plot_pylab.rst.txt new file mode 100644 index 0000000..f10524d --- /dev/null +++ b/docs/build/html/_sources/pylib.geometry_plot_pylab.rst.txt @@ -0,0 +1,7 @@ +pylib.geometry\_plot\_pylab module +================================== + +.. automodule:: pylib.geometry_plot_pylab + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/build/html/_sources/pylib.rst.txt b/docs/build/html/_sources/pylib.rst.txt index b66d511..922bf07 100644 --- a/docs/build/html/_sources/pylib.rst.txt +++ b/docs/build/html/_sources/pylib.rst.txt @@ -25,5 +25,7 @@ Submodules pylib.geometry pylib.geometry2d pylib.geometry2d_plot + pylib.geometry_plot + pylib.geometry_plot_pylab pylib.mathematics pylib.time_of_day diff --git a/docs/build/html/_static/alabaster.css b/docs/build/html/_static/alabaster.css index 8ccb045..39bcc1e 100644 --- a/docs/build/html/_static/alabaster.css +++ b/docs/build/html/_static/alabaster.css @@ -295,8 +295,8 @@ div.important { } div.note { - background-color: #EEE; - border: 1px solid #CCC; + background-color: #25272c; + border: 1px solid #2C2C2C; } div.tip { diff --git a/docs/build/html/_static/custom.css b/docs/build/html/_static/custom.css index b6a5152..e7df5f8 100644 --- a/docs/build/html/_static/custom.css +++ b/docs/build/html/_static/custom.css @@ -7,7 +7,7 @@ table.indextable tr.cap { } /* move doc link a bit up */ .viewcode-back { - float: right; - position: relative; - top: -1.5em; + float: right; + position: relative; + top: -1.5em; } diff --git a/docs/build/html/genindex.html b/docs/build/html/genindex.html index 995a34b..3429cb3 100644 --- a/docs/build/html/genindex.html +++ b/docs/build/html/genindex.html @@ -37,7 +37,8 @@

    Index

    - A + _ + | A | B | C | D @@ -62,6 +63,74 @@ | Z
    +

    _

    + + + +
    +

    A

    + + + + + + @@ -172,6 +182,16 @@ + + + + + +
    diff --git a/docs/build/html/objects.inv b/docs/build/html/objects.inv index d27f5f7..af114d8 100644 Binary files a/docs/build/html/objects.inv and b/docs/build/html/objects.inv differ diff --git a/docs/build/html/py-modindex.html b/docs/build/html/py-modindex.html index 2224931..c076c06 100644 --- a/docs/build/html/py-modindex.html +++ b/docs/build/html/py-modindex.html @@ -99,6 +99,16 @@ geometry2d_plot (*nix, Windows) 2D geometry plotting.
    + geometry_plot (*nix, Windows) + Geometry plotting.
    + geometry_plot_pylab (*nix, Windows) + Geometry plotting (pylab).
     
    i
        pylib.geometry2d_plot
        + pylib.geometry_plot +
        + pylib.geometry_plot_pylab +
        diff --git a/docs/build/html/pylib.data.html b/docs/build/html/pylib.data.html index af92f00..b86eb6f 100644 --- a/docs/build/html/pylib.data.html +++ b/docs/build/html/pylib.data.html @@ -83,6 +83,39 @@ array. m = k / n

    +
    +
    +issequence(obj)[source]
    +

    True for tuple, list, str +False for int, dict, set

    +
    +
    Example
    +

    +
    +
    >>> issequence(())
    +True
    +>>> issequence((3, ))
    +True
    +>>> issequence([])
    +True
    +>>> issequence([1])
    +True
    +>>> issequence([1, 2])
    +True
    +>>> issequence('')
    +True
    +
    +
    +
    >>> issequence((3))
    +False
    +>>> issequence({})
    +False
    +>>> issequence(set())
    +False
    +
    +
    +
    +
    load(file_name, default=None, verbose=False)[source]
    diff --git a/docs/build/html/pylib.function.html b/docs/build/html/pylib.function.html index 96a622a..8935d16 100644 --- a/docs/build/html/pylib.function.html +++ b/docs/build/html/pylib.function.html @@ -172,7 +172,7 @@ y(\theta) = (R - r)\sin\theta - d\sin\left(\frac{R-r}{r}\theta\right) \\

    See also

    -

    mathematics.lcm()

    +

    pylib.mathematics.lcm()

    @@ -359,7 +359,7 @@ Example of 3 columns and 3 rows (upside down view of ‘normal’ braille/drawil diff --git a/docs/build/html/pylib.geometry.html b/docs/build/html/pylib.geometry.html index cdf6301..3861f74 100644 --- a/docs/build/html/pylib.geometry.html +++ b/docs/build/html/pylib.geometry.html @@ -36,16 +36,23 @@

    pylib.geometry module

    -

    2D geometry objects.

    +

    Geometry objects.

    Date

    2019-12-21

    -
    +
    +

    Affine transforms

    +

    Functions in augmented space, in homogenous coordinates. +Points are augment to 4 dimensions, by adding a dummy coordinate. +For points the dummy coordinate is always normalized to 1. +With homogenous coordinates translation of points is repesentable +as a linear transformation.

    +
    class CS(x=[1, 0, 0], y=[0, 1, 0], z=[0, 0, 1])[source]
    -

    Bases: mathematics.matrix

    +

    Bases: pylib.mathematics.matrix

    Coordinate system

    @@ -85,13 +92,20 @@
    class Direction(x=1, y=0, z=0)[source]
    -

    Bases: mathematics.vector

    +

    Bases: pylib.mathematics.vector

    Direction in local coordinate system

    +
    +
    +class Hexahedron(point1=vector([-1, -1, -1, 1]), point2=vector([1, -1, -1, 1]), point3=vector([1, 1, -1, 1]), point4=vector([-1, 1, -1, 1]), point5=vector([-1, -1, 1, 1]), point6=vector([1, -1, 1, 1]), point7=vector([1, 1, 1, 1]), point8=vector([-1, 1, 1, 1]))[source]
    +

    Bases: pylib.geometry.Solid

    +

    Line a open wireframe object in local coordinate system

    +
    +
    -class Line(point1=vector([-1, 0, 0]), point2=vector([1, 0, 0]))[source]
    +class Line(point1=vector([-1, 0, 0, 1]), point2=vector([1, 0, 0, 1]))[source]

    Bases: pylib.geometry.Wireframe

    Line a open wireframe object in local coordinate system

    @@ -99,8 +113,14 @@
    class Point(x=0, y=0, z=0)[source]
    -

    Bases: mathematics.vector

    +

    Bases: pylib.mathematics.vector

    Point in local coordinate system

    +
    +
    +projection()[source]
    +

    Orthographic projection to the xy-plane

    +
    +
    @@ -110,12 +130,53 @@

    Polygon as closed wireframe object in local coordinate system

    +
    +
    +class Solid(*wireframes)[source]
    +

    Bases: object

    +

    Solid object in local coordinate system

    +

    This class lists Wireframe objects. +The Wireframe class create its own points (copy).

    +
    +
    +ch_cs(cs)[source]
    +
    + +
    +
    +scale(sx, sy=None, sz=None)[source]
    +
    + +
    +
    +translate(tx, ty, tz)[source]
    +
    + +
    +
    +wireframes()[source]
    +
    + +
    +
    class Wireframe(*points, closed=False)[source]

    Bases: object

    Open and closed wireframe object in local coordinate system

    This class create its own points (copy).

    +
    +
    +__iter__()[source]
    +

    Returns the Iterator object

    +
    + +
    +
    +__str__()[source]
    +

    Return str(self).

    +
    +
    ch_cs(cs)[source]
    @@ -152,10 +213,17 @@ translate(tx, ty, tz)[source]
    +
    +
    +xy()[source]
    +

    Get coordinates in 3d space

    +
    +
    xyz()[source]
    -
    +

    Get coordinates in 3d space

    +
    @@ -164,6 +232,12 @@ class World[source]

    Bases: object

    World-space with world-space coordinates

    +
    +
    +__iter__()[source]
    +

    Returns the Iterator object

    +
    +
    add(*objects)[source]
    @@ -224,8 +298,24 @@ translate(tx, ty, tz)[source]
    +
    +
    +wireframes()[source]
    +
    + +
    +
    +wireframes_xy()[source]
    +
    + +
    +
    +wireframes_xyz()[source]
    +
    +
    +
    diff --git a/docs/build/html/pylib.geometry2d.html b/docs/build/html/pylib.geometry2d.html index 7ccc9f6..14f9ac1 100644 --- a/docs/build/html/pylib.geometry2d.html +++ b/docs/build/html/pylib.geometry2d.html @@ -276,7 +276,7 @@ decides what the left and the right end point of the line is.

    See also

    -

    plot_lines() of the geometry_plot +

    plot_lines() of the geometry_plot module to plot the lines

    diff --git a/docs/build/html/pylib.geometry2d_plot.html b/docs/build/html/pylib.geometry2d_plot.html index e17c8dc..0ff8944 100644 --- a/docs/build/html/pylib.geometry2d_plot.html +++ b/docs/build/html/pylib.geometry2d_plot.html @@ -16,7 +16,7 @@ - + @@ -86,7 +86,7 @@
  • pylib
  • diff --git a/docs/build/html/pylib.geometry_plot.html b/docs/build/html/pylib.geometry_plot.html new file mode 100644 index 0000000..0c81824 --- /dev/null +++ b/docs/build/html/pylib.geometry_plot.html @@ -0,0 +1,123 @@ + + + + + + + pylib.geometry_plot module — pylib 2019.12.21 documentation + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + + +
    + +
    +

    pylib.geometry_plot module

    +

    Geometry plotter using matplotlib (pylab).

    +
    +
    Date
    +

    2019-12-23

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

    pylib.geometry_plot_pylab module

    +

    Geometry plotter using pylab (matplotlib).

    +
    +
    Date
    +

    2019-12-23

    +
    +
    +
    +
    +cad_wireframe(world, centering=True)[source]
    +

    Graphical projections

    +
      +
    • Parallel projections

      +
        +
      • Orthographic

        +
          +
        • Multiview

          +
            +
          • * First-angle

          • +
          • Third-angle

          • +
          • Plan Elevation

          • +
          +
        • +
        • Axonometric

          +
            +
          • * Isometric

          • +
          • Dimetric

          • +
          • Trimetri

          • +
          +
        • +
        +
      • +
      • Oblique

        +
          +
        • Carbinet

        • +
        • Cavalier

        • +
        • Military

        • +
        • Top-down

        • +
        +
      • +
      +
    • +
    • Perspective projections

      +
        +
      • 1-point

      • +
      • 2-point

      • +
      • 3-point

      • +
      • Curvilinear

      • +
      +
    • +
    +
    + +
    +
    +plot_post(ax)[source]
    +
    + +
    +
    +set_aspect_equal(ax)[source]
    +

    Make axes of 3D plot have equal scale so that spheres appear as +spheres, cubes as cubes, etc.. This is one possible solution to +Matplotlib’s ax.set_aspect(‘equal’) and ax.axis(‘equal’) not +working for 3D.

    +
    +
    Parameters
    +

    ax (pylab.Axes) – a pylab axis

    +
    +
    +

    Source: https://stackoverflow.com/a/35126679

    +
    + +
    +
    +wireframe3d(world)[source]
    +
    + +
    + + +
    + +
    +
    + +
    +
    + + + + + + + \ No newline at end of file diff --git a/docs/build/html/pylib.html b/docs/build/html/pylib.html index 77025b8..990ec91 100644 --- a/docs/build/html/pylib.html +++ b/docs/build/html/pylib.html @@ -61,9 +61,14 @@
  • pylib.date module
  • pylib.drawblock module
  • pylib.function module
  • -
  • pylib.geometry module
  • +
  • pylib.geometry module +
  • pylib.geometry2d module
  • pylib.geometry2d_plot module
  • +
  • pylib.geometry_plot module
  • +
  • pylib.geometry_plot_pylab module
  • pylib.mathematics module
  • pylib.time_of_day module
  • diff --git a/docs/build/html/pylib.mathematics.html b/docs/build/html/pylib.mathematics.html index d0d1fe2..9c445a4 100644 --- a/docs/build/html/pylib.mathematics.html +++ b/docs/build/html/pylib.mathematics.html @@ -17,7 +17,7 @@ - + @@ -53,6 +53,119 @@ class matrix[source]

    Bases: list

    Use/create matrix like list of lists

    +
    +
    +__getitem__(index)[source]
    +

    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]]
    +
    +
    +
    + +
    +
    +__mul__(other)[source]
    +

    Scalar multiplication, dot product (inner product) or +matrix-vector multiplication. (new object)

    +
    +
    +
    +\[\begin{split}\mathbf{C} &= \mathbf{A} \cdot b \\ +\mathbf{c} &= \mathbf{A} \cdot \mathbf{b} \\ +\mathbf{C} &= \mathbf{A} \cdot \mathbf{B}\end{split}\]
    +
    +

    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]]
    +
    +
    +
    +

    See also

    +

    __rmul__()

    +
    +
    + +
    +
    +__repr__()[source]
    +

    Return repr(self).

    +
    + +
    +
    +__rmul__(other)[source]
    +

    Scalar multiplication, dot product (inner product) or +vector-matrix multiplication. (new object)

    +
    +
    +
    +\[\begin{split}\mathbf{C} &= a \cdot \mathbf{B} \\ +\mathbf{c} &= \mathbf{a} \cdot \mathbf{B} \\ +\mathbf{C} &= \mathbf{A} \cdot \mathbf{B}\end{split}\]
    +
    +

    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]])
    +>>> 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]]
    +
    +
    +
    +

    See also

    +

    __mul__() and vector.__mul__() for vector * matrix

    +
    +
    + +
    +
    +__str__()[source]
    +

    Return str(self).

    +
    +
    rotate_x(theta)[source]
    @@ -134,7 +247,7 @@

    Rotation matrix about the x direction.

    Rotates the coordinate system of vectors

    -\[\begin{split}R_{x}(\theta) = +\[\begin{split}\mathbf{R}_{x}(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta & 0 \\ @@ -149,7 +262,7 @@

    Rotation matrix about the y direction.

    Rotates the coordinate system of vectors

    -\[\begin{split}R_{y}(\theta) = +\[\begin{split}\mathbf{R}_{y}(\theta) = \begin{bmatrix} \cos \theta & 0 & \sin \theta & 0 \\ 0 & 1 & 0 & 0 \\ @@ -164,7 +277,7 @@

    Rotation matrix about the z direction.

    Rotates the coordinate system of vectors

    -\[\begin{split}R_{z}(\theta) = +\[\begin{split}\mathbf{R}_{z}(\theta) = \begin{bmatrix} \cos \theta & -\sin \theta & 0 & 0 \\ \sin \theta & \cos \theta & 0 & 0 \\ @@ -176,14 +289,17 @@

    -\[\begin{split}R_{z}(\theta) \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = +\[\begin{split}\mathbf{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}1 \\ 0 \\ 0 \\ 1\end{bmatrix} \\ +&= \begin{bmatrix} 0 & -1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ @@ -200,12 +316,12 @@

    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.

    +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.

    -\[\begin{split}S = +\[\begin{split}\mathbf{S} = \begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ @@ -220,10 +336,10 @@ it should be.

    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.

    +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.

    \[\begin{split}\begin{bmatrix} xx' & xy' & xz' & t_x' \\ @@ -250,7 +366,7 @@ it should be.

    static t(tx, ty, tz)[source]

    Translation matrix

    -\[\begin{split}T = +\[\begin{split}\mathbf{T} = \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ @@ -292,60 +408,385 @@ it should be.

    Bases: list

    Use/create vector like lists

      -
    • size -> len(a)

    • -
    • abs -> abs(a)

    • -
    • dot -> a * b

    • -
    • outer -> a @ b

    • +
    • size, length of a vector use len(a)

    • +
    • absolute, magntude, norm of a vector use abs(a), see +__abs__()

    • +
    • dot product use a * b, see __mul__() and __rmul__()

    • +
    • outer product use a @ b, see __matmul__()

    -

    use super constructor

    -

    use super __iter__

    -

    use super __setitem__

    -
    >>> v = vector([1,2,3,4,5])
    ->>> v[3:5] = [1,2]
    +
    +
    __iter__
    +

    +
    +
    >>> [i*2 for i in vector([1, 2, 3])]
    +[2, 4, 6]
    +
    +
    +
    +
    __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
    +
    +
    __eq__(a, b)
    +

    +
    +
    >>> vector([1, 2, 3, 1, 2]) == vector([1, 2, 3, 1, 2])
    +True
    +>>> vector([1, 2, 3, 1, 2]) == vector([1, 2, 3, 2, 1])
    +False
    +
    +
    +
    +
    __ne__(a, b)
    +

    +
    +
    >>> vector([1, 2, 3, 1, 2]) != vector([1, 2, 3, 1, 2])
    +False
    +>>> vector([1, 2, 3, 1, 2]) != vector([1, 2, 3, 2, 1])
     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])
    +
    +
    __contains__
    +

    +
    +
    >>> 2 in vector([1, 2, 3])
     True
     
    -

    __isub__

    -
    >>> v = vector([1,2,3])
    ->>> v -= vector([3,3,3])
    +
    +
    __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])
    +
    +
    __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])
    +
    +
    __imatmul__
    +

    +
    +
    >>> m = vector([1, 2, 3])
    +>>> m *= vector([3, 3, 3])
     >>> print(v)
     [[3, 3, 3], [6, 6, 6], [9, 9, 9]]
     
    +
    +
    +__abs__()[source]
    +

    Magnitude / norm of a vector

    +
    +\[b = |\mathbf{a}| = \sqrt{\sum a_i^2} = +\sqrt{\mathbf{a} \cdot \mathbf{a}}\]
    +
    +
    Example
    +

    +
    +
    >>> v = vector([3, 4])
    +>>> abs(v)
    +5.0
    +
    +
    +
    + +
    +
    +__add__(other)[source]
    +

    a + b (new object)

    +
    +\[\mathbf{c} = \mathbf{a} + \mathbf{b}\]
    +
    +
    Example
    +

    +
    +
    >>> v = vector([1, 2, 3]) + vector([1, 2, 3])
    +>>> print(v)
    +[2, 4, 6]
    +
    +
    +
    + +
    +
    +__ge__(other)[source]
    +

    Test if this object is greater (larger) than or equal the +other object.

    +
    +\[|\mathbf{a}| \ge |\mathbf{b}|\]
    +
    +
    Example
    +

    +
    +
    >>> vector([1, 2, 3]) >= vector([3, 2, 1])
    +True
    +>>> vector([1, 2, 3]) >= vector([4, 2, 1])
    +False
    +
    +
    +
    + +
    +
    +__getitem__(index)[source]
    +

    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
    +
    +
    +
    + +
    +
    +__gt__(other)[source]
    +

    Test if this object is greater (larger) than the other +object.

    +
    +\[|\mathbf{a}| \gt |\mathbf{b}|\]
    +
    +
    Example
    +

    +
    +
    >>> vector([1, 2, 3]) > vector([3, 2, 1])
    +False
    +>>> vector([1, 2, 3]) > vector([2, 2, 1])
    +True
    +
    +
    +
    + +
    +
    +__iadd__(other)[source]
    +

    a += b (new object)

    +
    +
    Example
    +

    +
    +
    >>> v = vector([1, 2, 3])
    +>>> v += vector([3, 3, 3])
    +>>> print(v)
    +[4, 5, 6]
    +
    +
    +
    + +
    +
    +__le__(other)[source]
    +

    Test if this object is lower (smaller) than or equal the +other object.

    +
    +\[|\mathbf{a}| \le |\mathbf{b}|\]
    +
    +
    Example
    +

    +
    +
    >>> vector([3, 2, 1]) <= vector([1, 2, 3])
    +True
    +>>> vector([3, 2, 1]) <= vector([1, 2, 2])
    +False
    +
    +
    +
    + +
    +
    +__lt__(other)[source]
    +

    Test if this object is lower (smaller) than the other object.

    +
    +\[|\mathbf{a}| \lt |\mathbf{b}|\]
    +
    +
    Example
    +

    +
    +
    >>> vector([3, 2, 1]) < vector([1, 2, 3])
    +False
    +>>> vector([3, 2, 1]) < vector([1, 2, 4])
    +True
    +
    +
    +
    + +
    +
    +__matmul__(other)[source]
    +

    Outer product a @ b (new object)

    +
    +\[\begin{split}\mathbf{c} = \mathbf{a} \otimes \mathbf{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}\end{split}\]
    +
    +
    Example
    +

    +
    +
    >>> m = vector([1, 2, 3]) @ vector([1, 2, 4])
    +>>> print(m)
    +[[1, 2, 4], [2, 4, 8], [3, 6, 12]]
    +
    +
    +
    + +
    +
    +__mul__(other)[source]
    +

    Scalar multiplication, dot product (inner product) or +vector-matrix multiplication. (new object)

    +
    +
    +
    +\[\begin{split}\mathbf{c} &= \mathbf{a} \cdot b \\ +\mathbf{c} &= \mathbf{a} \cdot \mathbf{b} \\ +\mathbf{c} &= \mathbf{a} \cdot \mathbf{B}\end{split}\]
    +
    +

    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
    +
    +
    +
    +

    See also

    +

    __rmul__()

    +
    +
    + +
    +
    +__neg__()[source]
    +

    - a (new object)

    +
    +\[\mathbf{b} = -\mathbf{a}\]
    +
    + +
    +
    +__pos__()[source]
    +

    + a (new object)

    +
    +\[\mathbf{b} = +\mathbf{a}\]
    +
    + +
    +
    +__repr__()[source]
    +

    Return repr(self).

    +
    + +
    +
    +__rmul__(other)[source]
    +

    Scalar multiplication, dot product (inner product) or +matrix-vector multiplication. (new object)

    +
    +
    +
    +\[\begin{split}\mathbf{c} &= a \cdot \mathbf{b} \\ +\mathbf{c} &= \mathbf{a} \cdot \mathbf{b} \\ +\mathbf{c} &= \mathbf{A} \cdot \mathbf{b}\end{split}\]
    +
    +

    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]
    +
    +
    +
    +

    See also

    +

    __mul__() and matrix.__mul__() for matrix * vector

    +
    +
    + +
    +
    +__str__()[source]
    +

    Return str(self).

    +
    + +
    +
    +__sub__(other)[source]
    +

    a - b (new object)

    +
    +\[\mathbf{c} = \mathbf{a} - \mathbf{b}\]
    +
    +
    Example
    +

    +
    +
    >>> v = vector([1, 2, 3]) - vector([1, 2, 3])
    +>>> print(v)
    +[0, 0, 0]
    +
    +
    +
    +
    static abs(a)[source]
    @@ -370,9 +811,9 @@ it should be.

    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).

    +

    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).

    \[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = \begin{bmatrix} @@ -401,7 +842,7 @@ v and w direction vectors).

    c is orthogonal to both a and b. The direction of c can be found with the right-hand rule.

    -\[\vec{c} = \vec{a} \times \vec{b}\]
    +\[\mathbf{c} = \mathbf{a} \times \mathbf{b}\]
    @@ -444,10 +885,10 @@ columns filled with v.

    -\[\vec{e}_a = \frac{\vec{a}}{|\vec{a}|}\]
    +\[\mathbf{\hat{a}} = \frac{\mathbf{a}}{|\mathbf{a}|}\]

    See also

    -

    norm() for a norm (magnitude) of a vector

    +

    __abs__() for a norm (magnitude) of a vector

    @@ -473,8 +914,8 @@ columns filled with ones.

    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.

    +

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

    Example

    @@ -548,10 +989,10 @@ columns filled with random numbers.

    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.

    +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.

    \[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = \begin{bmatrix} @@ -578,11 +1019,6 @@ it should be.

    \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix}\end{split}\]
    -
    -
    -xyz()[source]
    -
    -
    static zeros(length)[source]
    @@ -637,7 +1073,7 @@ columns filled with zeros.

  • Documentation overview
    • pylib
    • diff --git a/docs/build/html/searchindex.js b/docs/build/html/searchindex.js index 2fec14d..efdc850 100644 --- a/docs/build/html/searchindex.js +++ b/docs/build/html/searchindex.js @@ -1 +1 @@ -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 +Search.setIndex({docnames:["index","modules","pylib","pylib.data","pylib.date","pylib.drawblock","pylib.function","pylib.geometry","pylib.geometry2d","pylib.geometry2d_plot","pylib.geometry_plot","pylib.geometry_plot_pylab","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.geometry_plot.rst","pylib.geometry_plot_pylab.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:[14,0,0,"-"],geometry2d:[8,0,0,"-"],geometry2d_plot:[9,0,0,"-"],geometry:[7,0,0,"-"],geometry_plot:[10,0,0,"-"],geometry_plot_pylab:[11,0,0,"-"],integration:[15,0,0,"-"],mathematics:[12,0,0,"-"],ode:[16,0,0,"-"],ode_model:[17,0,0,"-"],pylib:[2,0,0,"-"],time_of_day:[18,0,0,"-"]},"pylib.data":{fold_list:[3,1,1,""],get_id:[3,1,1,""],issequence:[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,""],Hexahedron:[7,2,1,""],Line:[7,2,1,""],Point:[7,2,1,""],Polygon:[7,2,1,""],Solid:[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.Point":{projection:[7,3,1,""]},"pylib.geometry.Solid":{ch_cs:[7,3,1,""],scale:[7,3,1,""],translate:[7,3,1,""],wireframes:[7,3,1,""]},"pylib.geometry.Wireframe":{__iter__:[7,3,1,""],__str__:[7,3,1,""],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,""],xy:[7,3,1,""],xyz:[7,3,1,""]},"pylib.geometry.World":{__iter__:[7,3,1,""],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,""],wireframes:[7,3,1,""],wireframes_xy:[7,3,1,""],wireframes_xyz:[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.geometry_plot_pylab":{cad_wireframe:[11,1,1,""],plot_post:[11,1,1,""],set_aspect_equal:[11,1,1,""],wireframe3d:[11,1,1,""]},"pylib.mathematics":{lcm:[12,1,1,""],matrix:[12,2,1,""],vector:[12,2,1,""]},"pylib.mathematics.matrix":{__getitem__:[12,3,1,""],__mul__:[12,3,1,""],__repr__:[12,3,1,""],__rmul__:[12,3,1,""],__str__:[12,3,1,""],rotate_x:[12,3,1,""],rotate_y:[12,3,1,""],rotate_z:[12,3,1,""],rx:[12,3,1,""],ry:[12,3,1,""],rz:[12,3,1,""],s:[12,3,1,""],scale:[12,3,1,""],t:[12,3,1,""],translate:[12,3,1,""]},"pylib.mathematics.vector":{__abs__:[12,3,1,""],__add__:[12,3,1,""],__ge__:[12,3,1,""],__getitem__:[12,3,1,""],__gt__:[12,3,1,""],__iadd__:[12,3,1,""],__le__:[12,3,1,""],__lt__:[12,3,1,""],__matmul__:[12,3,1,""],__mul__:[12,3,1,""],__neg__:[12,3,1,""],__pos__:[12,3,1,""],__repr__:[12,3,1,""],__rmul__:[12,3,1,""],__str__:[12,3,1,""],__sub__:[12,3,1,""],abs:[12,3,1,""],ang:[12,3,1,""],arg:[12,3,1,""],ch_cs:[12,3,1,""],conjugate:[12,3,1,""],cross:[12,3,1,""],full:[12,3,1,""],im:[12,3,1,""],normalize:[12,3,1,""],ones:[12,3,1,""],random:[12,3,1,""],re:[12,3,1,""],rotate_x:[12,3,1,""],rotate_y:[12,3,1,""],rotate_z:[12,3,1,""],scale:[12,3,1,""],translate:[12,3,1,""],zeros:[12,3,1,""]},"pylib.numerical":{fit:[14,0,0,"-"],integration:[15,0,0,"-"],ode:[16,0,0,"-"],ode_model:[17,0,0,"-"]},"pylib.numerical.fit":{gauss:[14,1,1,""],gauss_fit:[14,1,1,""]},"pylib.numerical.integration":{trapez:[15,1,1,""]},"pylib.numerical.ode":{e1:[16,1,1,""],e2:[16,1,1,""],e4:[16,1,1,""],fpi:[16,1,1,""],i1:[16,1,1,""],newmark_newtonraphson:[16,1,1,""],newmark_newtonraphson_rdk:[16,1,1,""]},"pylib.numerical.ode_model":{disk:[17,1,1,""],disk_nm:[17,1,1,""],disk_nmmdk:[17,1,1,""]},"pylib.time_of_day":{days:[18,1,1,""],days_norm:[18,1,1,""],hours:[18,1,1,""],hours_norm:[18,1,1,""],in_seconds:[18,1,1,""],minutes:[18,1,1,""],minutes_norm:[18,1,1,""],seconds:[18,1,1,""],seconds_norm:[18,1,1,""],transform:[18,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,"-"],geometry_plot:[10,0,0,"-"],geometry_plot_pylab:[11,0,0,"-"],mathematics:[12,0,0,"-"],numerical:[13,0,0,"-"],time_of_day:[18,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":16,"259f":6,"28ff":6,"2\u03c0f":6,"2nd":16,"4th":16,"9fsche_osterformel":4,"\u03bb":6,"\u03bd":6,"\u03c0":6,"\u03c6":6,"\u03c9":6,"boolean":6,"case":[6,15],"char":[3,6],"class":[7,12],"default":[3,6,8,14,15,16,18],"f\u00fcr":4,"float":[3,6,8,14,15,16,18],"fr\u00fchling":4,"function":[1,2,7,12,14,15,16,17],"gau\u00dfsch":4,"gau\u00dfsche_osterformel":4,"int":[3,4,6,8,12,14,15,16],"korrekturgr\u00f6\u00df":4,"m\u00e4rz":4,"m\u00e4rzdatum":4,"new":[12,18],"return":[3,4,6,7,8,12,14,15,16,18],"s\u00e4kular":4,"s\u00e4kularzahl":4,"static":[7,12],"super":[],"switch":6,"true":[3,6,11,12],"vorw\u00e4rt":16,Axes:11,Das:4,For:[7,12],The:[3,6,7,8,12,15,16,18],Use:12,With:7,_____:6,__abs__:12,__add__:12,__contains__:12,__eq__:12,__ge__:12,__getitem__:12,__gt__:12,__iadd__:12,__imatmul__:12,__imul__:12,__isub__:12,__iter__:[7,12],__le__:12,__lt__:12,__matmul__:12,__mul__:12,__ne__:12,__neg__:12,__pos__:12,__repr__:12,__rmul__:12,__setitem__:12,__str__:[7,12],__sub__:12,_subplot:[],a_i:12,about:12,abs:12,absolut:[8,12],add:7,adding:7,addit:8,affin:[1,2],afterward:12,against:16,algorithmu:4,alia:6,als:4,also:6,alwai:7,amplitud:[6,14],analyt:15,ang:12,angl:[8,11],angle1:8,angle2:8,angular:6,anim:6,appear:11,approx:15,approxim:[14,15,16],april:4,area:15,arg:12,argument:[6,8],arithmet:3,around:[6,8,12],arrai:3,ascens:4,ascension_of_jesu:4,ascii:3,assum:8,attach:6,augment:7,averag:18,avoid:12,axes3dsubplot:[],axes:11,axi:[6,11],axonometr:11,back:12,backward:16,base:[7,12,15],becaus:6,becom:16,begin:[12,16],beta:16,between:[3,6,8],binari:3,block:[5,6],bmatrix:[12,16],bool:[3,6,14,15,16],both:12,bottom:[6,8],bound:3,boundari:8,bounding_box:7,braill:6,build:8,cad_wirefram:11,calcul:[4,14,18],call:6,can:12,carbinet:11,cauchi:16,cavali:11,cdot:[12,16],center:[6,7,8,11,12],ch_c:[7,12],chang:[6,8],char_set:6,charact:[5,6],characterist:6,chart:[5,6],check:12,choos:16,circl:[6,7],close:[3,7],column:[3,6,12],com:11,common:[3,12],complex:12,composit:15,comput:12,condit:[8,16],conduct:12,conjug:12,consecut:3,constant:3,constructor:[],content:0,convert:[3,18],coordin:[7,8,12],copi:7,cos:[6,12],cosin:6,cosine_wav:6,counterclockwis:8,creat:[3,7,12],cross:12,cube:11,cubic:8,cubic_deg:8,cudb:6,curv:6,curvilinear:11,cycl:6,dai:[4,18],data:[1,2,6,14],databas:6,date:[1,2,3,5,6,7,8,9,10,11,12,14,15,16,17,18],datetim:4,datum:4,days_norm:18,ddot:16,decid:8,defin:[8,12],definit:15,deflect:8,deform:8,degener:3,degre:[6,8],den:4,densiti:6,depend:6,der:4,derform:8,deriv:[16,17],des:4,describ:[6,17],deviat:[6,14],diamet:[16,17],dict:3,die:4,differ:[3,16],differenti:[16,17],dimens:[6,7],dimension:3,dimenson:3,dimetr:11,dirction:12,direct:[6,7,8,12],disk:17,disk_nm:17,disk_nmmdk:17,displac:[8,16],distanc:[6,8],distribut:14,divid:15,doe:[6,8],dot:[5,6,12,16],down:[6,11],draw:5,drawblock:[1,2],drawil:6,dummi:7,each:[6,8],easter:4,easter_fridai:4,easter_mondai:4,easter_sundai:4,eccentr:17,edg:8,either:[6,8,12],element:[3,6,8],elev:11,empti:3,emptyset:3,end:[3,8,12,15,16],endpoint:8,entfernung:4,epitrochoid:6,equal:[11,12,15],equalii:15,equat:[6,16,17],error:[14,16],ersten:4,etc:11,euler:16,everi:16,exampl:[3,6,8,12,15,16],except:12,expect:14,explicit:16,explizit:16,exterior:6,f_n:15,factor:[6,8],fail:3,fals:[3,6,7,12,14,15,16],fassregel:15,file:3,file_nam:3,filenam:3,fill:12,fill_valu:12,first:[3,6,8,11,16,17],fisrt:6,fit:[2,13],fix:[6,16],float64:14,fnm:16,fold_list:3,follow:3,foral:15,forward:16,found:12,fourth:16,fpi:16,frac:[6,8,12,15,16],frame:6,frequenc:6,fridai:4,from:[3,6,12,16],full:[3,12,14],fwhm:14,gamma:16,gau:4,gauss:14,gauss_fit:14,gca:[],gener:6,geometri:[1,2,8,9,10,11],geometry2d:[1,2],geometry2d_plot:[1,2],geometry_plot:[1,2,8],geometry_plot_pylab:[1,2],get:[3,7],get_coordin:7,get_id:3,gilt:4,given:[3,8,12,14,16],global:[8,16],global_deform:8,govern:17,graphic:11,greater:12,gregorian:18,gregorianischen:4,half:14,hand:12,happen:12,has:[3,12,16],hat:12,have:[6,11,12],head:6,height:8,hermit:8,hexahedron:7,higher:6,histogram:[5,6],homogen:7,horizont:[6,8],hour:18,hours_norm:18,http:[4,11],hyotrochoid:6,hypotrochoid:6,ids:3,imaginari:12,implicit:16,in_second:18,inc:8,incid:8,index:[0,3,6,8,12],index_offset:8,inform:[3,14,15,16],initi:[16,17],inner:12,insid:6,integr:[2,13],integrand:15,interior:6,interpol:8,interpolate_hermit:8,interpret:[3,6],interv:15,isinst:12,isometr:11,issequ:3,iter:[7,16],its:[6,7,12],jahr:4,jesu:4,johann:15,kalend:4,kalendarisch:4,keim:4,kepler:15,keplersch:15,keyword:8,kutta:16,kwarg:[8,9],kx1:3,lag:6,lambda:[6,15],larger:12,last:6,lcm:[6,12],ldot:[15,16],lead:6,left:[3,6,8,15],leftrightarrow:14,len:12,length:[3,8,12,18],leq:15,lhape:12,lhd:8,like:12,limit:15,limits_:15,limits_a:15,line:[6,7,8],linear:[6,7],list:[3,6,7,8,12,14,15,16,17],lmax:12,lmin:12,lns:9,load:3,local:[7,16],locat:12,lower:[3,12,15],lowest:12,lst:3,lvd:8,lvert:16,magnitud:12,magntud:12,make:[6,11],manipul:3,march:4,mathbf:12,mathemat:[1,2,6,7],mathmat:17,mathrm:[6,14,15],matplotlib:[9,10,11],matrix:[7,12],max:6,max_iter:16,maximum:[14,16],mean:[6,16],method:16,militari:11,min:6,minumum:3,minut:18,minutes_norm:18,model:17,modul:[0,1,2,13],modulu:12,mondai:4,mondparamet:4,mondschaltung:4,move:[6,12],multipl:12,multiview:11,mxn:3,ndarrai:14,necessari:15,necessarili:15,newmark:16,newmark_newtonraphson:16,newmark_newtonraphson_rdk:16,node:8,non:6,none:[3,5,6,7,8,12,14,15],nonsens:12,norm:[6,12],normal:[6,7,12,18],note:12,number:[6,8,12,15,16],numer:[1,2],numerisch:15,numpi:14,obj:3,object:[3,7,8,12],object_data:3,obliqu:11,occur:6,ode:[2,13],ode_model:[2,13],offset:[14,18],often:6,omega:6,one:[3,6,8,11,16],ones:12,onli:3,open:[3,7],option:[6,8],order:[8,16,17],ordinari:[6,16,17],org:4,origin:[8,12],orthogon:12,orthograph:[7,11],oscil:6,osterentfernung:4,osterformel:4,ostergrenz:4,ostersonntag:4,other:[8,12],otherwis:8,otim:12,outer:12,output:[],outsid:6,over:6,own:7,packag:[0,1],page:0,parallel:11,paramet:[3,4,6,8,11,12,14,15,16,17,18],part:[6,12],pattern:6,peak:6,pentecost:4,per:[6,16],perform:12,period:6,perspect:11,phase:[6,12],phi:6,pixel:6,plan:11,plane:[7,8],plot:[6,8,11],plot_cubic_lin:9,plot_lin:[8,9],plot_post:11,plotter:[9,10,11],pmatrix:12,point1:[7,8],point1_i:8,point1_x:8,point2:[7,8],point2_i:8,point2_x:8,point3:[7,8],point4:[7,8],point5:7,point6:7,point7:7,point8:7,point:[6,7,8,11,15,16],point_i:8,point_x:8,points1_i:8,polygon:[7,8],polygonzugverfahren:16,popt:14,posit:[6,14],position_norm:18,possibl:11,print:[8,12,15,16],problem:[16,17],product:12,program:3,project:[7,11],propag:6,proport:16,proportion:6,pts:8,pylab:[9,10,11],quad:[15,16],quadratur:15,quasi:6,radian:[6,8],radiu:[6,7],random:12,rang:[6,12,18],rate:6,read:3,real:12,rectangl:8,refer:6,relat:6,repesent:7,repr:12,repres:6,residuum:16,result:[6,12],rhd:8,right:[3,6,8,12,15],roation:8,roll:6,rotat:[8,12,17],rotate_deg:8,rotate_i:[7,12],rotate_x:[7,12],rotate_xi:8,rotate_z:[7,12],rotation_plan:8,row:[6,12],rule:[12,15],rung:16,rvd:8,rvert:16,s_x:12,s_y:12,s_z:12,said:6,same:3,sampl:8,sample_point1_x:8,sample_point2_i:8,sample_point2_x:8,sample_points1_i:8,save_valu:15,scalar:12,scale:[6,7,11,12],scale_horizont:6,scale_i:8,scale_vert:6,scale_x:8,sche:16,search:0,second:[3,6,8,16,17,18],seconds_norm:18,see:12,segment:15,self:[7,12],seq:3,sequenc:3,set:[3,6,16],set_aspect:11,set_aspect_equ:11,shape:12,shift:6,shift_horizont:6,shift_vert:6,should:[8,12],side:15,sigma:14,simpson:15,simpsonregel:15,sin:[6,12],sine:6,sine_wav:6,sinusoid:6,size:[3,8,12,16],slope:8,smaller:12,smooth:6,solid:[7,8],solut:[11,15,16],solv:16,solver:16,sonnenschaltung:4,sonntag:4,sourc:[3,4,5,6,7,8,9,11,12,14,15,16,17,18],space:[7,15],space_diagon:7,spacial:4,spatial:6,special:15,specif:6,specifi:[6,15],speed:6,sphere:11,sqrt:[12,14],squar:[8,16],stabl:16,stackoverflow:11,standard:[14,16],start:[3,6,8],step:[3,16],stop:3,store:3,str:[3,6,7,12],straight:8,string:[6,8],struct_tim:18,structur:3,subinterv:15,submodul:1,subpackag:1,sum:[12,15],sundai:4,symbol:5,system:[7,8,12,16,17],t_0:16,t_i:16,t_x:12,t_y:12,t_z:12,tabl:8,tagen:4,term:3,test:12,text:16,than:[3,8,12],therefor:[12,16],theta:[6,7,12],theta_end:6,thi:[6,7,8,11,12],thick:16,thicker:6,third:11,thoma:15,ti1:16,time:[6,12,16,17,18],time_norm:18,time_of_dai:[1,2],to_str:6,tol:16,toler:16,top:[8,11],torqu:17,transform:[1,2,6,12,18],translat:[7,8,12],translate_xi:8,trapez:15,trapezium:15,trapezoid:15,trapezregel:15,trimetri:11,truee:[],tupl:[3,6,8,14],two:[3,8,15],type:[3,4,6,8,12,14,15,18],typr:6,u_i:12,u_x:12,u_z:12,uid:3,unicod:6,uniform:12,uniqu:3,unique_end:3,unit:6,upper:[3,15],upsid:6,usag:[6,12],use:12,used:14,uses:6,using:[9,10,11,15],usw:4,v_x:12,v_y:12,v_z:12,valu:[6,12,14,15,16,17,18],varepsilon:16,variabl:[4,6,15],varianc:14,varphi:6,vec:8,vector:[7,8,12],veloc:16,verbos:[3,14,15,16],verfahren:16,vert_0:15,vert_a:15,vertcal:8,vertic:[6,8,14],view:6,vollmond:4,von:4,w_x:12,w_y:12,w_z:12,wave:6,wavelength:6,wavenumb:6,what:8,when:12,where:[6,12,14],which:[6,16],width:[6,8,14],wiki:4,wikipedia:4,window:6,wirefram:7,wireframe3d:11,wireframes_xi:7,wireframes_xyz:7,wise:8,work:11,world:[7,11],write:3,wrong:12,x90:7,x_0:[6,15,16],x_1:[6,8,15,16],x_2:[8,15,16],x_column:3,x_fit:14,x_i:[15,16],x_n:15,xm90:7,xp0:16,xpn:17,xpp0:16,xppn:17,xyz:7,y90:7,y_1:8,y_2:8,y_column:3,y_fit:14,year:[4,18],ym90:7,zero:[6,12]},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.geometry_plot module","pylib.geometry_plot_pylab 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,affin:7,data:3,date:4,document:0,drawblock:5,fit:14,geometri:7,geometry2d:8,geometry2d_plot:9,geometry_plot:10,geometry_plot_pylab:11,indic:0,integr:15,mathemat:12,modul:[3,4,5,6,7,8,9,10,11,12,14,15,16,17,18],numer:[13,14,15,16,17],ode:16,ode_model:17,packag:[2,13],pylib:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18],submodul:[2,13],subpackag:2,tabl:0,time_of_dai:18,transform:7,welcom:0}}) \ No newline at end of file diff --git a/docs/source/_static/custom.css b/docs/source/_static/custom.css index b6a5152..e7df5f8 100644 --- a/docs/source/_static/custom.css +++ b/docs/source/_static/custom.css @@ -7,7 +7,7 @@ table.indextable tr.cap { } /* move doc link a bit up */ .viewcode-back { - float: right; - position: relative; - top: -1.5em; + float: right; + position: relative; + top: -1.5em; } diff --git a/docs/source/conf.py b/docs/source/conf.py index 77c126e..2f8f21e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -82,4 +82,10 @@ html_theme_options = { 'xref_border': 'transparent', 'seealso_bg': '#25272c', 'seealso_border': '#2C2C2C', + 'note_bg': '#25272c', + 'note_border': '#2C2C2C', +} + +autodoc_default_options = { + 'special-members': '__iter__, __contains__, __getitem__, __setitem__, __pos__, __neg__, __add__, __iadd__, __sub__, __isub__, __mul__, __rmul__, __imul__, __matmul__, __imatmul__, __abs__, __lt__, __le__, __gt__, __ge__, __eq__, __ne__, __str__, __repr__' } diff --git a/docs/source/pylib.geometry_plot.rst b/docs/source/pylib.geometry_plot.rst new file mode 100644 index 0000000..9b86fbc --- /dev/null +++ b/docs/source/pylib.geometry_plot.rst @@ -0,0 +1,7 @@ +pylib.geometry\_plot module +=========================== + +.. automodule:: pylib.geometry_plot + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.geometry_plot_pylab.rst b/docs/source/pylib.geometry_plot_pylab.rst new file mode 100644 index 0000000..f10524d --- /dev/null +++ b/docs/source/pylib.geometry_plot_pylab.rst @@ -0,0 +1,7 @@ +pylib.geometry\_plot\_pylab module +================================== + +.. automodule:: pylib.geometry_plot_pylab + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/pylib.rst b/docs/source/pylib.rst index b66d511..922bf07 100644 --- a/docs/source/pylib.rst +++ b/docs/source/pylib.rst @@ -25,5 +25,7 @@ Submodules pylib.geometry pylib.geometry2d pylib.geometry2d_plot + pylib.geometry_plot + pylib.geometry_plot_pylab pylib.mathematics pylib.time_of_day diff --git a/examples/geometry_hexahedra.py b/examples/geometry_hexahedra.py new file mode 100644 index 0000000..72e2410 --- /dev/null +++ b/examples/geometry_hexahedra.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Example geometry of hexahedra. + +:Date: 2019-12-24 + +.. module:: geometry_hexahedra + :platform: *nix, Windows + :synopsis: Example geometry of hexahedra. + +.. moduleauthor:: Daniel Weschke +""" +from pylib.geometry import World, Hexahedron +from pylib.geometry_plot_pylab import cad_wireframe + +def geometry(): + w = World() + for i in range(3): + for j in range(3): + for k in range(3): + w.add(Hexahedron().scale(0.8).translate(-2+2*i, -2+2*j, -2+2*k)) + return w + + +if __name__ == "__main__": + w = geometry() + #print(w.bounding_box()) + #print(*w) + #print(w.wireframes_xyz()) + cad_wireframe(w) diff --git a/examples/geometry_lines_circles.py b/examples/geometry_lines_circles.py new file mode 100644 index 0000000..a926fd2 --- /dev/null +++ b/examples/geometry_lines_circles.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Example geometry of lines and circles. + +:Date: 2019-12-23 + +.. module:: geometry_pyramidal_frustum + :platform: *nix, Windows + :synopsis: Example geometry of lines and circles. + +.. moduleauthor:: Daniel Weschke +""" +import math +from pylib.geometry import World, Point, Line, Circle +from pylib.geometry_plot_pylab import cad_wireframe, wireframe3d + +def geometry(): + w = World() + + p0 = Point(0, 0, 0) + p = Point(1, 1, 1) + + # add Lines to the Word + theta = math.pi/4 + w.add(*[Line(p0, p.rotate_x(theta/5)) for i in range(30)]) + w.add(*[Line(p0, p.rotate_x(theta/5)).translate(.1*i, 0, 0) for i in range(30)]) + + # add Circles to the Word + c1 = Circle() + c2 = Circle(2) + c3 = Circle(n=18).scale(3).rotate_x(math.pi/4) + w.add(c1, c2, c3) + + return w + + +if __name__ == "__main__": + w = geometry() + print(*w) + wireframe3d(w) + cad_wireframe(w, False) diff --git a/examples/geometry_pyramidal_frustum.py b/examples/geometry_pyramidal_frustum.py new file mode 100644 index 0000000..876659d --- /dev/null +++ b/examples/geometry_pyramidal_frustum.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Example geometry of a pyramidal frustum. + +:Date: 2019-12-23 + +.. module:: geometry_pyramidal_frustum + :platform: *nix, Windows + :synopsis: Example geometry of a pyramidal frustum. + +.. moduleauthor:: Daniel Weschke +""" +from pylib.geometry import World, Point, Polygon, Hexahedron +from pylib.geometry_plot_pylab import cad_wireframe + +def geometry(): + w = World() + p0 = Point() + p1 = Point(1.00, 0, 0) + p2 = Point(1.00, 1, 0) + p3 = Point(0.00, 1, 0) + p4 = Point(0.25, 0.25, 1) + p5 = Point(0.75, 0.25, 1) + p6 = Point(0.75, 0.75, 1) + p7 = Point(0.25, 0.75, 1) + pg0 = Polygon(p0, p1, p2, p3) + pg1 = Polygon(p4, p5, p6, p7) + pg2 = Polygon(p0, p1, p5, p4) + pg3 = Polygon(p2, p3, p7, p6) + w.add(pg0, pg1, pg2, pg3) + h = Hexahedron() + w.add(h) + return w + + +if __name__ == "__main__": + w = geometry() + print(*w) + print(w.wireframes_xyz()) + cad_wireframe(w) diff --git a/pylib/data.py b/pylib/data.py index 7f3e694..80a4d3d 100644 --- a/pylib/data.py +++ b/pylib/data.py @@ -12,6 +12,36 @@ """ import math import pickle +import collections + +def issequence(obj): + """ + True for tuple, list, str + False for int, dict, set + + :Example: + + >>> issequence(()) + True + >>> issequence((3, )) + True + >>> issequence([]) + True + >>> issequence([1]) + True + >>> issequence([1, 2]) + True + >>> issequence('') + True + + >>> issequence((3)) + False + >>> issequence({}) + False + >>> issequence(set()) + False + """ + return isinstance(obj, collections.abc.Sequence) def read(file_name, x_column, y_column, default=None, verbose=False): """Read ascii data file. diff --git a/pylib/function.py b/pylib/function.py index 95e6a8d..31e65aa 100644 --- a/pylib/function.py +++ b/pylib/function.py @@ -200,7 +200,7 @@ def hypotrochoid(R, r, d): >>> x, y, theta_end = hyotrochoid(20, 6, 6) .. seealso:: - :meth:`mathematics.lcm` + :meth:`pylib.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) @@ -377,7 +377,7 @@ def to_str(f, x=None, x_0=0, x_1=1, t=None, h=10, w=80, density=1, char_set="lin .. seealso:: - :meth:`pylib.function.transformation` + :meth:`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] @@ -402,7 +402,7 @@ def to_str(f, x=None, x_0=0, x_1=1, t=None, h=10, w=80, density=1, char_set="lin #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 + from .drawblock import histogram pixels_horizontal = 1 pixels_vertical = 8 @@ -412,6 +412,6 @@ def to_str(f, x=None, x_0=0, x_1=1, t=None, h=10, w=80, density=1, char_set="lin 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) + frame = histogram(f, x) return frame diff --git a/pylib/geometry.py b/pylib/geometry.py index e14df30..53c97a0 100644 --- a/pylib/geometry.py +++ b/pylib/geometry.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -"""2D geometry objects. +"""Geometry objects. :Date: 2019-12-21 @@ -9,26 +9,37 @@ :synopsis: Geometry objects. .. moduleauthor:: Daniel Weschke + +Affine transforms +----------------- + +Functions in augmented space, in homogenous coordinates. +Points are augment to 4 dimensions, by adding a dummy coordinate. +For points the dummy coordinate is always normalized to 1. +With homogenous coordinates translation of points is repesentable +as a linear transformation. """ import math import copy -from pylib.mathematics import vector, matrix +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 __str__(self): - return str(self.xyz()) - class Point(vector): """Point in local coordinate system""" def __init__(self, x=0, y=0, z=0): super().__init__([x, y, z, 1]) - def __str__(self): - return str(self.xyz()) + # TODO + def projection(self): + """Orthographic projection to the xy-plane + """ + # P = matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]) + #return (P*self)[:2] + return self[:2] class CS(matrix): """Coordinate system @@ -36,9 +47,6 @@ class CS(matrix): 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()]) + ']' - @staticmethod def x90(): return CS((1, 0, 0), (0, 0, -1), (0, 1, 0)) @@ -59,7 +67,133 @@ class CS(matrix): """Get coordinates in 3d space""" return self[:3,:3] -class World(): +# 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). + """ + 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 xy(self): + """Get coordinates in 3d space""" + return list(zip(*[i[:2] for i in self.points()])) + + def xyz(self): + """Get coordinates in 3d space""" + return list(zip(*[i[:3] 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 is not suitable because 0 is also false + if sy is None: + 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.cos(i*2*math.pi/n) + y = radius * math.sin(i*2*math.pi/n) + points.append(Point(x, y, 0)) + super().__init__(*points) + +class Solid: + """Solid object in local coordinate system + + This class lists Wireframe objects. + The Wireframe class create its own points (copy). + """ + def __init__(self, *wireframes): + self._wireframes = wireframes + + def wireframes(self): + return self._wireframes + + def translate(self, tx, ty, tz): + self._wireframes = [wireframe.translate(tx, ty, tz) for + wireframe in self._wireframes] + return self + + def scale(self, sx, sy=None, sz=None): + # if not sy is not suitable because 0 is also false + if sy is None: + sy = sx + sz = sx + self._wireframes = [wireframe.scale(sx, sy, sz) for + wireframe in self._wireframes] + return self + + def ch_cs(self, cs): + self._wireframes = [wireframe.ch_cs(cs) for + wireframe in self._wireframes] + return self + +class Hexahedron(Solid): + """Line a open wireframe object in local coordinate system""" + def __init__(self, + point1=Point(-1, -1, -1), point2=Point(1, -1, -1), + point3=Point(1, 1, -1), point4=Point(-1, 1, -1), + point5=Point(-1, -1, 1), point6=Point(1, -1, 1), + point7=Point(1, 1, 1), point8=Point(-1, 1, 1)): + super().__init__( + Polygon(point1, point2, point3, point4), + Polygon(point5, point6, point7, point8), + Polygon(point1, point2, point6, point5), + Polygon(point3, point4, point8, point7) + ) + +class World: """World-space with world-space coordinates """ def __init__(self): @@ -72,7 +206,8 @@ class World(): return iter(self.objects()) def _store_init(self): - """Initialize or reset calculated values, because a new object was added. + """Initialize or reset calculated values, because a new object + was added. """ self._bb = None self._sd = None @@ -106,6 +241,33 @@ class World(): self._cs.scale(sx, sy, sz) return self + def wireframes(self): + result = [] + for i in self.objects(): + if isinstance(i, Wireframe): + result.append(i.points()) + elif isinstance(i, Solid): + [result.append(j.points()) for j in i.wireframes()] + return result + + def wireframes_xy(self): + result = [] + for i in self.objects(): + if isinstance(i, Wireframe): + result.append(i.xy()) + elif isinstance(i, Solid): + [result.append(j.xy()) for j in i.wireframes()] + return result + + def wireframes_xyz(self): + result = [] + for i in self.objects(): + if isinstance(i, Wireframe): + result.append(i.xyz()) + elif isinstance(i, Solid): + [result.append(j.xyz()) for j in i.wireframes()] + return result + def objects(self): return [copy.deepcopy(i).ch_cs(self._cs) for i in self._objects] @@ -124,10 +286,9 @@ class World(): 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 + for i in self.wireframes_xyz(): + xi, yi, zi = map(min, i) + xs, ys, zs = map(max, i) xmin = xi if xi < xmin else xmin ymin = yi if yi < ymin else ymin zmin = zi if zi < zmin else zmin @@ -148,78 +309,8 @@ class World(): 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]]) + self.ch_cs([[1, 0, 0, -(bb[0]+bb[1])/2], + [0, 1, 0, -(bb[2]+bb[3])/2], + [0, 0, 1, -(bb[4]+bb[5])/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). - """ - 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_plot.py b/pylib/geometry2d_plot.py index 7f5aa65..c123e1d 100644 --- a/pylib/geometry2d_plot.py +++ b/pylib/geometry2d_plot.py @@ -11,7 +11,7 @@ .. moduleauthor:: Daniel Weschke """ import pylab -from geometry2d import ( +from .geometry2d import ( distance, angle, line, interpolate_hermite, rotate_xy, translate_xy ) diff --git a/pylib/geometry_plot.py b/pylib/geometry_plot.py new file mode 100644 index 0000000..9b68819 --- /dev/null +++ b/pylib/geometry_plot.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Geometry plotter using matplotlib (pylab). + +:Date: 2019-12-23 + +.. module:: geometry_plot + :platform: *nix, Windows + :synopsis: Geometry plotting. + +.. moduleauthor:: Daniel Weschke +""" + +backend = 'pylab' + +if backend == 'pylab': + from .geometry_plot_pylab import cad_wireframe, wireframe3d diff --git a/pylib/geometry_plot_pylab.py b/pylib/geometry_plot_pylab.py new file mode 100644 index 0000000..9c0f92c --- /dev/null +++ b/pylib/geometry_plot_pylab.py @@ -0,0 +1,243 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Geometry plotter using pylab (matplotlib). + +:Date: 2019-12-23 + +.. module:: geometry_plot_pylab + :platform: *nix, Windows + :synopsis: Geometry plotting (pylab). + +.. moduleauthor:: Daniel Weschke +""" +import math +# This import registers the 3D projection, but is otherwise unused. +from mpl_toolkits.mplot3d import Axes3D +assert Axes3D # silence pyflakes +import pylab +pylab.style.use('dark_background') +pylab.rcParams['text.color'] = 'grey' # lightgrey +pylab.rcParams['axes.edgecolor'] = 'grey' # lightgrey +pylab.rcParams['grid.color'] = 'grey' # lightgrey +pylab.rcParams['xtick.color'] = 'grey' # lightgrey +pylab.rcParams['ytick.color'] = 'grey' # lightgrey +pylab.rcParams['axes3d.grid'] = False +# default for dark_background cycler( +# 'color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', +# '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']) +pylab.rcParams['axes.prop_cycle'] = pylab.cycler( + "color", ['#3498DB', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', + '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']) + +# remove f for fullscreen toggle, default ['f', 'ctrl+f'] +pylab.rcParams['keymap.fullscreen'] = ['ctrl+f'] +# remove L for log/lin toggle, default ['k', 'L'] +pylab.rcParams['keymap.xscale'] = ['k'] +# remove l for log/lin toggle, default ['l'] +pylab.rcParams['keymap.yscale'] = [] + +from pylab import mean +from .geometry import CS + +# type of ax +# - matplotlib.axes._subplots.Axes3DSubplot) +# - matplotlib.axes.Axes +# - pylab.Axes + +def set_aspect_equal(ax): + '''Make axes of 3D plot have equal scale so that spheres appear as + spheres, cubes as cubes, etc.. This is one possible solution to + Matplotlib's ax.set_aspect('equal') and ax.axis('equal') not + working for 3D. + + :param ax: a pylab axis + :type ax: pylab.Axes + + Source: https://stackoverflow.com/a/35126679 + ''' + if ax.name == '3d': + + xlim = ax.get_xlim3d() + ylim = ax.get_ylim3d() + zlim = ax.get_zlim3d() + + xmean = mean(xlim) + ymean = mean(ylim) + zmean = mean(zlim) + + plot_radius = max([abs(lim - mean_) + for lims, mean_ in ((xlim, xmean), + (ylim, ymean), + (zlim, zmean)) + for lim in lims]) + + ax.set_xlim3d([xmean - plot_radius, xmean + plot_radius]) + ax.set_ylim3d([ymean - plot_radius, ymean + plot_radius]) + ax.set_zlim3d([zmean - plot_radius, zmean + plot_radius]) + else: + ax.axis('equal') + +def plot_post(ax): + if isinstance(ax, pylab.Axes): + ax = [ax] + for axi in ax: + if axi.name == '3d': + #axi.w_xaxis.set_pane_color((0, 0, 0, 0)) + #axi.w_yaxis.set_pane_color((0, 0, 0, 0)) + #axi.w_zaxis.set_pane_color((0, 0, 0, 0)) + axi.w_xaxis.pane.fill = False + axi.w_yaxis.pane.fill = False + axi.w_zaxis.pane.fill = False + set_aspect_equal(axi) + +def wireframe3d(world): + fig = pylab.figure() + ax = fig.add_subplot(111, projection='3d') + [ax.plot(*i, 'C0') for i in world.wireframes_xyz()] + plot_post(ax) + +def cad_wireframe(world, centering=True): + """ + Graphical projections + + * Parallel projections + + * Orthographic + + * Multiview + + * \* First-angle + * Third-angle + * Plan Elevation + + * Axonometric + + * \* Isometric + * Dimetric + * Trimetri + + * Oblique + + * Carbinet + * Cavalier + * Military + * Top-down + + * Perspective projections + + * 1-point + * 2-point + * 3-point + * Curvilinear + + """ + if centering: + world.center() + + fig = pylab.figure('geometry-cad') + fig.clf() + ax = fig.add_subplot(111) + + pylab.axis('off') + pylab.subplots_adjust(left=0, right=1, top=1, bottom=0) + + lps = [ax.plot(*i, 'C0')[0] for i in world.wireframes_xy()] + + plot_post(ax) + + def press(event, world, lps): + #print('key pressed:', event.key) + #sys.stdout.flush() + if event.key in [ + 'left', 'right', 'up', 'down', + 'f', 't', 'b', 'l', 'r', 'i', 'd', + 'shift+left', 'shift+right', 'shift+up', 'shift+down', + 'ctrl+up', 'ctrl+down', 'ctrl+left', 'ctrl+right']: + d = world.space_diagonal() + if event.key == 'left': + world.rotate_y(-math.pi/180*10) + elif event.key == 'right': + world.rotate_y(+math.pi/180*10) + elif event.key == 'up': + world.rotate_x(-math.pi/180*10) + elif event.key == 'down': + world.rotate_x(+math.pi/180*10) + elif event.key == 'f': + world.cs(CS()) + if centering: + world.center() + elif event.key == 't': + world.cs(CS.x90()) + if centering: + world.center() + elif event.key == 'b': + world.cs(CS.xm90()) + if centering: + world.center() + elif event.key == 'l': + world.cs(CS.y90()) + if centering: + world.center() + elif event.key == 'r': + world.cs(CS.ym90()) + if centering: + world.center() + elif event.key == 'i': + #theta_y = -math.pi/2/3 + #theta_x = math.pi/2/3 + theta_y = -math.pi/2/2 + theta_x = math.asin(math.tan(math.pi/2/3)) + world.cs(CS().rotate_y(theta_y).rotate_x(theta_x)) + if centering: + world.center() + elif event.key == 'd': + #theta_x = math.asin(math.tan(math.pi/2/3/2)) + theta_y = -math.pi/2/2 + theta_x = math.atan(1/2) + world.cs(CS().rotate_y(theta_y).rotate_x(theta_x)) + if centering: + world.center() + elif event.key == 'shift+left': + world.translate(-0.1*d, 0, 0) + elif event.key == 'shift+right': + world.translate(0.1*d, 0, 0) + elif event.key == 'shift+up': + world.translate(0, 0.1*d, 0) + elif event.key == 'shift+down': + world.translate(0, -0.1*d, 0) + elif event.key == 'ctrl+left': + world.rotate_z(+math.pi/180*10) + elif event.key == 'ctrl+right': + world.rotate_z(-math.pi/180*10) + elif event.key == 'ctrl+up': + world.scale(1.1) + elif event.key == 'ctrl+down': + world.scale(0.9) + for i, j in zip(lps, world.wireframes_xy()): + i.set_data(j) + fig.canvas.draw() + + def onresize(event, w): + r = 2 * w.space_diagonal()/2 + pylab.xlim((-r, r)) + pylab.ylim((-r, r)) + + fig.canvas.mpl_connect('key_press_event', + lambda event: press(event, world, lps)) + fig.canvas.mpl_connect('resize_event', + lambda event: onresize(event, world)) + + pylab.text( + 0+.01, 1-.015, + 'rotate: left, right, up, down, ctrl+left, ctrl+right\n' + + 'pan: shift+left, shift+right, shift+up, shift+down\n' + + 'zoom: ctrl+up, ctrl+down\n' + + 'view: f (front), l (left), r (right), t (top), b (bottom)\n' + + ' i (isometric), d (dimetric)', + horizontalalignment='left', + verticalalignment='top', + transform=fig.transFigure, + bbox=dict(facecolor='black', alpha=0.5), + family='monospace' + ) + pylab.show() diff --git a/pylib/mathematics.py b/pylib/mathematics.py index a2298d3..11d2803 100644 --- a/pylib/mathematics.py +++ b/pylib/mathematics.py @@ -21,64 +21,63 @@ def lcm(a, b): class vector(list): """Use/create vector like lists - * size -> len(a) - * abs -> abs(a) - * dot -> a * b - * outer -> a @ b + * size, length of a vector use len(a) + * absolute, magntude, norm of a vector use abs(a), see + :meth:`__abs__` + * dot product use a * b, see :meth:`__mul__` and :meth:`__rmul__` + * outer product use a @ b, see :meth:`__matmul__` - use super constructor + :__iter__: - use super __iter__ + >>> [i*2 for i in vector([1, 2, 3])] + [2, 4, 6] - use super __setitem__ + :__setitem__: - >>> v = vector([1,2,3,4,5]) - >>> v[3:5] = [1,2] + >>> 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) + :__eq__(a, b): - use super __le__(a, b) + >>> vector([1, 2, 3, 1, 2]) == vector([1, 2, 3, 1, 2]) + True + >>> vector([1, 2, 3, 1, 2]) == vector([1, 2, 3, 2, 1]) + False - use super __eq__(a, b) + :__ne__(a, b): - >>> v = vector([1,2,3,1,2]) - >>> v2 = vector([1,2,3,1,2]) - >>> v == v2 + >>> vector([1, 2, 3, 1, 2]) != vector([1, 2, 3, 1, 2]) + False + >>> vector([1, 2, 3, 1, 2]) != vector([1, 2, 3, 2, 1]) True - use super __ne__(a, b) + :__contains__: - use super __ge__(a, b) - - use super __gt__(a, b) - - use super __contains__ - - >>> 2 in vector([1,2,3]) + >>> 2 in vector([1, 2, 3]) True - __isub__ + :__isub__: - >>> v = vector([1,2,3]) - >>> v -= vector([3,3,3]) + >>> v = vector([1, 2, 3]) + >>> v -= vector([3, 3, 3]) >>> print(v) [-2, -1, 0] - __imul__ + :__imul__: - >>> v = vector([1,2,3]) - >>> v *= vector([3,3,3]) + >>> v = vector([1, 2, 3]) + >>> v *= vector([3, 3, 3]) >>> print(v) 18 - __imatmul__ + :__imatmul__: - >>> m = vector([1,2,3]) - >>> m *= vector([3,3,3]) + >>> m = vector([1, 2, 3]) + >>> m *= vector([3, 3, 3]) >>> print(v) [[3, 3, 3], [6, 6, 6], [9, 9, 9]] """ @@ -101,33 +100,43 @@ class vector(list): return vector(item) if isinstance(item, list) else item def __pos__(self): - """+ a (new object) + """\+ a (new object) + + .. math:: + \mathbf{b} = +\mathbf{a} """ return vector([*self]) def __neg__(self): - """- a (new object) + """\- a (new object) + + .. math:: + \mathbf{b} = -\mathbf{a} """ return vector([-i for i in self]) def __add__(self, other): """a + b (new object) + .. math:: + \mathbf{c} = \mathbf{a} + \mathbf{b} + :Example: - >>> v = vector([1,2,3]) + vector([1,2,3]) + >>> 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)]) + # overwrite because [1, 2] + [5, 8] = [1, 2, 5, 8] def __iadd__(self, other): """a += b (new object) :Example: - >>> v = vector([1,2,3]) - >>> v += vector([3,3,3]) + >>> v = vector([1, 2, 3]) + >>> v += vector([3, 3, 3]) >>> print(v) [4, 5, 6] """ @@ -136,9 +145,12 @@ class vector(list): def __sub__(self, other): """a - b (new object) + .. math:: + \mathbf{c} = \mathbf{a} - \mathbf{b} + :Example: - >>> v = vector([1,2,3]) - vector([1,2,3]) + >>> v = vector([1, 2, 3]) - vector([1, 2, 3]) >>> print(v) [0, 0, 0] """ @@ -146,9 +158,7 @@ class vector(list): def __mul__(self, other): r"""Scalar multiplication, dot product (inner product) or - vector-matrix multiplication. - - a * b (new object) + vector-matrix multiplication. (new object) :type other: scalar, vector (or 1d list), matrix (or 2d list) @@ -158,18 +168,18 @@ class vector(list): \mathbf{c} &= \mathbf{a} \cdot \mathbf{B} .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). + 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 + >>> v = vector([1, 2, 3, 4, 5]) * 3 >>> print(v) [3, 6, 9, 12, 15] - >>> v = vector([1,2,3,4,5])*3. + >>> 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]) + >>> s = vector([1, 2, 3]) * vector([1, 2, 3]) >>> print(s) 14 @@ -180,15 +190,14 @@ class vector(list): 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)]) + 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) + matrix-vector multiplication. (new object) :type other: scalar (or 1d list and 2d list) @@ -198,24 +207,24 @@ class vector(list): \mathbf{c} &= \mathbf{A} \cdot \mathbf{b} .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). + 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]) + >>> v = 3 * vector([1, 2, 3, 4, 5]) >>> print(v) [3, 6, 9, 12, 15] - >>> v = 3.*vector([1,2,3,4,5]) + >>> 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 + :meth:`__mul__` and :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]) + return vector([sum(c*d for c, d in zip(a_row, self)) for + a_row in other]) except: # scalar * vector return self*other @@ -223,7 +232,7 @@ class vector(list): r"""Outer product a @ b (new object) .. math:: - \vec{a} \otimes \vec{b} + \mathbf{c} = \mathbf{a} \otimes \mathbf{b} = \begin{pmatrix} a_{1}\\ @@ -246,7 +255,7 @@ class vector(list): :Example: - >>> m = vector([1,2,3]) @ vector([1,2,4]) + >>> m = vector([1, 2, 3]) @ vector([1, 2, 4]) >>> print(m) [[1, 2, 4], [2, 4, 8], [3, 6, 12]] """ @@ -259,17 +268,80 @@ class vector(list): r"""Magnitude / norm of a vector .. math:: - b = \sqrt{\sum a_i^2} + b = |\mathbf{a}| = \sqrt{\sum a_i^2} = + \sqrt{\mathbf{a} \cdot \mathbf{a}} :Example: - >>> norm([3, 4]) - 5 - >>> norm(vector([3, 4])) - 5 + >>> v = vector([3, 4]) + >>> abs(v) + 5.0 """ return math.sqrt(self * self) + def __lt__(self, other): + """Test if this object is lower (smaller) than the other object. + + .. math:: + |\mathbf{a}| \lt |\mathbf{b}| + + :Example: + + >>> vector([3, 2, 1]) < vector([1, 2, 3]) + False + >>> vector([3, 2, 1]) < vector([1, 2, 4]) + True + """ + return abs(self) < abs(other) + + def __le__(self, other): + """Test if this object is lower (smaller) than or equal the + other object. + + .. math:: + |\mathbf{a}| \le |\mathbf{b}| + + :Example: + + >>> vector([3, 2, 1]) <= vector([1, 2, 3]) + True + >>> vector([3, 2, 1]) <= vector([1, 2, 2]) + False + """ + return abs(self) <= abs(other) + + def __gt__(self, other): + """Test if this object is greater (larger) than the other + object. + + .. math:: + |\mathbf{a}| \gt |\mathbf{b}| + + :Example: + + >>> vector([1, 2, 3]) > vector([3, 2, 1]) + False + >>> vector([1, 2, 3]) > vector([2, 2, 1]) + True + """ + return abs(self) > abs(other) + + def __ge__(self, other): + """Test if this object is greater (larger) than or equal the + other object. + + .. math:: + |\mathbf{a}| \ge |\mathbf{b}| + + :Example: + + >>> vector([1, 2, 3]) >= vector([3, 2, 1]) + True + >>> vector([1, 2, 3]) >= vector([4, 2, 1]) + False + """ + return abs(self) >= abs(other) + def __str__(self): return str([*self]) @@ -328,8 +400,8 @@ class vector(list): @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. + """Returns a random vector of length n or matrix of size m rows, + n columns filled with random numbers. :Example: @@ -351,10 +423,10 @@ class vector(list): :type a: vector .. math:: - \vec{e}_a = \frac{\vec{a}}{|\vec{a}|} + \mathbf{\hat{a}} = \frac{\mathbf{a}}{|\mathbf{a}|} .. seealso:: - :meth:`norm` for a norm (magnitude) of a vector + :meth:`__abs__` for a norm (magnitude) of a vector """ a_mag = abs(a) return vector([i/a_mag for i in a]) @@ -415,15 +487,12 @@ class vector(list): The direction of c can be found with the right-hand rule. .. math:: - \vec{c} = \vec{a} \times \vec{b} + \mathbf{c} = \mathbf{a} \times \mathbf{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]] - def xyz(self): - return self[:3] - def rotate_x(self, theta): r"""Rotation about the x dirction. @@ -493,10 +562,10 @@ class vector(list): 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. + 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} = @@ -508,16 +577,17 @@ class vector(list): \end{bmatrix} \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix} """ - if not sy: + # if not sy is not suitable because 0 is also false + if sy is None: sy = sx sz = sx self[:] = matrix.s(sx, sy, sz) * self return self 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). + 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} = @@ -542,21 +612,23 @@ class matrix(list): :Example: - >>> m = matrix([[1, 2, 3, 0], [4, 5, 6, 0], [7, 8, 9, 0], [0, 0, 0, 0]]) + >>> 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]) + >>> print(m[:, 1:3]) [[2, 3], [5, 6], [8, 9], [0, 0]] - >>> print(m[0:2,1:3]) + >>> print(m[0:2, 1:3]) [[2, 3], [5, 6]] - >>> print(m[::2,::2]) + >>> 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)) + # for 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])] + 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 @@ -568,7 +640,7 @@ class matrix(list): Rotates the coordinate system of vectors .. math:: - R_{x}(\theta) = + \mathbf{R}_{x}(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta & 0 \\ @@ -591,7 +663,7 @@ class matrix(list): Rotates the coordinate system of vectors .. math:: - R_{y}(\theta) = + \mathbf{R}_{y}(\theta) = \begin{bmatrix} \cos \theta & 0 & \sin \theta & 0 \\ 0 & 1 & 0 & 0 \\ @@ -614,7 +686,7 @@ class matrix(list): Rotates the coordinate system of vectors .. math:: - R_{z}(\theta) = + \mathbf{R}_{z}(\theta) = \begin{bmatrix} \cos \theta & -\sin \theta & 0 & 0 \\ \sin \theta & \cos \theta & 0 & 0 \\ @@ -625,14 +697,17 @@ class matrix(list): :Example: .. math:: - R_{z}(\theta) \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = + \mathbf{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}1 \\ 0 \\ 0 \\ 1\end{bmatrix} \\ + &= \begin{bmatrix} 0 & -1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ @@ -655,7 +730,7 @@ class matrix(list): r"""Translation matrix .. math:: - T = + \mathbf{T} = \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ @@ -675,13 +750,13 @@ class matrix(list): 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. + 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 = + \mathbf{S} = \begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ @@ -689,7 +764,8 @@ class matrix(list): 0 & 0 & 0 & 1 \end{bmatrix} """ - if not sy: + # if not sy is not suitable because 0 is also false + if sy is None: sy = sx sz = sx T = matrix([[sx, 0, 0, 0], @@ -700,9 +776,7 @@ class matrix(list): def __mul__(self, other): r"""Scalar multiplication, dot product (inner product) or - matrix-vector multiplication. - - a * b (new object) + matrix-vector multiplication. (new object) :type other: scalar, vector (or 1d list), matrix (or 2d list) @@ -712,21 +786,25 @@ class matrix(list): \mathbf{C} &= \mathbf{A} \cdot \mathbf{B} .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). + 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 + >>> 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. + >>> 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]) + >>> 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]]) + >>> 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]] @@ -734,18 +812,18 @@ class matrix(list): :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]) + 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]) + 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) + vector-matrix multiplication. (new object) :type other: scalar (or 1d list and 2d list) @@ -755,27 +833,30 @@ class matrix(list): \mathbf{C} &= \mathbf{A} \cdot \mathbf{B} .. note:: - No size checking will be conducted, therefore no exceptions for - wrong usage (result will be nonsense). + 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 + >>> m = 5 * matrix([[1, 2, 3, 4], [5, 6, 7, 8], \ + [9, 10, 11, 12], [0, 0, 0, 1]]) >>> 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]]) + >>> 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 + :meth:`__mul__` and :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]) + 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)]) + 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 @@ -894,10 +975,10 @@ class matrix(list): 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. + 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} @@ -919,7 +1000,8 @@ class matrix(list): 0 & 0 & 0 & h \end{bmatrix} """ - if not sy: + # if not sy is not suitable because 0 is also false + if sy is None: sy = sx sz = sx self[:] = matrix.s(sx, sy, sz) * self diff --git a/tests/test_data.py b/tests/test_data.py index 428fa0e..5437b01 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -12,8 +12,8 @@ import unittest import os import sys -sys.path.insert(0, os.path.abspath('../pylib')) -from data import read, unique_ending, get_id, seq +sys.path.insert(0, os.path.abspath('..')) +from pylib.data import read, unique_ending, get_id, seq class TestData(unittest.TestCase): diff --git a/tests/test_fit.py b/tests/test_fit.py index ee509f9..a2323e2 100644 --- a/tests/test_fit.py +++ b/tests/test_fit.py @@ -13,9 +13,9 @@ import unittest import os import sys from pylab import array, argmax, subplot, plot, title, xlim, show, gradient, linspace -sys.path.insert(0, os.path.abspath('../pylib')) -from data import data_read -from numerical.fit import gauss_fit +sys.path.insert(0, os.path.abspath('..')) +from pylib.data import read +from pylib.numerical.fit import gauss_fit class TestFit(unittest.TestCase): @@ -23,7 +23,7 @@ class TestFit(unittest.TestCase): def test_gauss(self): """test function""" file_name = "test_fit.dat" - x, y = data_read(file_name, 3, 2) + x, y = read(file_name, 3, 2) subplot(2, 2, 1) plot(x, y, '.-') diff --git a/tests/test_geometry.py b/tests/test_geometry.py index df9cf09..61fc966 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -13,69 +13,85 @@ import unittest import os import sys import math -sys.path.insert(0, os.path.abspath('../pylib')) -from mathematics import vector -from geometry import Direction, Point, CS, Wireframe, Polygon +sys.path.insert(0, os.path.abspath('..')) +from pylib.geometry import Direction, Point, CS, Wireframe, Line, Polygon, Circle class TestGeometry(unittest.TestCase): def test_Direction(self): p = Direction() self.assertIsInstance( - p, list) + p, + list) self.assertEqual( - p, [1, 0, 0, 0]) + p, + [1, 0, 0, 0]) self.assertEqual( - Direction(2, 3, 4), [2, 3, 4, 0]) + Direction(2, 3, 4), + [2, 3, 4, 0]) - self.assertIsInstance( - p, vector) + def test_Direction_getitem(self): self.assertEqual( - p, vector([1, 0, 0, 0])) + Direction()[:3], + [1, 0, 0]) self.assertEqual( - Direction(2, 3, 4), vector([2, 3, 4, 0])) - - def test_Direction_xyz(self): - self.assertEqual( - Direction().xyz(), [1, 0, 0]) - self.assertEqual( - Direction(1, -1, 1).xyz(), [1, -1, 1]) + Direction(1, -1, 1)[:3], + [1, -1, 1]) def test_Point(self): p = Point() self.assertIsInstance( - p, list) + p, + list) self.assertEqual( - p, [0, 0, 0, 1]) + p, + [0, 0, 0, 1]) self.assertEqual( - Point(2, 3, 4), [2, 3, 4, 1]) + Point(2, 3, 4), + [2, 3, 4, 1]) - self.assertIsInstance( - p, vector) + def test_Point_getitem(self): self.assertEqual( - p, vector([0, 0, 0, 1])) + Point()[:3], + [0, 0, 0]) self.assertEqual( - Point(2, 3, 4), vector([2, 3, 4, 1])) + Point(1, -1, 1)[:3], + [1, -1, 1]) - def test_Point_xyz(self): + def test_Point_rotate(self): + [self.assertAlmostEqual(i, j) for i, j in + zip(Point(1, 1, 1).rotate_x(math.pi/4), [1, 0, 1.414213562373095, 1])] + + def test_CS(self): self.assertEqual( - Point().xyz(), [0, 0, 0]) - self.assertEqual( - Point(1, -1, 1).xyz(), [1, -1, 1]) + CS(), + [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) + + def test_CS_rotate(self): + [self.assertAlmostEqual(k, l) for i, j in + zip(CS().rotate_y(-math.pi/2), + [[0, 0.0, -1.0, 0.0], [0, 1, 0, 0], [1.0, 0.0, 0, 0.0], [0, 0, 0, 1]]) + for k, l in zip(i, j)] def test_Wireframe(self): self.assertEqual( - Wireframe().points(), []) + Wireframe().points(), + []) # 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(), [[]]) + Wireframe([]).points(), + [[]]) self.assertEqual( - Wireframe(Point()).points(), [[0, 0, 0, 1]]) + Wireframe(Point()).points(), + [[0, 0, 0, 1]]) + + def test_Line(self): self.assertEqual( - Wireframe(Point()).points(), [vector([0, 0, 0, 1])]) + Line().points(), + [[-1, 0, 0, 1], [1, 0, 0, 1]]) def test_Polygon(self): p0 = Point() @@ -87,6 +103,14 @@ class TestGeometry(unittest.TestCase): pg.points(), [[0, 0, 0, 1], [1, 0 , 0, 1], [1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 0, 1]]) + def test_Polygon_rotate(self): + pg = Polygon(Point(1, 1, 1)).rotate_x(math.pi/4) + [self.assertAlmostEqual(i, j) for i, j in + zip(pg.points()[0], [1, 0, 1.414213562373095, 1])] + [self.assertAlmostEqual(k, l) for i, j in + zip(pg.xyz(), ((1, 1), (0, 0), (1.414213562373095, 1.414213562373095))) + for k, l in zip(i, j)] + def test_Polygon_ch_cs(self): # example object to rotate p0 = Point() @@ -103,5 +127,23 @@ class TestGeometry(unittest.TestCase): pg.ch_cs(cs) [self.assertAlmostEqual(i, j) for i, j in zip(pg.points(), test)] + def test_Circle(self): + cs = Circle(n=4).points() + test = [[1, 0, 0, 1], [0, 1, 0, 1], [-1, 0, 0, 1], [0, -1, 0 ,1], [1, 0, 0, 1]] + [self.assertAlmostEqual(i, j) for i, j in zip(cs, test)] + + cs = Circle().points() + test = [[1.0, 0.0, 0, 1], + [0.8090169943749475, 0.5877852522924731, 0, 1], + [0.30901699437494745, 0.9510565162951535, 0, 1], + [-0.30901699437494734, 0.9510565162951536, 0, 1], + [-0.8090169943749473, 0.5877852522924732, 0, 1], + [-1.0, 1.2246467991473532e-16, 0, 1], + [-0.8090169943749476, -0.587785252292473, 0, 1], + [-0.30901699437494756, -0.9510565162951535, 0, 1], + [0.30901699437494723, -0.9510565162951536, 0, 1], + [0.8090169943749473, -0.5877852522924734, 0, 1]] + [self.assertAlmostEqual(k, l) for i, j in zip(cs, test) for k, l in zip(i, j) ] + if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/tests/test_geometry2d.py b/tests/test_geometry2d.py index 444c289..cbd3f30 100644 --- a/tests/test_geometry2d.py +++ b/tests/test_geometry2d.py @@ -14,10 +14,10 @@ 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 +sys.path.insert(0, os.path.abspath('..')) +from pylib.data import fold_list +from pylib.geometry2d import translate_xy, rotate_xy, interpolate_hermite, lines, cubics +from pylib.geometry2d_plot import plot_lines, plot_cubic_lines class TestGeometry2d(unittest.TestCase): diff --git a/tests/test_mathematics.py b/tests/test_mathematics.py index 3769a3c..9a43e55 100644 --- a/tests/test_mathematics.py +++ b/tests/test_mathematics.py @@ -12,10 +12,10 @@ import unittest import os import sys -sys.path.insert(0, os.path.abspath('../pylib')) +sys.path.insert(0, os.path.abspath('..')) import math -from mathematics import vector, matrix +from pylib.mathematics import vector, matrix class TestGeometry(unittest.TestCase): diff --git a/tests/test_ode.py b/tests/test_ode.py index 7b74257..365aa22 100644 --- a/tests/test_ode.py +++ b/tests/test_ode.py @@ -19,10 +19,10 @@ from matplotlib.pyplot import figure, subplots, plot, show import os import sys -sys.path.insert(0, os.path.abspath('../pylib')) -from numerical.ode import (e1, e2, e4, i1, newmark_newtonraphson, - newmark_newtonraphson_rdk) -from numerical.ode_model import disk, disk_nm, disk_nmmdk +sys.path.insert(0, os.path.abspath('..')) +from pylib.numerical.ode import (e1, e2, e4, i1, + newmark_newtonraphson, newmark_newtonraphson_rdk) +from pylib.numerical.ode_model import disk, disk_nm, disk_nmmdk def plotx1rphi(x, t, title): """Plot plane rotation (x, y, phi) diff --git a/tests/test_time_of_day.py b/tests/test_time_of_day.py index f4bc20b..903a9d7 100644 --- a/tests/test_time_of_day.py +++ b/tests/test_time_of_day.py @@ -14,8 +14,8 @@ from time import mktime import os import sys -sys.path.insert(0, os.path.abspath('../pylib')) -from time_of_day import (in_seconds, seconds, seconds_norm, +sys.path.insert(0, os.path.abspath('..')) +from pylib.time_of_day import (in_seconds, seconds, seconds_norm, minutes, minutes_norm, hours, hours_norm, days, days_norm, transform)