mathutils.Vector.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import mathutils
  2. # zero length vector
  3. vec = mathutils.Vector((0.0, 0.0, 1.0))
  4. # unit length vector
  5. vec_a = vec.normalized()
  6. vec_b = mathutils.Vector((0.0, 1.0, 2.0))
  7. vec2d = mathutils.Vector((1.0, 2.0))
  8. vec3d = mathutils.Vector((1.0, 0.0, 0.0))
  9. vec4d = vec_a.to_4d()
  10. # other mathutuls types
  11. quat = mathutils.Quaternion()
  12. matrix = mathutils.Matrix()
  13. # Comparison operators can be done on Vector classes:
  14. # (In)equality operators == and != test component values, e.g. 1,2,3 != 3,2,1
  15. vec_a == vec_b
  16. vec_a != vec_b
  17. # Ordering operators >, >=, > and <= test vector length.
  18. vec_a > vec_b
  19. vec_a >= vec_b
  20. vec_a < vec_b
  21. vec_a <= vec_b
  22. # Math can be performed on Vector classes
  23. vec_a + vec_b
  24. vec_a - vec_b
  25. vec_a @ vec_b
  26. vec_a * 10.0
  27. matrix @ vec_a
  28. quat @ vec_a
  29. -vec_a
  30. # You can access a vector object like a sequence
  31. x = vec_a[0]
  32. len(vec)
  33. vec_a[:] = vec_b
  34. vec_a[:] = 1.0, 2.0, 3.0
  35. vec2d[:] = vec3d[:2]
  36. # Vectors support 'swizzle' operations
  37. # See https://en.wikipedia.org/wiki/Swizzling_(computer_graphics)
  38. vec.xyz = vec.zyx
  39. vec.xy = vec4d.zw
  40. vec.xyz = vec4d.wzz
  41. vec4d.wxyz = vec.yxyx