Rotate an object using another object orientation

Hi , i would like to
rotate an object_or_vertex using another object local-orientation ?
In the image, i want to rotate the “greycube”, along the X of the “greenbar” .
im trying to, rotate the vector-distance between them
to get the location, with bad result.
Also i have no idea of how rotate the “rotation”.

Right now i understand that coordinates of vertex are “local” (they depend on the transform)
so to obtain the realworld 3Dlocation
i have to multiply them for the matrix of the object. ( Little test with bluecube )

Can i use the matrix to obtain the rotation too?

thanks for your time

I’m not 100% sure I understand what it is you are trying to do, but it may be a lot easier to just change the pivot point of the object you are trying to rotate:

def set_origin(ob, global_origin=Vector()):
    mw = ob.matrix_world
    o = mw.inverted() @ Vector(global_origin)
    mw.translation = global_origin
# call the function:

then use the rotate code to rotate it, but this way, the center of rotation will be at the origin, and it will remain constant, I am not sure if that is what you want. If that is not, there is a math function for it, normally they will use some form of sin and cosine. Trigonometric stuff. Alternatively I suppose you could also change the pivot point location as it rotates.

Hi man, thanks for reply,
and thank you very much for this piece of code,
its pretty useful get an example of inverted_matrix used ! this is the kind things i was searching about!

Sorry for the incoming mess
Basically i would just do ,
what happen when you parent an object .
I can parent A to B and now i can use the local transfromation of B to move A.
I dont think i can use parent since i would do this to object, and faces, and vertex,… (am i wrong?)

I followed some tutorials about matrix but i get lost in understanding some parts.

When i get to the Inverted matrix the definition is “a matrix that invert- cancel the transformations”,
for me its not really clear and i made some experiment to understand,

I just duplicated some cube to show tha path, but the inverted matrix what is exactly?
,i am very interested but also confused XD.

Watching this i clearly understand that the transformations occur around the world origin, but maybe i can do it with any “point-origin”

Basically is just what happen when you parent an object .
I can parent A to B and now i can use the local transfromation of B to move A.

I do not use linear algebra much, as I just do not understand it that much, and, most of the functions that you need in Blender Python are built in, so you do not need linear algebra. To drive the rotation of one object from the rotation of another would normally be accomplished via drivers if the ratio was not one-to-one, but it can just as easily be done using Python rotation functions. By the way, I found that function from the last post by searching the internet, which is one of the best ways to find the code that you need, but you have to use the right keywords and have a good idea what you are looking for. I am working on creating tutorials on my website, but have not covered drivers yet.

Yep , watching tutorials and googling on euler-matrix-quaternion here !
but keywords and general behaviour are not universal for everybody.
Like the pivot XD, coming from maya i usually think to it like a free identity,
not the result of the matrix stuff.

thanks for reply man