I have an array filled with points that should be aligned to a random coordinate system. The direction vectors of the coordinate system are known, as well as the direction vectors that form the points together.
My approach was to calculate the respective angle, from each point to the appropriate direction vector and then to rotate each point by this angle. The centre of rotation is the origin of all vertices together.
vert_array = [vert_1, vert_2, ..., vert_x] def dotproduct(v1, v2): return sum((a*b) for a, b in zip(v1, v2)) def length(v): return math.sqrt(dotproduct(v, v)) def angle(v1, v2): return math.acos(dotproduct(v1, v2) / (length(v1) * length(v2))) angle_x = angle(x_axis_vec_coordinatesys, direction_vec_x_array) for vert in vert_array: mat_rot = mathutils.Matrix.Rotation(angle, 4, direction_vec_x_array) new_point= mat_rot * (vert - origin) + origin vert_array_new.append(new_point) #And so on for all axis.....
Unfortunately, that doesn't really work. If I had the vertices in an object, I would know how to adjust the object using DirectionVector.to_track_quat('X', 'Z'). However, it is not possible for me to save the points in an object here. These must remain independent of each other in an array.
I know i have somehow to use the rotation matrix and translation matrix, but i don't know how.
Edit: I've added a blend file for a better understanding. My current code is included there. The emptys in this file should simulate the coordinate axes. I've also added the translation of the new coordinate system, not like before.
My new coordinate system and the incorrectly placed points:
Advice, suggestions, questions, or assistance are all welcome.