pymchelper.flair.common.bmath module

pymchelper.flair.common.bmath.Cmp0(x)[source]
class pymchelper.flair.common.bmath.DefaultDict(default=None)[source]

Bases: dict

class pymchelper.flair.common.bmath.Matrix(rows=4, cols=-1, type=0)[source]

Bases: list

Matrix 4x4 used for vector transformations

O = [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]
T()[source]

@return transpose matrix

U = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]
append(col)[source]

Append object to the end of the list.

clone()[source]

Clone matrix

det(eps=1e-15)[source]

determinant of square matrix using Gauss method

determinant(eps=1e-15)

determinant of square matrix using Gauss method

static diagonal(lst)[source]
static eulerRotation(rx, ry, rz)[source]
getEulerRotation()[source]
inv()[source]

Inverse matrix in place

inverse()

Inverse matrix in place

make(X, Y, Z=None, T=None)[source]

Create a transformation matrix from 3 normalized vectors

multNoTranslation(B)[source]

Multiply matrix with a vector ignoring the translation part

static rotX(angle)[source]

m = Matrix.rotX(angle) - Return a rotation matrix around X

static rotY(angle)[source]

m = Matrix.rotY(angle) - Return a rotation matrix arround Y

static rotZ(angle)[source]

m = Matrix.rotZ(angle) - Return a rotation matrix arround Z

rotate(angle, axis)[source]

Add rotation elements to the matrix around one axis Axis X=0, Y=1, Z=2, or an arbitrary one given by vector axis

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

m = Matrix.scale(scale|vector) @return a scaling matrix

trace()[source]

Return trace of matrix (sum of diagonal elements)

static translate(x, y=0.0, z=0.0)[source]

m = Matrix.translate(x,y,z|vector) @return a translation matrix

transpose()

@return transpose matrix

unary()[source]

Unary matrix

writeOctave(filename, name)[source]

Write an octave matrix file

zero()[source]

Zero matrix

class pymchelper.flair.common.bmath.Quaternion(a, b=None, c=None, d=None)[source]

Bases: list

matrix()[source]

return rotation matrix

norm()[source]

normalize quaternion

normalize()

normalize quaternion

vector()[source]

return vector of quaternion

class pymchelper.flair.common.bmath.Vector(x=3, *args)[source]

Bases: list

Vector class

O = [0, 0, 0]
X = [1, 0, 0]
Y = [0, 1, 0]
Z = [0, 0, 1]
arg()[source]

return vector angle

clone()[source]

Clone vector

cosTheta()[source]
cross(v)[source]

Cross product of 2 vectors

direction(zero=1e-15)[source]

return containing the direction if normalized with any of the axis

dot(v)[source]

Dot product of 2 vectors

eq(v, acc=1e-15)[source]

Test for equality with vector v within accuracy

length()[source]

Return length of vector

length2()[source]

Return length squared of vector

norm()[source]

Normalize vector and return length

normalize()

Normalize vector and return length

orthogonal()[source]

return a vector orthogonal to self

perp()[source]
perp2()[source]
phi()[source]
set(x, y, z=None)[source]

Set vector

setPolar(ma, ph, th)[source]
theta()[source]
unit()[source]

return a unit vector

x()[source]
y()[source]
z()[source]
class pymchelper.flair.common.bmath.ZeroDict[source]

Bases: pymchelper.flair.common.bmath.DefaultDict

class pymchelper.flair.common.bmath.ZeroIntDict[source]

Bases: pymchelper.flair.common.bmath.DefaultDict

pymchelper.flair.common.bmath.cubic(a, b, c, d=None, eps=1e-15)[source]
pymchelper.flair.common.bmath.d2s(ang, fmt='')[source]
pymchelper.flair.common.bmath.dms(d, m, s)[source]
pymchelper.flair.common.bmath.eigenvalues(M, eps=1e-15, check=False)[source]

Return eigen values and eigen vectors of a symmetric matrix

pymchelper.flair.common.bmath.fitPlane(xyz)[source]
pymchelper.flair.common.bmath.format_number(number, length=10, useExp=False, useD=False)[source]

Format a number to fit in the minimum space given by length

pymchelper.flair.common.bmath.frange(start, stop, step)[source]

range(start,stop,step) for floating point numbers

pymchelper.flair.common.bmath.gauss(A, B)[source]

Solve A*X = B using the Gauss elimination method

pymchelper.flair.common.bmath.goldenSectionSearch(func, ax, bx, cx, x, d=1, eps=1e-15)[source]
pymchelper.flair.common.bmath.int2roman(num)[source]

Convert an integer to Roman numeral

pymchelper.flair.common.bmath.limit(min_, num, max_)[source]

limit a number within a specific range :param min_: :param num: :param max_: :return:

pymchelper.flair.common.bmath.linear(X, Y)[source]

Solve linear regression y = ax + b @return a,b,r

pymchelper.flair.common.bmath.polar(x, y, deg=False)[source]
Convert from rectangular (x,y) to polar (r,w)
r = sqrt(x^2 + y^2) w = arctan(y/x) = [-pi,pi] = [-180,180]
pymchelper.flair.common.bmath.polyderiv(a)[source]
p’(x) = polyderiv(a)
= b[0] + b[1]x + b[2]x^2 +…+ b[n-2]x^{n-2} + b[n-1]x^{n-1}

where b[i] = (i+1)a[i+1]

pymchelper.flair.common.bmath.polyeval(a, x)[source]
p(x) = polyeval(a, x)
= a[0] + a[1]x + a[2]x^2 +…+ a[n-1]x^{n-1} + a[n]x^n = a[0] + x(a[1] + x(a[2] +…+ x(a[n-1] + a[n]x)…)
pymchelper.flair.common.bmath.polyreduce(a, root)[source]

Given x = r is a root of n’th degree polynomial p(x) = (x-r)q(x), divide p(x) by linear factor (x-r) using the same algorithm as polynomial evaluation. Then, return the (n-1)’th degree quotient q(x) = polyreduce(a, r)

= c[0] + c[1]x + c[2]x^2 +…+ c[n-2]x^{n-2} + c[n-1]x^{n-1}
pymchelper.flair.common.bmath.quadratic(b, c, eps=1e-15)[source]
pymchelper.flair.common.bmath.random3D()[source]
pymchelper.flair.common.bmath.rect(r, w, deg=False)[source]
Convert from polar (r,w) to rectangular (x,y)
x = r cos(w) y = r sin(w)
pymchelper.flair.common.bmath.rndColor(x)[source]
pymchelper.flair.common.bmath.roman2int(roman)[source]

convert a roman string to integer

pymchelper.flair.common.bmath.solveOverDetermined(A, B, W=None)[source]
Solve the overdetermined linear system defined by the matrices A,B
such as A*X = B

Optionally a weight can be specified

pymchelper.flair.common.bmath.xcombinations(items, n)[source]
pymchelper.flair.common.bmath.xpermutations(items)[source]
pymchelper.flair.common.bmath.xselections(items, n)[source]
pymchelper.flair.common.bmath.xuniqueCombinations(items, n)[source]