# Multiply Vector * Matrix bugs?

I’m trying to update a script I’m writing to 2.40 and I used to use the depricated MatMultVec() and VecMultMat() functions. They no longer work and so I replaced them with the simpler vec * mat syntax. I’ve tried all kinds of things, but can’t get it to work correctly. All I want is a simple transformation. Here’s the code:

``````import math
from math import *
import Blender
from Blender.Mathutils import *

p = Vector(0.0, 0.0, 0.0)
transMatrix = TranslationMatrix(Vector(0.0,15.0,0.0))
print 'pBefore:', p
print 'transMatrix: ', transMatrix

p.resize4D()
p2 = transMatrix * p
print 'pAfter: ', p2
``````

If anyone with 2.40 can try this out and let me know if I’m doing something wrong that’d be great! Incidentally someone else seems to be having a similar problem:

https://blenderartists.org/forum/viewtopic.php?t=53692&highlight=matmultvec

p.resize4D() gives now a vector [0.0, 0.0, 0.0, 0.0]
instead of [0.0, 0.0, 0.0, 1.0] in the 237.I have no
idea why!!!

Thanks for the reply, but I’m not sure how that makes a difference. I thought the 4th number in the vector had no effect and is thrown out anyway if I resize3D() afterward.

Either way, the first 3 numbers (x, y, z) are the only ones that really mean anything, and the y value should be changed to 15.0 in this situation.

Ok well unfortunately I haven’t gotten an answer to my question in the last few days, so I think I’ll end up submitting a bug report for this problem.

The 4th value is essential. Just do the math:

``````
1 0 0 0          0
0 1 0 1.5   X    0
0 0 1 0          0
0 0 0 1          w

``````

the resulting vector is

``````
1*0 + 0*0 + 0*0 + 0*w
0*0 + 1*0 + 0*0 + 1.5*w
0*0 + 0*0 + 1*0 + 0*w
0*0 + 0*0 + 0*0 + 1*w

``````

Obviously, if w is 0 then the resulting vector has no translation component at all.

So, like Ben said, the bug is in the resize4d code.

Martin