Page MenuHome

Fix T73301: Support mathutils.Vector.rotate for 2D vectors
ClosedPublic

Authored by Tiago Chaves (laurelkeys) on Feb 18 2020, 6:48 PM.

Details

Summary

Support mathutils.Vector.rotate of 2D vectors by 2x2 matrices.

  • Added a "special case" check for when the vector has size = 2 and the matrix is 2x2.
  • Rotation of 2D vectors by Euler or Quaternion remain invalid, since it's not an operation as "well defined" as with a 2x2 matrix.
  • Implemented Matrix.to_3x3 and Matrix.to_4x4 for 2x2 matrices as well (currently it raises a "inappropriate matrix size" ValueError).

Also, by allowing 2x2 matrices to be "casted", we can have the same result of v.rotate(m) when using v.resize_3d(); v.rotate(m.to_3x3()); v.resize_2d(), e.g.:

m = Matrix.Rotation(radians(90), 2)

v0 = Vector((1.0, 0.5))
v1 = Vector((1.0, 0.5))
v2 = Vector((1.0, 0.5))

v1.rotate(m)

v2.resize_3d()
v2.rotate(m.to_3x3())
v2.resize_2d()

assert v1 == v2
assert v2 == m @ v0       # calling v.rotate(m) is equivalent to m @ v, and not v @ m
assert m @ v0 != v0 @ m   # m @ v will generally be different from v @ m, as it is in this case

Diff Detail

Repository
rB Blender

Event Timeline

It looks good, I didn't see any problems.
If @Campbell Barton (campbellbarton) doesn't have any observations, I can commit (this week maybe).

This revision is now accepted and ready to land.Feb 19 2020, 8:17 PM

Thanks, committed rBbc86eb1780a8: mathutils: support Vector.rotate for 2D vectors, {0115568ca6537260b2f177bf59edd55d07904099}

Made some changes to matrix parsing, using a generic function.