103. opengl.matrix
— opengl/matrix.py¶
Python OpenGL framework for pyFormex
103.1. Classes defined in module opengl.matrix¶
-
class
opengl.matrix.
Vector4
(data=None)[source]¶ A set of homogeneous coordinates
The input can be 3D or 4D coordinates. The results is always a 2-dimensional array: a single point has nrows=1.
Examples
>>> Vector4([1, 2, 3]) Vector4([[1., 2., 3., 1.]]) >>> Vector4([[1, 2, 3],[4, 5, 6]]) Vector4([[1., 2., 3., 1.], [4., 5., 6., 1.]]) >>> Vector4([[1, 2, 3, 0], [4., 5., 6., 1.]]) Vector4([[1., 2., 3., 0.], [4., 5., 6., 1.]]) >>> Vector4([[1,2,3]]).dtype dtype('float32')
-
class
opengl.matrix.
Matrix4
(data=None)[source]¶ A 4x4 transformation matrix for homogeneous coordinates.
The matrix is to be used with post-multiplication on row vectors (i.e. OpenGL convention).
- Parameters
data (array_like (4,4), optional) – If specified, should be a (4,4) float array or compatible. Else a 4x4 identity matrix is created.
Examples
>>> I = Matrix4() >>> print(I) [[1. 0. 0. 0.] [0. 1. 0. 0.] [0. 0. 1. 0.] [0. 0. 0. 1.]]
We can first scale and then rotate, or first rotate and then scale (with another scaling factor):
>>> a = I.scale([4.,4.,4.]).rotate(45.,[0.,0.,1.]) >>> b = I.rotate(45.,[0.,0.,1.]).scale([2.,2.,2.]) >>> a Matrix4([[ 0., 4., 0., 0.], [-4., 0., 0., 0.], [ 0., 0., 8., 0.], [ 0., 0., 0., 1.]]) >>> (a==b).all() True