can anyone tell me the best way to exactly align plane 2 to the side of plane 1 in this blend file. It's like they are 2x4 lumber. Imagine plane 1 is in a fixed position, and my task is to line up plane 2 exactly side by side to plane 1. I made all the locations and rotations random just to see the best way to align plane 2 with an arbitrary location and rotation of plane 1. Thanks for any ideas for me to try. Here's the .blend file:
Since these object's local axes are both aligned to their meshes, you can use standard align and snapping tools.. in 2.8, all in Object Mode:
- Create a Custom Transform Orientation from the target (stationary) object. (Orientation dropdown in the header, '+' with target selected)
- With the source (moving) object selected, Object Menu > Transform > 'Align to Transform Orientation'. Now your objects rotations should be the same.
- Move the source object roughly into place, and with Snap (ShiftCtrlTab) set to 'Vertex', 'Closest' , with Align to Rotation switched off, snap the source object into place.
2.8 has lost a lot of standard keymaps, which makes this harder to describe than in 2.79.
Scripting & theory.
Assign the matrix world of plank 1 to plank 2 and both will have the same transform, akin to adding a copy transform constraint.
Translate (move) plane 2 along local y by its y dimension it will be "side by side". (Going by axes in question. Using x would be "end to end" and z stacking "top to bottom")
Test in python console, have two objects akin to question, "Cube.036" is my "plank1" and "Cube.037" as "plank2".
Select plank1, ie make it active in 3d view, then type following in py console (
C is a convenience variable for
>>> p1 = C.object
then select plank2 in 3D view,
>>> p2 = C.object
Check, correct planks assigned to variables
>>> p1, p2 (bpy.data.objects['Cube.036'], bpy.data.objects['Cube.037'])
>>> p2.matrix_world = p1.matrix_world
p2 now overlays
p1. Next move along local y axis (direction of G Y Y in UI) The vector representing the local y axis
>>> y_axis = Vector((0, 1, 0))
A matrix world is a 4x4 matrix, the 3x3 part is the rotation. Multiplying 3x3 matrix by y_axis is Rotating the axis such that it is converted to global coordinates. Normalizing makes it unit length
>>> dy = (p1.matrix_world.to_3x3() @ y_axis).normalized()
Now we translate plank2 by its y dimension in the local y axis direction (eg if both have y dimension is 2 would be akin to G Y Y 2in UI)
If the two objects have different y dimension, then the distance apart will be the sum of half of dimension of each.
>>> p2.matrix_world.translation += 0.5 * (p1.dimensions.y + p2.dimensions.y) * dy
now the planks are exactly side by side.