2
$\begingroup$

I have two vectors that I would like to print to a file but before that I would like to multiply x and y in the first with -1 so instead of Vector((5, -10, 0)) it should be ((-5, 10, 0)) and in the second I would like to change order of y and z from Vector((0.0, 0.5, 1.0)) to Vector((0.0, 1.0, 0.5)).

Any ideas?

$\endgroup$
1
  • 2
    $\begingroup$ its simple.(its mainly a python question) 1) a = Vector((5, -10, 0)) 2) a.z, a.y = a.y, a.z 3) a = -a 4) print to file $\endgroup$ Jun 21, 2022 at 14:37

1 Answer 1

3
$\begingroup$

First one is simple, multiply by (-1,-1,1):

a = Vector((5,-10,0))
print(a * Vector((-1,-1,1)))
# output: Vector((-5.0, 10.0, 0.0))

Second - rearrange it like this:

b =  Vector((0.0, 0.5, 1.0))
print(Vector((b.x, b.z, b.y)))
# output: Vector((0.0, 1.0, 0.5))
$\endgroup$
5
  • $\begingroup$ Thanks a lot. I get NameError: name 'Vector' is not defined, is there some library that I miss? $\endgroup$ Jun 21, 2022 at 14:53
  • $\begingroup$ from mathutils import Vector $\endgroup$
    – Crantisz
    Jun 21, 2022 at 14:53
  • $\begingroup$ Thanks, you are the best. $\endgroup$ Jun 21, 2022 at 14:57
  • 1
    $\begingroup$ You can also scale the vector with a *= -1 or a = a * - 1. Please note in this case 0 can become -0 which is weird and can lead to problems if testing for equality. $\endgroup$
    – Gorgious
    Jun 21, 2022 at 15:33
  • $\begingroup$ @Gorgious X and Y was asked to be inverted, not the Z $\endgroup$
    – Crantisz
    Jun 21, 2022 at 16:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .