Hi,

I’m trying to find an equivalence for the getInverseMatrix() in 2.54 APIs but can’t find it in the APIs reference. Any idea ?

Thanks

Hi,

I’m trying to find an equivalence for the getInverseMatrix() in 2.54 APIs but can’t find it in the APIs reference. Any idea ?

Thanks

Not completely certain, but this looks like what you need:

mathutils.Matrix(bpy.context.object.matrix_world).invert()

Yes, the Matrix has the option invert() and **replaces **the matrix by its inverse.

Therefore maybe do not forget to use **copy()** too!

Yeah, thanks for answering, I first thought to that method too but can’t figure how to use it, here is the context I have to face :

Blender 2.49

light = Blender.Object.Get(“mylight”)

matrix = Mathutils.Matrix(light.getInverseMatrix())

Blender 2.5

light = bpy.data.objects[“mylight”]

matrix=???

No, I was talking about 2.54 …

probably

matrix = bpy.data.objects[“mylight”].matrix_world.invert()

I just checked it and something peculiar is going on. Here’s an example of the matrices of the same object both in 2.49 and 2.54 (rev 31878). The 2.49 situation is used as a reference.

```
2.49
normal inverse
n1 n2 n3 0 i1 i2 i3 0
n4 n5 n6 0 i4 i5 i6 0
n7 n8 n9 0 i7 i8 i9 0
Lx Ly Lz 1 ix iy iz 1
2.54
normal inverse
n1 n4 n7 Lx i1 i4 i7 ix
n2 n5 n8 Ly i2 i5 i8 iy
n3 n6 n9 Lz i3 i6 n9 iz
0 0 0 1 0 0 0 1
```

n1-n9 are just numbers that show up in the matrix in 2.49 and depend on the location and rotation of the object.

i1-i9 are the inverted values of n1-n9

Lx, Ly, Lz are the location of the object (as entered in the properties tab)

ix, iy, iz are the inverted values of Lx, Ly, Lz

In short: the matrices in 2.54 are transposed compared to 2.49. So to get the same as you used to get with object.getInverseMatrix(), use the following:

```
light = bpy.data.objects["mylight"]
matrix = mathutils.Matrix(light.matrix_world.copy()).invert().transpose()
```

would that be an error in 2.54?

why is it transposed?

i mean a colum vector is now a row vector !

meaning that all the data repesented as vector / matrix inside 2.5 have been transposed!

or does it means that the matrix are not process the same way in 2.54 then in 2.49 ?

thanks and happy 2.5

Sure!

In another ‘experiment’ I had to set a matrix using one list of 16 numbers, I thaught it rowise and did only realize that the initialization was columnwize, though the vectors shown later are rowvectors ( so to say laying in the matrix).

Al works well but maybe this should be explained (later in the wiki or wikibooks or …)

Hi,

Thanks the code is ok and it works fine, strangely I had to remove the transpose and I get the same result as 2.49 simply by using the invert function.

enricoceric: what version of 2.5 are you using (I tested it on 2.54 official, rev 31878)? It could be that this changed somewhere during development.

ome thing i noticed too

there is a difference for matrix representation inside blender and how it is printed

they are also transposed

rows inside are shown as column when printed!

example

**this is under version 32385**

M=mathutils.Matrix((1,2,3,4),(-1,2,-3,4),(1,-2,3,-4),(1,1,1,1))

print (‘M =’,M)

the printed values are as follows

draws swap exchange 9

M = Matrix((1.000000, -1.000000, 1.000000, 1.000000), (2.000000, 2.000000, -2.00

0000, 1.000000), (3.000000, -3.000000, 3.000000, 1.000000), (4.000000, 4.000000,

-4.000000, 1.000000))

i mean rows become columns!

butnow looks like it is more then in the print function it may also some of the math operations

but is it changing the end results or only internaly modfiied

sorry not much time for now and i have to wait this weekend to do some experimentation on this!

but overall what would be the new rule to use vector or matrix under 254

and someone should add this to the wiki page so people know the difference between old 2.49 and 2.5 !

salutations and happy 2.5

As I realized, the input of a matrix is COLUMNWIZE, the matrix is internally an object with 4 Vectors, columnwize.

but in printing(RickyBlender is correct) the matrix is shown as one would write it: rowwize

Proof, multipy the matrix with a Vector from the left and from the right!

```
from mathutils import *
M=Matrix((1,1,1,1),(0,2,2,2),(0,0,3,3),(0,0,0,4))
print ('M =',M)
print("first of M",M[0])
print("first row of M",M[0][0],M[1][0],M[2][0],M[3][0])
V = Vector((1,1,1,1))
print(M*V) #V used as column-vector result a vector(column)
print(V*M) #V used as row-vector result a vector (row)
```

That means too, that mathutils returns always a Vector, which may be used as column 1st example

or row 2nd example!

gives:

M = Matrix((1.000000, 0.000000, 0.000000, 0.000000),

1.000000, 2.000000, 0.000000, 0.000000), (1.000000, 2000000, 3.000000, 0.000000), (1.000000, 2.000000, 3.00000, 4.000000))

first of M Vector((1.0, 1.0, 1.0, 1.0))

first row of M 1.0 0.0 0.0 0.0

Vector((1.0, 3.0, 6.0, 10.0))

Vector((4.0, 6.0, 6.0, 4.0))

is this like it was in 2.49 ?

i find confusing to enter columns instead of row for vectors in matrix

i’m use to think of vectors as rows like in x1 i + y1 j + z1 k

but there are occasions where you need to input vector as column

so may be we should have the choice but how ?

but may be this should be the same then in old 2.49

so that there is minimum conversion effort

compatibility between 2.5 and old 2.49 !

thanks and happy 2.5

I’m using the 2.54 official rev 31878 too, downloaded from the blender site.

how to upate this to 2.59?

light = bpy.data.objects[“mylight”]

matrix = mathutils.Matrix(light.matrix_world.copy()).invert().transpose()

thanks

happy 2.59