1

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
from math import radians


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
Rick T
  • 4,391
  • 1
  • 20
  • 64
  • 1
    Related https://blender.stackexchange.com/questions/139511/replace-matrix-vector-list-comprehensions-with-something-more-efficient – batFINGER Apr 25 '20 at 08:28

1 Answers1

1

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))]
Rick T
  • 4,391
  • 1
  • 20
  • 64