from vl_sdv import *
Category | Class | |||
Vectors | &vec1d; | &vec2d; | &vec3d; | &vec4d; |
Matrices | &mat1d; | &mat2d; | &mat3d; | &mat4d; |
Transformations | &igl1d; | &igl2d; | &igl3d; | &igl4d; |
Quaternions | &quatd; | |||
Rotations | &rot2d; | &rot3d; |
>>> vec1d();vec2d();vec3d();vec4d(); vec1d(0.0) vec2d(0.0,0.0) vec3d(0.0,0.0,0.0) vec4d(0.0,0.0,0.0,0.0)
>>> vec1d(2);vec2d(2,3);vec3d(2,3,5);vec4d(2,3,5,7); vec1d(2.0) vec2d(2.0,3.0) vec3d(2.0,3.0,5.0) vec4d(2.0,3.0,5.0,7.0)
>>> vec1d([2]);vec2d([2,3]);vec3d([2,3,5]);vec4d([2,3,5,7]); vec1d(2.0) vec2d(2.0,3.0) vec3d(2.0,3.0,5.0) vec4d(2.0,3.0,5.0,7.0)
>>> vec1d((2));vec2d((2,3));vec3d((2,3,5));vec4d((2,3,5,7)); vec1d(2.0) vec2d(2.0,3.0) vec3d(2.0,3.0,5.0) vec4d(2.0,3.0,5.0,7.0)
>>> a = vec1d(2);b = vec2d(2,3);c = vec3d(2,3,5);d = vec4d(2,3,5,7); >>> vec1d(a);vec2d(b);vec3d(c);vec4d(d) vec1d(2.0) vec2d(2.0,3.0) vec3d(2.0,3.0,5.0) vec4d(2.0,3.0,5.0,7.0)
>>> vec(3);vec(3,4);vec(3,4,5);vec(3,4,5,6) vec1d(3.0) vec2d(3.0,4.0) vec3d(3.0,4.0,5.0) vec4d(3.0,4.0,5.0,6.0)
>>> print vec1d(2),vec2d(2,3),vec3d(2,3,5),vec4d(2,3,5,7) [2.0] [2.0,3.0] [2.0,3.0,5.0] [2.0,3.0,5.0,7.0]
>>> print len(vec1d()),len(vec2d()),len(vec3d()),len(vec4d()) 1 2 3 4 >>> a = vec4d(1,2,4,8) >>> a[3] = 10 >>> print a [1.0,2.0,4.0,10]
print [10 * i for i in vec4d(2,3,5,7)] [20.0, 30.0, 50.0, 70.0]
Operator | Return type | Argument type | Semantics |
&op_plus; | Vector | Vector | Identity |
&op_minus; | Vector | Vector | Negative of a vector (reversed direction) |
>>> -vec(3);-vec(3,4);-vec(3,4,5);-vec(3,4,5,6) vec1d(-3.0) vec2d(-3.0,-4.0) vec3d(-3.0,-4.0,-5.0) vec4d(-3.0,-4.0,-5.0,-6.0) >>> +vec(3);+vec(3,4);+vec(3,4,5);+vec(3,4,5,6) vec1d(3.0) vec2d(3.0,4.0) vec3d(3.0,4.0,5.0) vec4d(3.0,4.0,5.0,6.0)
>>> a = vec(3,4);b = +a;b[1] = 5 >>> print "a:",a,"\nb:",b a: [3.0,4.0] b: [3.0,5.0]
Operator | Return type | &first; Arg type | &second; Arg type | Semantics |
&op_plus; | Vector | Vector | Vector | Sum of two vectors |
&op_minus; | Vector | Vector | Vector | Difference of two vectors |
&op_mul; | Vector | Number | Vector | Product of number and vector |
&op_mul; | Vector | Vector | Number | Product of number and vector |
&op_mul; | Vector | Vector | Matrix | Multiplication by a matrix from the right b_{i} = ∑_{j} a_{j} m_{ji} |
&op_mul; | Number | Vector | Vector |
a ⋅ b = ∑_{i} a_{i} b_{i} |
&op_div; | Vector | Vector | Number | Quotient of vector and number |
Matrix | Vector | Vector | Tensor product of two vectors (a ⊗ b)_{ij} = a_{i} b_{j} |
>>> print vec(2,3) + vec(5,7) [7.0,10.0] >>> print vec(5,7) - vec(2,3) [3.0,4.0]
>>> print 3 * vec(5,6,7) [15.0,18.0,21.0] >>> print vec(5,6,7) * 3 [15.0,18.0,21.0] >>> print vec(50,60,70) / 10 [5.0,6.0,7.0]
>>> vec(2) * vec(3) 6.0 >>> vec(2,3) * vec(5,7) 31.0 >>> vec(2,3,5) * vec(7,11,13) 112.0 >>> vec(2,3,5,7) * vec(11,13,17,19) 279.0
>>> print vec(3,4) & vec(1,10) [[3.0,30.0],[4.0,40.0]]
Dimension | Return type | Semantics | Math symbol |
2 | Number | e.g. "Spinor product" | various, e.g. a ∧ b (on 2-forms) |
3 | Vector | a ∧ b (on 3-forms), a × b |
>>> vec(2,3) ^ vec(5,7) -1.0 >>> vec(1,0,0) ^ vec(0,1,0) vec3d(0.0,0.0,1.0)
Operator | Argument type | Semantics |
&op_pluseq; | Vector | Add a vector to &self; |
&op_minuseq; | Vector | Subtract a vector from &self; |
&op_muleq; | Matrix | Multiply &self; by a matrix from the right |
&op_muleq; | Number | Multiply &self; by a number |
&op_diveq; | Number | Divide &self; by a number |
>>> a = vec(2,3,5,7);a += vec(8,4,2,1);print a [10.0,7.0,7.0,8.0] >>> a = vec(2,3,5);a -= vec(4,2,1);print a [-2.0,1.0,4.0] >>> a = vec(3,5);a *= 10;print a; [30.0,50.0] >>> a = vec(10);a /= 2;print a; [5.0]
>>> a = vec(2,3);a *= mat(1,10,100,1000) >>> print a [302.0,3020.0]
Method | Result type | Semantics |
&dotsq; | Number | Inner product of a vector with itself |
&tensq; | Matrix | Tensor product of a vector with itself |
&norm1; | Number | Sum of absolute values of the components |
&norm2; | Number | |
&norminf; | Number | Maximum of absolute values of the components |
&fn_unit; | Vector | |
¶ | Matrix | Projector onto the vector |
&ortho; | Matrix | Projector into the space orthogonal to the vector |
>>> (vec(1,2) + vec(2,2)).dotsq() 25.0
>>> vec(3,4).tensq() mat2d(vec2d(9.0,12.0),vec2d(12.0,16.0))
>>> vec(3,-4).norm2() 5.0
>>> vec(3,-4).norm1() 7.0 >>> vec(3,-4).norminf() 4.0
>>> print vec(3,4).unit() [0.6,0.8] >>> print vec(3,4).unit().norm2() 1.0
>>> print vec(1).para() [[1.0]] >>> print vec(1).ortho() [[0.0]]
>>> print vec(0,0,1).para() [[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,1.0]] >>> print vec(0,0,1).ortho() [[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,0.0]]
Dimension | Return type |
2 | Vector |
3 | Matrix |
>>> mat1d();mat2d();mat3d();mat4d() mat1d(vec1d(0.0)) mat2d(vec2d(0.0,0.0),vec2d(0.0,0.0)) mat3d(vec3d(0.0,0.0,0.0),vec3d(0.0,0.0,0.0), vec3d(0.0,0.0,0.0)) mat4d(vec4d(0.0,0.0,0.0,0.0),vec4d(0.0,0.0,0.0,0.0), vec4d(0.0,0.0,0.0,0.0),vec4d(0.0,0.0,0.0,0.0))
>>> print mat1d(2) [[2.0]] >>> print mat2d(3) [[3.0,0.0],[0.0,3.0]] >>> print mat3d(5) [[5.0,0.0,0.0],[0.0,5.0,0.0],[0.0,0.0,5.0]] >>> print mat4d(7) [[7.0,0.0,0.0,0.0],[0.0,7.0,0.0,0.0],[0.0,0.0,7.0,0.0],[0.0,0.0,0.0,7.0]]
>>> print len(mat1d()),len(mat2d()),len(mat3d()),len(mat4d()) 1 2 3 4
>>> a = mat2d(1,2,4,8) >>> a[0] = vec2d(3,5) >>> a[1] = [7,9] >>> print a [[3.0,5.0],[7.0,9.0]]
>>> a = mat2d(1,2,4,8) >>> a[1][1] = 7 >>> print a [[1.0,2.0],[4.0,7.0]]
>>> a = mat4d(11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44) >>> for i in a: print i; ... [11.0,12.0,13.0,14.0] [21.0,22.0,23.0,24.0] [31.0,32.0,33.0,34.0] [41.0,42.0,43.0,44.0]
>>> print mat(2) [[2.0]] >>> print mat(2,3,5,7) [[2.0,3.0],[5.0,7.0]] >>> print mat(1,0,0,0,2,0,0,0,3) [[1.0,0.0,0.0],[0.0,2.0,0.0],[0.0,0.0,3.0]] >>> print mat(1,1,1,1,0,1,1,1,0,0,1,1,0,0,0,1) [[1.0,1.0,1.0,1.0],[0.0,1.0,1.0,1.0],[0.0,0.0,1.0,1.0],[0.0,0.0,0.0,1.0]]
Operator | Return type | Argument type | Semantics |
&op_plus; | Matrix | Matrix | Identity |
&op_minus; | Matrix | Matrix | Negative of a matrix |
>>> -mat1d(3);-mat2d(4);-mat3d(5);-mat4d(6) mat1d(vec1d(-3.0)) mat2d(vec2d(-4.0,-0.0),vec2d(-0.0,-4.0)) mat3d(vec3d(-5.0,-0.0,-0.0),vec3d(-0.0,-5.0,-0.0), vec3d(-0.0,-0.0,-5.0)) mat4d(vec4d(-6.0,-0.0,-0.0,-0.0),vec4d(-0.0,-6.0,-0.0,-0.0), vec4d(-0.0,-0.0,-6.0,-0.0),vec4d(-0.0,-0.0,-0.0,-6.0)) >>> +mat1d(3);+mat2d(4);+mat3d(5);+mat4d(6) mat1d(vec1d(3.0)) mat2d(vec2d(4.0,0.0),vec2d(0.0,4.0)) mat3d(vec3d(5.0,0.0,0.0),vec3d(0.0,5.0,0.0), vec3d(0.0,0.0,5.0)) mat4d(vec4d(6.0,0.0,0.0,0.0),vec4d(0.0,6.0,0.0,0.0), vec4d(0.0,0.0,6.0,0.0),vec4d(0.0,0.0,0.0,6.0))
>>> a = mat2d(3);b = +a;b[1][0] = 5 >>> print "a:",a,"\nb:",b a: [[3.0,0.0],[0.0,3.0]] b: [[3.0,0.0],[5.0,3.0]]
Operator | Return type | &first; Arg type | &second; Arg type | Semantics |
&op_plus; | Matrix | Matrix | Matrix | Sum of two matrices C_{ij} = A_{ij} + B_{ij} |
&op_minus; | Matrix | Matrix | Matrix | Difference of two matrices C_{ij} = A_{ij} - B_{ij} |
&op_mul; | Matrix | Number | Matrix | Product of number and matrix C_{ij} = A_{ij} x |
&op_mul; | Matrix | Matrix | Number | Product of number and matrix C_{ij} = A_{ij} x |
&op_mul; | Vector | Matrix | Vector | Product of matrix and vector: w_{i} = ∑_{j} A_{ij}v_{j} |
&op_mul; | Matrix | Matrix | Matrix | Matrix product: C_{ik} = ∑_{j} A_{ij}B_{jk} |
&op_div; | Matrix | Matrix | Number | Quotient of Matrix and number C_{ij} = A_{ij} / x |
Operator | Argument type | Semantics |
&op_pluseq; | Matrix | Add a matrix to &self; S_{ij}→S_{ij} + M_{ij} |
&op_minuseq; | Matrix | Subtract a matrix from &self; S_{ij}→S_{ij} - M_{ij} |
&op_muleq; | Matrix | Multiply &self; by a matrix from the right S_{ij}→∑_{k} S_{ik}M_{kj} |
&op_muleq; | Number | Multiply &self; by a number S_{ij}→ S_{ij} x |
&op_diveq; | Number | Divide &self; by a number S_{ij}→ S_{ij} / x |
>>> a = mat(2,3,5,7);a += mat(8,4,2,1);print a [[10.0,7.0],[7.0,8.0]] >>> a = mat(2,3,5,7);a -= mat(8,4,2,1);print a [[-6.0,-1.0],[3.0,6.0]] >>> a = mat(2,3,5,7);a *= mat(8,4,2,1);print a [[22.0,11.0],[54.0,27.0]] >>> a = mat(2,3,5,7);a *= 10;print a [[20.0,30.0],[50.0,70.0]] >>> a = mat(2,3,5,7);a /= 10;print a [[0.2,0.3],[0.5,0.7]]
Method | Result type | Semantics |
&trans; | Matrix | Transposed of a matrix (M^{T})_{ij} = M_{ji} |
&trace; | Number | Trace of a matrix trM = ∑_{i}M_{ii} |
⊂(i,j) | Matrix | Submatrix by ommiting row i and column j |
&adj; | Matrix | Adjugate of a matrix |
&det; | Number | Determinant of a matrix |
&invert; | Matrix | Inverse of a matrix |
a2 = mat2d(2,3,5,7) print "original:", a2 print " trans:", a2.trans() print " trace:", a2.trace() print "sub(1,0):", a2.sub(1,0) print " adj:", a2.adj() print " det:", a2.det() print " invert:", a2.invert()
original: [[2.0,3.0],[5.0,7.0]] trans: [[2.0,5.0],[3.0,7.0]] trace: 9.0 sub(1,0): [[3.0]] adj: [[7.0,-3.0],[-5.0,2.0]] det: -1.0 invert: [[-7.0,3.0],[5.0,-2.0]]
>>> print igl2d() [[[1.0,0.0],[0.0,1.0]],[0.0,0.0]]
>>> print igl2d(vec2d(2,3)) [[[0.0,0.0],[0.0,0.0]],[2.0,3.0]] >>> print igl2d(mat2d(2,3,5,7)) [[[2.0,3.0],[5.0,7.0]],[0.0,0.0]] >>> print igl2d(mat2d(2,0,0,3),vec2d(5,7)) [[[2.0,0.0],[0.0,3.0]],[5.0,7.0]]
>>> a = igl2d(mat2d(2,0,0,3),vec2d(5,7)) >>> print a.m, a.v [[2.0,0.0],[0.0,3.0]] [5.0,7.0] >>> a.m = mat2d(1,2,3,4) >>> a.v = vec(5,6) >>> print a.m, a.v [[1.0,2.0],[3.0,4.0]] [5.0,6.0]
Operator | Return type | &first; Arg type | &second; Arg type | Semantics |
&op_mul; | Transformation | Transformation | Transformation | Semi-direct product |
Method | Result type | Semantics |
&invert; | Transformation | Inverse |
&mat; | Matrix | Embedding into higher dimensional matrix space |
>>> a = igl2d(mat2d(2,0,0,3),vec2d(5,7))
>>> print mat3d(a) [[2.0,0.0,5.0],[0.0,3.0,7.0],[0.0,0.0,1.0]]
>>> print quatd() [0.0,[0.0,0.0,0.0]]
>>> a = 1;b = vec(0.1,0.2,0.3); >>> print quatd(a,b) [1.0,[0.1,0.2,0.3]] >>> print quatd(1,[0.1,0.2,0.3]); [1.0,[0.1,0.2,0.3]]
>>> print quatd(1) [1.0,[0.0,0.0,0.0]] >>> print quatd(vec(0.1,0.2,0.3)) [0.0,[0.1,0.2,0.3]]
>>> print quatd(1,0.1,0.2,0.3) [1.0,[0.1,0.2,0.3]] >>> print quatd(vec4d(1,0.1,0.2,0.3)) [1.0,[0.1,0.2,0.3]] >>> a = quatd(2,3,5,7);b = quatd(a) >>> print b [2.0,[3.0,5.0,7.0]]
>>> a = quatd(2,3,5,7); >>> print a[0]; 2.0 >>> print a[1]; [3.0,5.0,7.0]
>>> a = quatd(2,3,5,7); >>> print a.s; 2.0 >>> print a.v; [3.0,5.0,7.0]
Operator | Return type | Semantics |
&op_plus; | Quaternion | Identity |
&op_minus; | Quaternion | Negative of a quaternion |
>>> a = quatd(2,3,5,7); >>> print -a; [-2.0,[-3.0,-5.0,-7.0]] >>> print +a; [2.0,[3.0,5.0,7.0]]
Operator | Return type | &first; Arg type | &second; Arg type | Semantics |
&op_plus; | Quaternion | Quaternion | Quaternion | Sum of two quaternions |
&op_minus; | Quaternion | Quaternion | Quaternion | Difference of two quaternions |
&op_mul; | Quaternion | Number | Quaternion | Product of number and quaternion |
&op_mul; | Quaternion | Quaternion | Number | Product of number and quaternion |
&op_mul; | Quaternion | Quaternion | Quaternion | (Non-commuting) Product of two quaternions |
&op_div; | Quaternion | Quaternion | Number | Quotient of quaternion and number |
>>> print quatd(2,3,5,7) + quatd(1,2,4,8) [3.0,[5.0,9.0,15.0]] >>> print quatd(2,3,5,7) - quatd(1,2,4,8) [1.0,[1.0,1.0,-1.0]] >>> print quatd(2,3,5,7) * 10 [20,[30,50,70]] >>> print quatd(2,3,5,7) / 10 [0.2,[0.3,0.5,0.7]]
>>> print quatd(0,1,0,0) * quatd(0,0,1,0) [0.0,[0.0,0.0,1.0]]
Operator | Argument type | Semantics |
&op_pluseq; | Quaternion | Add a quaternion to &self; |
&op_minuseq; | Quaternion | Subtract a quaternion from &self; |
&op_muleq; | Number | Multiply &self; by a number |
&op_diveq; | Number | Divide &self; by a number |
>>> a = quatd(2,3,5,7) >>> b = quatd(a);b += quatd(1,2,4,8) >>> print b [3.0,[5.0,9.0,15.0]] >>> b = quatd(a);b -= quatd(1,2,4,8) >>> print b [1.0,[1.0,1.0,-1.0]] >>> b = quatd(a);b *= 10 >>> print b [20.0,[30.0,50.0,70.0]] >>> b = quatd(a);b /= 10 >>> print b [0.2,[0.3,0.5,0.7]]
Method | Result type | Semantics |
&conjugate; | Quaternion | Conjugate of the quaternion (vector part reverted) |
&invert; | Quaternion | Returns the inverse quaternion with respect to &op_mul; |
&dotsq; | Number | Inner product of the quaternion (interpreted as four-dimensional vector) with itself |
&norm2; | Number | Length of the quaternion (interpreted as four-dimensional vector) |
&fn_unit; | Quaternion | Returns the normalized quaternion |
>>> print quatd(2,3,5,7).conjugate() [2.0,[-3.0,-5.0,-7.0]] >>> print (3 + 4j).conjugate() (3-4j)
>>> a = quatd(2,3,5,7) >>> print a * a.invert() [1.0,[0.0,0.0,0.0]] >>> print a.invert() * a [1.0,[0.0,0.0,0.0]]
>>> a = quatd(1,2,4,10) >>> print a.dotsq() 121.0 >>> print a.norm2() 11.0 >>> print a.unit() [0.0909090909091,[0.181818181818,0.363636363636,0.909090909091]]
>>> a = quatd(2,3,5,7) >>> print vec4d(a) [2.0,3.0,5.0,7.0]
>>> print mat4d(quatd(2,3,5,7)) [[2.0,-3.0,-5.0,-7.0],[3.0,2.0,-7.0,5.0],[5.0,7.0,2.0,-3.0],[7.0,-5.0,3.0,2.0]]
>>> print rot2d() 0.0 >>> print rot3d() [1.0,[0.0,0.0,0.0]]
>>> a = rot2d(0.1);b = rot2d(a) >>> print b 0.1 >>> a = rot3d();b = rot3d(a) >>> print b [1.0,[0.0,0.0,0.0]]
>>> print rot2d(0.2) 0.2
>>> phi = 0.3 >>> c = math.cos(phi);s = math.sin(phi) >>> print rot2d(mat2d(c,-s,s,c)) 0.3
>>> a = vec(3,4);b = vec(-4,3); >>> print rot2d(a,b) 1.57079632679
>>> a = 1 + 2j; >>> print complex(rot2d(a)) * abs(a) (1+2j)
>>> print rot3d(quatd(1,.1,.2,.3)) [0.707106781187,[0.0,0.707106781187,0.0]]
>>> from math import * >>> c = cos(radians(60));s = sin(radians(60)) >>> m = mat3d(c,-s,0,s,c,0,0,0,1) >>> print rot3d(m) [0.866025403784,[-0.0,-0.0,0.5]]
>>> a = vec(0,1,0);b = vec(1,0,0) >>> print rot3d(a,b) [0.707106781187,[0.0,0.0,-0.707106781187]]
>>> print rot3d(vec(.1,.2,.3)) [0.982550982155,[0.0497088433249,0.0994176866497,0.149126529975]]
>>> print rot3d(vec(10,0,0),radians(90)) [0.707106781187,[0.707106781187,0.0,0.0]]
>>> print rot3d(0,math.radians(90),math.radians(-90),VL_APPLY_ZYX) [0.5,[-0.5,0.5,-0.5]] >>> print rot3d(math.radians(-90),0,math.radians(-90),VL_APPLY_XYZ) [0.5,[-0.5,0.5,-0.5]]
>>> a = rot3d(quatd(0,1,0,0)) >>> b = rot3d(quatd(0,0,1,0)) >>> print a * b [0.0,[0.0,0.0,1.0]]
>>> a = rot3d(quatd(1,0,0,1)) >>> print a * vec(1,0,0) [0.0,1.0,0.0]
>>> a = rot3d(quatd(1,0.1,0.2,0.3)) >>> print a * a.invert() [1.0,[0.0,0.0,0.0]] >>> print a.invert() * a [1.0,[0.0,0.0,0.0]]
>>> a = rot3d(0,radians(45),0,VL_APPLY_XYZ) >>> print a.mat() [[0.707106781187,0.0,0.707106781187], [0.0,1.0,0.0], [-0.707106781187,0.0,0.707106781187]]
>>> a = rot3d(radians(90),radians(90),0,VL_APPLY_XYZ) >>> print a.quat() [0.5,[0.5,0.5,-0.5]]
>>> a = rot3d(radians(179),0,0,VL_APPLY_XYZ) >>> print a.quat() [0.00872653549837,[0.999961923064,0.0,0.0]] >>> b = rot3d(radians(-179),0,0,VL_APPLY_XYZ) >>> print b.quat() [0.00872653549837,[-0.999961923064,0.0,0.0]] >>> print b.quat(a.quat()) [-0.00872653549837,[0.999961923064,-0.0,-0.0]]
>>> a = rot3d(vec(6,8,0),radians(90)) >>> print a.axis() [0.6,0.8,0.0] >>> print degrees(a.angle()) 90.0
>>> a = rot3d(radians(20),radians(10),radians(30),VL_APPLY_ZYX) >>> phi_x,phi_y,phi_z = a.angles(VL_APPLY_ZYX) >>> print degrees(phi_x),degrees(phi_y),degrees(phi_z) 20.0 10.0 30.0
>>> print quatd(rot3d()) [1.0,[0.0,0.0,0.0]] >>> print mat3d(rot3d()) [[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]]
Function | Dimension | Return type | &first; Arg type | &second; Arg type | Semantics |
˙ | 1 to 4 | Number | Vector | Vector | |
&ten; | 1 to 4 | Matrix | Vector | Vector | |
&wdg; | 2 | Number | Vector | Vector | |
&wdg; | 3 | Vector | Vector | Vector |
affine transformation | 3 |
dot product | 4.1.5.2, 5 |
dyadic product | 5 |
euclidian norm | 4.1.6 |
inner product | 4.1.5.2 |
matrix | 4.2 |
quaternion | 4.4 |
rotation | 4.5 |
skew-symmetric product | 5, 5 |
tensor product | 4.1.5.2, 5 |
transformation | 4.3 |
unit vector | 4.1.6 |
vec() | 4.1.2 |
vector | 4.1 |
vector product | 4.1.5.2, 5 |