# How can I multiply a quaternion and a list of vectors that represent xyz vertices of an object

How can I multiply a quaternion and a list of vectors together (which will represent the x,y,z vertices of an object)? The error I get is: Error: Quaternion multiplication: not supported between quaternion and numpy.ndarray types

A snippet of the code is below

import math
import sys
import mathutils
import numpy as np

w_rot=0.9961946980917455
i_rot=0.0
j_rot=0.08715574274765817
k_rot=0.0

quat1 = mathutils.Quaternion((w_rot, i_rot, j_rot, k_rot))
vector_xyz_rows = np.array([[1, 2, 3],[4.1, 5.1, 6.1]])

test_calc = quat1 @ vector_xyz_rows

• Commented Apr 25, 2020 at 8:28

Here's the answer that @batFINGER helped me figure out.

import bpy
import mathutils

ob = bpy.context.object

old_verts = [v.co for v in ob.data.vertices]
print("old_verts=%s" % old_verts)

#Do calculation
quat1 = mathutils.Quaternion((1, 2, 3, 4))
new_verts = [quat1 @ v.co for v in ob.data.vertices]

print("--------------")
print("new_verts=%s" % new_verts)


Output:

old_verts=[Vector((1.0, 1.0, 1.0)), Vector((1.0, 1.0, -1.0)), Vector((1.0, -1.0, 1.0)), Vector((1.0, -1.0, -1.0)), Vector((-1.0, 1.0, 1.0)), Vector((-1.0, 1.0, -1.0)), Vector((-1.0, -1.0, 1.0)), Vector((-1.0, -1.0, -1.0))]
--------------
new_verts=[Vector((6.0, 30.0, 42.0)), Vector((-38.0, -10.0, 34.0)), Vector((-2.0, 50.0, -14.0)), Vector((-46.0, 10.0, -22.0)), Vector((46.0, -10.0, 22.0)), Vector((2.0, -50.0, 14.0)), Vector((38.0, 10.0, -34.0)), Vector((-6.0, -30.0, -42.0))]

• Also using quat.to_matrix() will enable the use of methods linked to comment. Commented Apr 26, 2020 at 4:52