Multiplying a vector with a TranslationMatrix

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Risky.Martin
Posts: 4
Joined: Sat Jul 30, 2005 11:37 am

Multiplying a vector with a TranslationMatrix

Postby Risky.Martin » Sat Dec 09, 2006 1:04 pm

(I posted this on BlenderArtist, before realizing that here is probably
a better place for this sort of question)

Hi,

Using TranslationMatrix is giving me quite a hard time.


Code: Select all

## --- example code
v_a = Blender.Mathutils.Vector(1, 0, 0 ,0)
v_b = Blender.Mathutils.Vector(0, 1, 0 ,0)
m_t = Blender.Mathutils.TranslationMatrix(v_a)


Code: Select all

print(m_t)


gives

Code: Select all

[1.000000, 0.000000, 0.000000, 0.000000](matrix [row 0])
[0.000000, 1.000000, 0.000000, 0.000000](matrix [row 1])
[0.000000, 0.000000, 1.000000, 0.000000](matrix [row 2])
[1.000000, 0.000000, 0.000000, 1.000000](matrix [row 3])


that looks much like the transpose of what I would have expected...
I proceed anyway, following the documentation, and I multiply the vector by the matrix
(I would have rather done Mv rather vM but since we already have
a transpose, I assume that what I know does not apply to the python API...)

Code: Select all

print(v_b * m_t)


Ouch, I get my vector v_b untouched:

Code: Select all

[0.000000, 1.000000, 0.000000](vector)


Assuming that the doc is not accurate I try:

Code: Select all

m_t.transpose()
m_t * v_b


Still the same:

Code: Select all

[0.000000, 1.000000, 0.000000](vector)


Anyone with an advice ?


Thanks,

rm.

cedricp
Posts: 17
Joined: Mon May 15, 2006 5:22 pm

Postby cedricp » Wed Dec 13, 2006 2:25 pm

Hi,

You should define your vector with w value = 1.0 if you want it translated:

v = Vector(1.0,0.0,0.0,1.0)

and it'll work.

Cheers.

Risky.Martin
Posts: 4
Joined: Sat Jul 30, 2005 11:37 am

Thanks.

Postby Risky.Martin » Mon Dec 18, 2006 4:33 pm

...late-at-night hacking...
I should have opened a book (and my eyes).

Thanks again.


Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests