How to convert from world space to object space[specific case]

I have a vector in world space(e.g. let’s say it’s (0, 0, -2)). I have an object(which has orientation matrix). It has a vector in it’s local space. That vector’s local Z axis goes through the centre of it’s master object in negative direction. The vector has no orientation matrix, however, in calculations it uses axis. The axis must only use the master object’s orientation matrix, position of itself and master object.


The image should explain the problem pretty well. As you can see, I require some advanced math(not primary school - that’s why I haven’t learnt those things yet). However, I hope that somebody can help me out. Thanks!:slight_smile:

Attachments


The basics of transformations are as follows:

To rotate a vector by a matrix,

rotated = mat * vec

To rotate a direction vector from local to world space (of an object)

world = obj_rot_mat * local

To rotate a direction vector from world to local space (of an object)

local = obj_rot_mat.inverted() * world

An orientation matrix (obj_rot_mat) just rotates vectors (doesn’t affect their lengths). A Transformation matrix (obj.worldTransform) will rotate and scale vectors. It’s useful when transformation position vectors from local to world space.
A position vector and direction vector is just a semantic difference. They’re both vectors but they mean​ subtly different things.

OK! But now, how do I get the rotation matrix if I know the world vector and world orientation, the position of point and I know that the point’s Z axis are facing right away from the centre?

A rotation matrix for the orientation of an object is the worldOrientation matrix.

I can’t really understand what you want to do from the diagram, unfortunately, but thanks for attempting one in the first place.

I actually decided to use my system in world-space only. This seems to remove any need of this complex math.

You should take a course in some vector mathematics, as it often simplifies these problems