Vector Math Newb

Hi everyone,

I’ve been learning Python as my first language for a while now and am fine with the logic but not quite so clued up with the math. If someone could help me out with a few basic vector questions it would be greatly appreciated.

I understand a Vector3 as a direction in 3D space with a magnitude (length). This I get, so I understand the following for example:

getVectTo(pos)

What I don’t understand is what is happening when you convert a coordinate to a vector like the following:

Vector(owner.position)

What has this done exactly? A single coordinate can’t have a magnitude or a direction so I’m not sure what this has created.

Also:

What would be the process for supplying a coordinate, a vector and a distance and attaining the new coordinate?

Can I use the axis vector from another object to translate a coordinate? How would I get the normalised vector of an axis?

Can coordinates be mirrored along a vector between two points?

Any help would, as always, be super appreciated!

I don’t know much about vectors, but they have useful values and functions present to help you out with math - for example, the reflect function. This function allows you to get the reflecting vector from a given wall vector.

If you convert a position to a vector, it would most likely return a vector simply containing the values you pass. For example,

Say you have a cube at position (0.5, 1.0, 2.0).
If you convert that position to a vector, it will be (0.5, 1.0, 2.0) still.

Here’s the link to the Wikipedia page explaining Euclidian vectors.

A vector of a position would represent the distance (length) from (0,0,0) and the direction, which is just another way to describe the position.

A vector is the direction and magnitude between two points. Finding vectors is actually easy.

If B = (1, 2, 3) and A = (6, 0, 8)
Then vector AB = (1-6, 2-0, 3-8) = (-5, 2, -5)

Normalizing the vector is a bit trickier though.

If vector AB = (-5, 2, -5)
abs = √(-5*-5 + 22 + -5-5)
Then AB normalized = (-5/abs, 2/abs, -5/abs) = (-.68, .27, -.68)

If you had a vector then you could easily find a point lying on it at a certain distance.

If point A = (1, 1, 1) and point B = (1, 1, -1)
Then vector AB = (0, 0, 2)
So vector AB normalized = (0, 0, 1)

So if point C lies on vector AB at a distance of 5
D = (ABxAx + AByAy + ABzAz) = (10 + 10 + 11) = 1
point C = (05+D, 05+D, 1*5+D) = (1, 1, 6)

As for your first question

Vector(owner.position)

I would have to guess that a vector would be made with the values of the position of that object.

Sim88 A vector of a position would represent the distance (length) from (0,0,0) and the direction, which is just another way to describe the position.

That’s not really true. A vector represents more than the points that were used to find it.

Repeat after me: There is no such thing as a “point”; there are only vectors.

It’s not “point A, point B” and then a vector AB (or BA) between them -> It’s Vector A, Vector B, and then Vector A - B, or B - A.

Generalize your thinking in terms of vectors, and you’ll preserve your sanity.

It created a Vector object using the information in the supplied list, which, by itself, represents a position in 3D space, with reference to the origin (0, 0, 0). The reason people bother to create vectors from position lists is simply because, as Joeman16 said, a Vector object provides certain functions (like reflection) that are not available on the the list object.

Also, and perhaps more important, is the fact that Vectors have common operation overloads (like addition, subtraction, dot product, etc), and they can be used with matrices in a fairly natural manner (I will demonstrate this below, as it answers one of your previous questions).

In 2.5, this was streamlined, and owner.worldPosition is a proper Vector object.

What would be the process for supplying a coordinate, a vector and a distance and attaining the new coordinate?
Think in vectors:


pos_vec = Vector(own.worldPosition)
distance = 24.5 # or any other scalar
dir_vec = Vector((1, 1, 1)) # or any other direction

trans_vec = dir_vec.copy()
trans_vec.magnitude = distance

new_coordinate = pos_vec + trans_vec

Can I use the axis vector from another object to translate a coordinate? How would I get the normalised vector of an axis?
Yes, and there are a few ways to do that, both involving the orientation matrix. One is to pick out the appropriate column from the matrix, because that’s essentially what the matrix holds (axis vectors):


mat = own.worldOrientation
x_axis = Vector((mat[0][0], mat[1][0], mat[2][0]))
y_axis = Vector((mat[0][1], mat[1][1], mat[2][1]))
z_axis = Vector((mat[0][2], mat[1][2], mat[2][2]))

The other is to simply transform a global axis vector with the matrix of the object in question:


mat = Matrix(*own.worldOrientation) # "*" splits list components into 3 list arguments
x_axis = mat * Vector((1, 0, 0))
y_axis = mat * Vector((0, 1, 0))
z_axis = mat * Vector((0, 0, 1))

Can coordinates be mirrored along a vector between two points?
The reflect method mentioned by Joeman16 should be what you’re looking for.

Relevant documentation can be found here: http://www.blender.org/documentation/249PythonDoc/GE/Mathutils.Vector-class.html

Wow, this has been an incredible response. Thanks everyone for the resources! This is exactly what I’d spent several hours scouring the forums looking for.

It’s still a bit above my head when it comes to thinking in vectors, so I’m going to keep practicing with simple vectors before looking into matrix multiplication etc.

This:

It’s not “point A, point B” and then a vector AB (or BA) between them -> It’s Vector A, Vector B, and then Vector A - B, or B - A.

and this:

because that’s essentially what the matrix holds (axis vectors)

Have saved my brain!