Simulating Ray Direction and getVectTo

It works by multiplying the global vector by the orientation matrix. To explore the specific details of that operation you can google “vector matrix multiplication”.

Does that work?

Basically, this:

from Mathutils import Vector, Matrix
global_vec = Vector([2.0,2.0,2.0]) #Because that is what the other script eventually returns.

mat = Matrix(*own.worldOrientation)
local_vec = global_vec * mat

At a quick glance, yea, I think that should work.

Did you test it? What result are you expecting?

I wasn’t really sure what to expect…I was just testing it.

I got the result of [2.0,2.0,2.0]

When I multiplied that same vector by the normal orientation matrix of an object. (As in, the one it starts out having with no rotation.)

By the way, when I googled vector matrix multiplication…I got this really complicated wiki article…

Could you give me a description in a nut shell? I know how to multiply polynomials, and I hear that this isn’t a lot different.

Well, obviously, if the result is equal to the local vector, as calculated by the getVectTo function, then it works, and you can use it instead of getVectTo(b)[2] to calculate the local vector (assuming that’s what you really want to do here).

I think you need to explain your goals better. As I said, I assume you simply want to replace the getVectTo function with some pure python stuff, but I don’t see why you would want to, since getVectTo already exists.

If you need to get the information that getVectTo supplies, then just use that; the function is there for your convenience.

When I multiplied that same vector by the normal orientation matrix of an object. (As in, the one it starts out having with no rotation.)
Multiplying a vector by the identity matrix (default orientation) should produce the same vector, and, if you noticed, when the orientation is at default, the vectors returned by getVectTo are equivalent, which is as it should be.

By the way, when I googled vector matrix multiplication…I got this really complicated wiki article…

Could you give me a description in a nut shell? I know how to multiply polynomials, and I hear that this isn’t a lot different.
Here you go:

v = [x,y,z]

mat =
[m00, m01, m02]
[m10, m11, m12]
[m20, m21, m22]

v * mat = [xm00 + ym10 + zm20, xm01 + ym11 + zm21, xm02 + ym12 + z*m22]

A python function you can use to test the process:


def vecMatMult(vec, mat): 
    """vec is a Matutils Vector, mat is Mathutils Matrix""" 
    result_vec = Vector([0,0,0]) 
     
    result_vec.x = vec.x*mat[0].x + vec.y*mat[1].x + vec.z*mat[2].x 
    result_vec.y = vec.x*mat[0].y + vec.y*mat[1].y + vec.z*mat[2].y 
    result_vec.z = vec.x*mat[0].z + vec.y*mat[1].z + vec.z*mat[2].z 
     
    return result_vec

Although, I should mention again that actually using all of this when getVectTo returns the very same results is somewhat pointless.

I see what you mean and thanks for all the help! :smiley:

I found this script that makes mesh waves, and I thought that was very interesting. So I devised a sort of “Sim City” like god mode. If you don’t know what that is, it is basically a terrain maker. My new script that I wrote uses vertices to make it seem like the user is actually moving around and shaping the ground. I needed to know how the getVectTo function worked, so that I could make the vertices move to the correct calculated spot in stead of just snapping right to it.

If that makes sense, I needed the information mostly for curiosity but also for making the calculations between two position vectors.

Hope I made enough sense, thanks for all your help. :slight_smile:
Sunjay03