matrix multiplication, matrix * point
using mathutils:
using numpy:
and three.js too
http://docs.scipy.org/doc/numpy/reference/generated/numpy.matrix.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mathutils import Matrix, Vector | |
>>> M = Matrix([[1, 0, 0, 0],[0, 1, 0, 0],[0, 0, -1.2, -2.2],[0, 0, -1, 0]]) | |
>>> vec_1 = Vector((0,0,-1,1)) | |
>>> vec_2 = Vector((0,11,-11,1)) | |
>>> vec_3 = Vector((0,4,-6,1)) | |
>>> for vec in [vec_1, vec_2, vec_3]: M*vec | |
... | |
Vector((0.0, 0.0, -1.0, 1.0)) | |
Vector((0.0, 11.0, 11.0, 11.0)) | |
Vector((0.0, 4.0, 5.0, 6.0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
mdata = "[1 0 0 0; 0 1 0 0; 0 0 -1.2 -2.2; 0 0 -1 0]" | |
M = np.matrix(mdata) | |
vec_1 = np.array([0,0,-1,1]) | |
vec_2 = np.array([0,11,-11,1]) | |
vec_3 = np.array([0,4,-6,1]) | |
for vec in [vec_1, vec_2, vec_3]: | |
print(M.dot(vec)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// because 4*4 is inferred, the matrix is vectorized (flattened) | |
var M = new THREE.Matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1.2, -2.2, 0, 0, -1, 0); | |
var vec_1 = new THREE.Vector4( 0, 0, -1, 1); | |
var vec_2 = new THREE.Vector4( 0, 11,-11, 1); | |
var vec_3 = new THREE.Vector4( 0, 4, -6, 1); | |
[vec_1, vec_2, vec_3].forEach(function(vec,i){ | |
var vector_new = vec.applyMatrix4(M); | |
console.log(vector_new) | |
}) |
references
http://www.scipy.org/NumPy_for_Matlab_Usershttp://docs.scipy.org/doc/numpy/reference/generated/numpy.matrix.html