pylib package¶
Subpackages¶
Submodules¶
pylib.data module¶
Read and write data to or from file and manipulate data structures.
- Date
2019-10-11
-
fold_list(lst, n)[source]¶ Convert one-dimensional kx1 array (list) to two-dimensional mxn array. m = k / n
- Parameters
lst (list) – list to convert
n (int) – length of the second dimenson
- Returns
two-dimensional array (list of lists)
- Return type
list
-
get_id(ids, uide)[source]¶ Get full id from unique id ending.
- Parameters
ids (list) – ids
uide (str) – unique id ending
- Returns
full id
- Return type
str or int
-
load(file_name, default=None, verbose=False)[source]¶ Load stored program objects from binary file.
- Parameters
file_name (str) – file to load
default (object) – return object if data loading fails
verbose (bool) – verbose information (default = False)
- Returns
loaded data
- Return type
object
-
read(file_name, x_column, y_column, default=None, verbose=False)[source]¶ Read ascii data file.
- Parameters
filename (str) – file to read
x_column (int) – column index for the x data (first column is 0)
y_column (int) – column index for the y data (first column is 0)
default (object) – return object if data loading fails
verbose (bool) – verbose information (default = False)
- Returns
x and y
- Return type
tuple(list, list)
-
seq(start, stop=None, step=1)[source]¶ Create an arithmetic bounded sequence.
The sequence is one of the following;
empty \(\{\}=\emptyset\), if start and stop are the same
degenerate \(\{a\}\), if the sequence has only one element.
left-close and right-open \([a, b)\)
- Parameters
start (int or float) – start of the sequence, the lower bound. If only start is given than it is interpreted as stop and start will be 0.
stop (int or float) – stop of sequence, the upper bound.
step (int or float) – step size, the common difference (constant difference between consecutive terms).
- Returns
arithmetic bounded sequence
- Return type
list
-
store(file_name, object_data)[source]¶ Store program objects to binary file.
- Parameters
file_name (str) – file to store
object_data (object) – data to store
pylib.date module¶
Calculate spacial dates.
- Date
2018-01-15
-
ascension_of_jesus(year)[source]¶ Ascension of Jesus.
- Parameters
year (int) – the year to calculate the ascension of Jesus
- Returns
the day of ascension of Jesus
- Return type
datetime.date
-
easter_friday(year)[source]¶ Easter Friday.
- Parameters
year (int) – the year to calculate the Easter Friday
- Returns
the day of Easter Friday
- Return type
datetime.date
-
easter_monday(year)[source]¶ Easter Monday.
- Parameters
year (int) – the year to calculate the Easter Monday
- Returns
the day of Easter Monday
- Return type
datetime.date
-
easter_sunday(year)[source]¶ Easter Sunday.
- Parameters
year (int) – the year to calculate the Easter Sunday
- Returns
the day of Easter Sunday
- Return type
datetime.date
-
gaußsche_osterformel(year)[source]¶ Gaußsche Osterformel.
- Parameters
year (int) – the year to calculate the Easter Sunday
- Returns
the day of Easter Sunday as a day in march.
- Return type
int
- Variables
X (int) – Das Jahr / year
K(X) (int) – Die Säkularzahl
M(X) (int) – Die säkulare Mondschaltung
S(K) (int) – Die säkulare Sonnenschaltung
A(X) (int) – Den Mondparameter
D(A,M) (int) – Den Keim für den ersten Vollmond im Frühling
R(D,A) (int) – Die kalendarische Korrekturgröße
OG(D,R) (int) – Die Ostergrenze
SZ(X,S) (int) – Den ersten Sonntag im März
OE(OG,SZ) (int) – Die Entfernung des Ostersonntags von der Ostergrenze (Osterentfernung in Tagen)
OS(OG,OE) (int) – Das Datum des Ostersonntags als Märzdatum (32. März = 1. April usw.)
Algorithmus gilt für den Gregorianischen Kalender.
source: https://de.wikipedia.org/wiki/Gau%C3%9Fsche_Osterformel
pylib.drawblock module¶
pylib.function module¶
Mathematical equations.
- Date
2019-11-15
-
cosine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False)[source]¶ A cosine wave is said to be sinusoidal, because, \(\cos(x) = \sin(x + \pi/2)\), which is also a sine wave with a phase-shift of π/2 radians. Because of this head start, it is often said that the cosine function leads the sine function or the sine lags the cosine.
- Parameters
A (float or int) – amplitude
k (float or int) – (angular) wave number
f (float or int) – ordinary frequency
phi (float or int) – phase
D (float or int) – non-zero center amplitude
degree (bool) – boolean to switch between radians and degree. If False phi is interpreted in radians and if True then phi is interpreted in degrees.
- Results
sine wave function of spatial variable x and optional time t
See also
-
epitrochoid(R, r, d)[source]¶ Epitrochoid
A point is attached with a distance d from the center of a circle of radius r. The circle is rolling around the outside of a fixed circle of radius R.
- Parameters
R (float) – radius of the fixed interior circle
r – radius of the rolling circle outside of the fixed circle
d (float) – distance from the center of the exterior circle
- Typre r
float
- Results
functions for x of theta and y of theta
- Return type
tuple
\[\begin{split}x(\theta) = (R + r)\cos\theta - d\cos\left(\frac{R+r}{r}\theta\right) \\ y(\theta) = (R + r)\sin\theta - d\sin\left(\frac{R+r}{r}\theta\right) \\ \theta = \left[0, 2\pi\right]\end{split}\]* * * * R * * * * * * * * * * r * * ** .... * * ** d * * * * * * * * * * * * * * * *
>>> x, y = epitrochoid(3, 1, 0.5)[:1] >>> x, y, theta_end = epitrochoid(3, 1, 0.5)
-
hypotrochoid(R, r, d)[source]¶ Hypotrochoid
A point is attached with a distance d from the center of a circle of radius r. The circle is rolling around the inside of a fixed circle of radius R.
- Parameters
R (float) – radius of the fixed exterior circle
r – radius of the rolling circle inside of the fixed circle
d (float) – distance from the center of the interior circle
- Typre r
float
- Results
functions for x of theta and y of theta
- Return type
tuple
\[\begin{split}x(\theta) = (R - r)\cos\theta + d\cos\left(\frac{R-r}{r}\theta\right) \\ y(\theta) = (R - r)\sin\theta - d\sin\left(\frac{R-r}{r}\theta\right) \\ \theta = \left[0, 2\pi\frac{\mathrm{lcm}(r, R)}{R}\right]\end{split}\]* * * * R * * * * * * * * * r ** * * .... * * * d * * * ** * * * * * * * * * * *
>>> x, y = hyotrochoid(20, 6, 6)[:1] >>> x, y, theta_end = hyotrochoid(20, 6, 6)
See also
-
sine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False)[source]¶ A sine wave or sinusoid is a mathematical curve that describes a smooth periodic oscillation.
- Parameters
A (float or int) – amplitude
k (float or int) – (angular) wave number
f (float or int) – ordinary frequency
phi (float or int) – phase
D (float or int) – non-zero center amplitude
degree (bool) – boolean to switch between radians and degree. If False phi is interpreted in radians and if True then phi is interpreted in degrees.
- Results
sine wave function of spatial variable x and optional time t
In general, the function is:
\[\begin{split}y(x,t) = A\sin(kx + 2\pi f t + \varphi) + D \\ y(x,t) = A\sin(kx + \omega t + \varphi) + D\end{split}\]where:
A, amplitude, the peak deviation of the function from zero.
f, ordinary frequency, the number of oscillations (cycles) that occur each second of time.
ω = 2πf, angular frequency, the rate of change of the function argument in units of radians per second. If ω < 0 the wave is moving to the right, if ω > 0 the wave is moving to the left.
φ, phase, specifies (in radians) where in its cycle the oscillation is at t = 0.
x, spatial variable that represents the position on the dimension on which the wave propagates.
k, characteristic parameter called wave number (or angular wave number), which represents the proportionality between the angular frequency ω and the linear speed (speed of propagation) ν.
D, non-zero center amplitude.
The wavenumber is related to the angular frequency by:
\[k={\omega \over v}={2\pi f \over v}={2\pi \over \lambda }\]where λ (lambda) is the wavelength, f is the frequency, and v is the linear speed.
See also
-
to_str(f, x=None, x_0=0, x_1=1, t=None, h=10, w=80, density=1, char_set='line')[source]¶ Represent functions as string frame with a specific character set. which are normed to the range of [0, 1] to
- Parameters
f (function or list) – function or list of functions normed to the range of [0, 1]
h (int) – number of chars in vertical direction
w (int) – number of chars in horizontal direction
char_set (str) – either “braille” or “block”. “braille” uses Unicode Characters in the Braille Patterns Block (fisrt index U+2800, last index U+28FF [CUDB]) and the “block” uses part of the Unicode Characters in the Block Elements Block (fisrt index U+2580, last index U+259F [CUDB]). Alias for braille is line and alias for block is histogram
- Usage:
case dependent arguments
1 quasi line plot (braille characters) f = lambda function (lambda x, t=0: …) x_1 = max x value x_0 = min x value t = time (animation)
2 histogram (block characters) f = lambda function (lambda x, t=0: …) x_1 = max x value x_0 = min x value t = time (animation) chart=”histogram”
general arguments w = window width in number of chars density = number of data point per pixel (for line chart higher density makes thicker lines) chart = either “line” or “histogram”
Braille Patterns Block
Dots or pixels per character in vertical direction: 6
Dots or pixels per character in horizontal direction: 2
First dot (bottom left) is the zero (0) position of the function. So, a function value of zero does not mean to have zero dots but one. Example of 3 columns and 3 rows (upside down view of ‘normal’ braille/drawille position)
| ^ y axis | | | ,_____,,_____,,_____, 7 + | * *|| * *|| * *| 6 + | * *|| * *|| * *| 5 + | * *|| * *|| * *| 4 + | * *|| * *|| * *| | ;=====;;=====;;=====; 3 + | * *|| * *|| * *| 2 + | * *|| * *|| * *| 1 + | * *|| * *|| * *| 0 + - | * *|| * *|| * *| ---> x axis | ;=====;;=====;;=====; -1 + | * *|| * *|| * *| -2 + | * *|| * *|| * *| -3 + | * *|| * *|| * *| -4 + | * *|| * *|| * *| | ````````````````````` | | `-----+--+---+--+---+--+------------- -2 -1 0 1 2 3Block Elements Block
Dots or pixels per character in vertical direction: 8
Dots or pixels per character in horizontal direction: 1
Example of 3 columns and 3 rows
| ^ y axis | | | ,_____,,_____,,_____, 15 + | --- || --- || --- | 14 + | --- || --- || --- | 13 + | --- || --- || --- | 12 + | --- || --- || --- | 11 + | --- || --- || --- | 10 + | --- || --- || --- | 9 + | --- || --- || --- | 8 + | --- || --- || --- | | ;=====;;=====;;=====; 7 + | --- || --- || --- | 6 + | --- || --- || --- | 5 + | --- || --- || --- | 4 + | --- || --- || --- | 3 + | --- || --- || --- | 2 + | --- || --- || --- | 1 + | --- || --- || --- | 0 + - | --- || --- || --- | ---> x axis | ;=====;;=====;;=====; -1 + | --- || --- || --- | -2 + | --- || --- || --- | -3 + | --- || --- || --- | -4 + | --- || --- || --- | -5 + | --- || --- || --- | -6 + | --- || --- || --- | -7 + | --- || --- || --- | -8 + | --- || --- || --- | | ````````````````````` | | `------+------+------+--------------- -1 0 1References
See also
-
transformation(f, scale_vertical=1, scale_horizontal=1, shift_horizontal=0, shift_vertical=0)[source]¶ Transform functions.
- Parameters
f (function or list) – function or list of functions
scale_vertical – “a” scale factor in vertical direction (default = 1)
scale_horizontal – “b” scale factor in horizontal direction (default = 1)
shift_horizontal – “c” shift factor in horizontal direction (default = 0)
shift_vertical – “d” shift factor in vertical direction (default = 0)
- Returns
transformed function or list of transformed functions
- Return type
function or list
\[y = a \, f(b\,(x-c)) + d\]
pylib.geometry module¶
2D geometry objects.
- Date
2019-08-28
-
angle(point1, point2=None)[source]¶ Angle of point or between two points.
- Parameters
point1 (tuple) – (first) point
point2 (tuple) – second point (default = None)
- Returns
angle of point or between two points
- Return type
float
-
cubic(point1, angle1, point2, angle2, samples=10)[source]¶ Cubic line defined by two end points and the rotation in radians at the points.
- Parameters
point1 (tuple) – one end point
angle1 (int or float) – the slope at the one end point
point2 (tuple) – other end point
angle2 (int or float) – the slope at the other end point
samples (int) – number of sampling points (default = 10)
- Returns
([sample_point1_x, sample_point2_x, …], [sample_points1_y, sample_point2_y, …])
- Return type
tuple
-
cubic_deg(point1, angle1, point2, angle2)[source]¶ Cubic line defined by two end points and the roation in degree at the points.
- Parameters
point1 (tuple) – one end point
angle1 (int or float) – the slope at the one end point
point2 (tuple) – other end point
angle2 (int or float) – the slope at the other end point
- Returns
([sample_point1_x, sample_point2_x, …], [sample_points1_y, sample_point2_y, …])
- Return type
tuple
See also
-
cubics(pts, **kwargs)[source]¶ Cubic lines defined by a list of two end points. The deformation as displacement and rotation (radians) is defined element wise as keyword argument deformation or global node wise as global_deformation. The global coordinate system is xy. x in the right direction and y in the top direction.
- Parameters
pts – list of points in absolute global coordinate system. If keyword inc is given than the inc decides what the left and the right end point of the line is, otherwise it is assumed that the points build a solid line, that is lines between the given points in given order.
**kwargs –
options:
deformation – list of deformation element wise. Additional deformation (translation and rotation in radians) at element left and right node.
rotation_plane – rotation plane of the element wise deformation defined by a string; either ‘xy’ or ‘xz’ (default = ‘xy’). x in the right direction and y in the top direction or z in the bottom direction.
global_deformation – list of deformation global node wise. Additional deformation (horizontal translation, vertical translation and rotation in radians) at node.
factor – factor of the derformation (default = 1).
inc – the incidence table, a list of 2 element lists. The inc decides what the left and the right end point of the line is.
index_offset – starting index of lists (default = 0).
- Returns
list of endpoints for each line; [(((point1_x, point1_y) angle1), ((point2_x, point2_y), angle2), (p1, angle1, p2, angle2), …]
- Return type
list
-
distance(point1, point2)[source]¶ Distance between two points (or length of a straight line).
- Parameters
point1 (tuple) – first point (first end point of straight line)
point2 (tuple) – second point (second end point of straight line)
- Returns
distance between the two points
- Return type
float
-
interpolate_hermite(lvd, lr, rvd, rr, lhd=0, rhd=0, scale_x=1, scale_y=1, samples=10)[source]¶ Interpolate cubic line with hermite boundary conditions.
- Parameters
lvd (int or float) – left vertcal deflection
lr (int or float) – left rotation
rvd (int or float) – right vertical deflection
rr (int or float) – right rotation
lhd (int or float) – left horizontal deformation (default = 0)
rhd (int or float) – right horizontal deformation (default = 0)
scale_x (int or float) – length of element (default = 1)
scale_y (int or float) – factor of the deformation (default = 1). This does not change the length.
samples (int) – number of sampling points (default = 10)
\[\begin{split}s = \frac{x - x_1}{L} \\ x = s\,L + x_1\end{split}\]
-
line(point1, point2, samples=2)[source]¶ Line defined by two end points.
\[y = \frac{y_2-y_1}{x_2-x_1}(x-x_1) + y_1\]- Parameters
point1 (tuple) – one end point
point2 (tuple) – other end point
samples (int) – number of sampling points (default = 2)
- Returns
((point1_x, point2_x), (points1_y, point2_y)) or ([sample_point1_x, sample_point2_x, …], [sample_points1_y, sample_point2_y, …])
- Return type
tuple
- Example
>>> x, y = line((0, 0), (1, 0)) >>> print(x, y) ((0, 1), (0, 0))
-
lines(pts, **kwargs)[source]¶ Lines defined by a list of end points.
- Parameters
pts (list) – list of points in absolute global coordinate system. If keyword inc is given than the inc decides what the left and the right end point of the line is, otherwise it is assumed that the points build a solid line, that is lines between the given points in given order.
**kwargs –
options:
deformation – list of points. Additional deformation (translation) at point.
factor – factor of the deformation (default = 1).
inc – the incidence table, a list of 2 element lists. The inc decides what the left and the right end point of the line is.
index_offset – starting index of lists (default = 0).
- Returns
list of endpoints for each line; [((point1_x, point1_y), (point2_x, point2_y)), (p1, p2), …]
- Return type
list
See also
plot_lines()of thegeometry_plotmodule to plot the lines
-
rectangle(width, height)[source]¶ - Parameters
width (int or float) – the width of the rectangle
height (int or float) – the height of the rectangle
- Returns
(point1, point2, point3, point4)
- Return type
tuple
-
rotate(origin, angle, *pts, **kwargs)[source]¶ Rotate a point or polygon counterclockwise by a given angle around a given origin. The angle should be given in radians.
- Parameters
origin (tuple) – the center of rotation
angle (int or float) – the rotation angle
*pts – points to rotate
**kwargs – options
- Returns
(point_x, point_y) or (point1, point2, …)
- Return type
tuple
See also
-
rotate_deg(origin, angle, *pts, **kwargs)[source]¶ Rotate a point or polygon counterclockwise by a given angle around a given origin. The angle should be given in degrees.
- Parameters
origin (tuple) – the center of rotation
angle (int or float) – the rotation angle
*pts – points to rotate
**kwargs – options
- Returns
(point_x, point_y) or (point1, point2, …)
- Return type
tuple
See also
-
rotate_xy(origin, angle, x, y, **kwargs)[source]¶ Rotate x and y coordinates counterclockwise by a given angle around a given origin. The angle should be given in radians.
- Parameters
origin (tuple) – the center of rotation
angle (int or float) – the rotation angle
x (int or float or list) – x coordinates
y (int or float or list) – y coordinates
**kwargs – options
See also
-
square(width)[source]¶ - Parameters
width (int or float) – the edge size of the square
- Returns
(point1, point2, point3, point4)
- Return type
tuple
See also
-
translate(vec, *pts)[source]¶ Translate a point or polygon by a given vector.
- Parameters
vec (tuple) – translation vector
*pts – points to translate
- Returns
(point_x, point_y) or (point1, point2, …)
- Return type
tuple
See also
pylib.mathematics module¶
Mathematical functions and objects.
- Date
2019-12-12
-
class
matrix[source]¶ Bases:
listUse/create matrix like list of lists
-
rotate_x(theta)[source]¶ Rotation about the x dirction.
\[\begin{split}\begin{bmatrix} xx & xy & xz & t_x \\ yx' & yy' & yz' & t_y' \\ zx' & zy' & zz' & t_z' \\ 0 & 0 & 0 & h \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta & 0 \\ 0 & \sin \theta & \cos \theta & 0 \\ 0 & 0 & 0 & h \end{bmatrix} \begin{bmatrix} xx & xy & xz & t_x \\ yx & yy & yz & t_y \\ zx & zy & zz & t_z \\ 0 & 0 & 0 & h \end{bmatrix}\end{split}\]
-
rotate_y(theta)[source]¶ Rotation about the y dirction.
\[\begin{split}\begin{bmatrix} xx' & xy' & xz' & t_x' \\ yx & yy & yz & t_y \\ zx' & zy' & zz' & t_z' \\ 0 & 0 & 0 & h \end{bmatrix} = \begin{bmatrix} \cos \theta & 0 & \sin \theta & 0 \\ 0 & 1 & 0 & 0 \\ -\sin \theta & 0 & \cos \theta & 0 \\ 0 & 0 & 0 & h \end{bmatrix} \begin{bmatrix} xx & xy & xz & t_x \\ yx & yy & yz & t_y \\ zx & zy & zz & t_z \\ 0 & 0 & 0 & h \end{bmatrix}\end{split}\]
-
rotate_z(theta)[source]¶ Rotation about the z dirction.
\[\begin{split}\begin{bmatrix} xx' & xy' & xz' & t_x' \\ yx' & yy' & yz' & t_y' \\ zx & zy & zz & t_z \\ 0 & 0 & 0 & h \end{bmatrix} = \begin{bmatrix} \cos \theta & -\sin \theta & 0 & 0 \\ \sin \theta & \cos \theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} xx & xy & xz & t_x \\ yx & yy & yz & t_y \\ zx & zy & zz & t_z \\ 0 & 0 & 0 & h \end{bmatrix}\end{split}\]
-
static
rx(theta)[source]¶ Rotation matrix about the x direction.
Rotates the coordinate system of vectors
\[\begin{split}R_{x}(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta & 0 \\ 0 & \sin \theta & \cos \theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]
-
static
ry(theta)[source]¶ Rotation matrix about the y direction.
Rotates the coordinate system of vectors
\[\begin{split}R_{y}(\theta) = \begin{bmatrix} \cos \theta & 0 & \sin \theta & 0 \\ 0 & 1 & 0 & 0 \\ -\sin \theta & 0 & \cos \theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]
-
static
rz(theta)[source]¶ Rotation matrix about the z direction.
Rotates the coordinate system of vectors
\[\begin{split}R_{z}(\theta) = \begin{bmatrix} \cos \theta & -\sin \theta & 0 & 0 \\ \sin \theta & \cos \theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]- Example
\[\begin{split}R_{z}(\theta) \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = \begin{bmatrix} \cos 90° & -\sin 90° & 0 & 0 \\ \sin 90° & \cos 90° & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = \begin{bmatrix} 0 & -1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}1 \\ 0 \\ 0 \\ 1\end{bmatrix} = \begin{bmatrix}0 \\ 1 \\ 0 \\ 1\end{bmatrix}\end{split}\]
-
static
s(sx, sy=None, sz=None)[source]¶ 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.
\[\begin{split}S = \begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]
-
scale(sx, sy=None, sz=None)[source]¶ Scaling
uniform scaling if sx=sy=sz=s. Note that scaling happens around the origin, so objects not 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' \\ yx' & yy' & yz' & t_y' \\ zx' & zy' & zz' & t_z' \\ 0 & 0 & 0 & h \end{bmatrix} = \begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} xx & xy & xz & t_x \\ yx & yy & yz & t_y \\ zx & zy & zz & t_z \\ 0 & 0 & 0 & h \end{bmatrix}\end{split}\]
-
static
t(tx, ty, tz)[source]¶ Translation matrix
\[\begin{split}T = \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]
-
translate(tx, ty, tz)[source]¶ Translation
\[\begin{split}\begin{bmatrix} xx & xy & xz & t_x' \\ yx & yy & yz & t_y' \\ zx & zy & zz & t_z' \\ 0 & 0 & 0 & h \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} xx & xy & xz & t_x \\ yx & yy & yz & t_y \\ zx & zy & zz & t_z \\ 0 & 0 & 0 & h \end{bmatrix}\end{split}\]
-
-
class
vector[source]¶ Bases:
listUse/create vector like lists
size -> len(a)
abs -> abs(a)
dot -> a * b
outer -> a @ b
use super constructor
use super __iter__
use super __setitem__
>>> v = vector([1,2,3,4,5]) >>> v[3:5] = [1,2] >>> print(v) [1, 2, 3, 1, 2] >>> isinstance(v, vector) True
use super __lt__(a, b)
use super __le__(a, b)
use super __eq__(a, b)
>>> v = vector([1,2,3,1,2]) >>> v2 = vector([1,2,3,1,2]) >>> v == v2 True
use super __ne__(a, b)
use super __ge__(a, b)
use super __gt__(a, b)
use super __contains__
>>> 2 in vector([1,2,3]) True
__isub__
>>> v = vector([1,2,3]) >>> v -= vector([3,3,3]) >>> print(v) [-2, -1, 0]
__imul__
>>> v = vector([1,2,3]) >>> v *= vector([3,3,3]) >>> print(v) 18
__imatmul__
>>> m = vector([1,2,3]) >>> m *= vector([3,3,3]) >>> print(v) [[3, 3, 3], [6, 6, 6], [9, 9, 9]]
-
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).
\[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = \begin{bmatrix} u_x & u_y & u_z & 0 \\ v_x & v_y & v_z & 0 \\ w_x & w_y & w_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix}\end{split}\]
-
static
cross(a, b)[source]¶ Cross product
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}\]
-
static
full(length, fill_value)[source]¶ Returns a vector of length m or matrix of size m rows, n columns filled with v.
- Parameters
length (int) – length of the vector, e. g. 3
fill_value – Fill value
- Type fill_value
scalar
- Example
>>> v = vector.full(3, 7) >>> print(v) [7, 7, 7]
-
static
normalize(a)[source]¶ Normalize a vector (i. e. the vector has a length of 1)
\[\vec{e}_a = \frac{\vec{a}}{|\vec{a}|}\]See also
norm()for a norm (magnitude) of a vector
-
static
ones(length)[source]¶ Returns a vector of length m or matrix of size rows, n columns filled with ones.
- Parameters
length (int) – lhape of the vector, e. g. 3
- Example
>>> v = ones(3) >>> print(v) [1.0, 1.0, 1.0]
-
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.
- Example
>>> v = random(3) >>> print(v) [0.9172905912930438, 0.8908124278322492, 0.5256002790725927] >>> v = random(3, 1, 2) >>> print(v) [1.2563665665080803, 1.9270454509964547, 1.2381672401270487]
-
rotate_x(theta)[source]¶ Rotation about the x dirction.
\[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta & 0 \\ 0 & \sin \theta & \cos \theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix}\end{split}\]
-
rotate_y(theta)[source]¶ Rotation about the y dirction.
\[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = \begin{bmatrix} \cos \theta & 0 & \sin \theta & 0 \\ 0 & 1 & 0 & 0 \\ -\sin \theta & 0 & \cos \theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix}\end{split}\]
-
rotate_z(theta)[source]¶ Rotation about the z dirction.
\[\begin{split}\begin{bmatrix}x' \\ y' \\ z' \\ h'\end{bmatrix} = \begin{bmatrix} \cos \theta & -\sin \theta & 0 & 0 \\ \sin \theta & \cos \theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix}\end{split}\]
-
scale(sx, sy=None, sz=None)[source]¶ Scaling
uniform scaling if sx=sy=sz=s. Note that scaling happens around the origin, so objects not 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} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}x \\ y \\ z \\ h\end{bmatrix}\end{split}\]
pylib.time_of_day module¶
Calculate time.
- Date
2019-06-01
-
days(time)[source]¶ The days of the time (year).
- Parameters
time (float or time.struct_time) – the time in seconds
- Returns
hours, range [0, 365.2425]
- Return type
float
-
days_norm(time)[source]¶ The days normalized to 365.2425 (Gregorian, on average) days.
- Parameters
time (float or time.struct_time) – the time in seconds
- Returns
the normalized days, range [0, 1]
- Return type
float
-
hours(time)[source]¶ The hours of the time.
- Parameters
time (float or time.struct_time) – the time in seconds
- Returns
hours, range [0, 24]
- Return type
float
-
hours_norm(time)[source]¶ The hours normalized to 24 hours.
- Parameters
time (float or time.struct_time) – the time in seconds
- Returns
the normalized hours, range [0, 1]
- Return type
float
-
in_seconds(time)[source]¶ If time is time.struct_time convert to float seconds.
- Parameters
time (float or time.struct_time) – the time in seconds
- Returns
the time in seconds
- Return type
float
-
minutes(time)[source]¶ The minutes of the time.
- Parameters
time (float or time.struct_time) – the time in seconds
- Returns
minutes, range [0, 60]
- Return type
float
-
minutes_norm(time)[source]¶ The minutes normalized to 60 minutes.
- Parameters
time (float or time.struct_time) – the time in seconds
- Returns
the normalized minutes, range [0, 1]
- Return type
float
-
seconds(time)[source]¶ The seconds of the time.
- Parameters
time (float or time.struct_time) – the time in seconds
- Returns
seconds, range [0, 60]
- Return type
float