1
$\begingroup$

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: Blender_3-24-19_how_to_align_2_to_1

$\endgroup$
3
$\begingroup$

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:

  1. Create a Custom Transform Orientation from the target (stationary) object. (Orientation dropdown in the header, '+' with target selected)
  2. With the source (moving) object selected, Object Menu > Transform > 'Align to Transform Orientation'. Now your objects rotations should be the same.
  3. 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.

$\endgroup$
  • $\begingroup$ I've tried every combination of what you describe there I think, but I cannot get the "boards" to exactly line up side by side easily. So what I'm looking for is a very simple snapping solution, with a specific series of steps to get board two to sit exactly side by side with board one, without having to reposition board one. I thought by figuring out how to accomplish this goal in a context where board one is in a kind of random location and rotation, that I might then be much better prepared to deal with snapping objects together in general. Thanks for the ideas. $\endgroup$ – frew Mar 25 at 13:56
  • 1
    $\begingroup$ My bad, actually your step by step here works so simply and easily The first time I tried it I did it wrong. This is the snapping solution I was looking for, thanks so much! The part that I was missing, that I did not know about, was the part you mentioned "Object Menu > Transform > 'Align to Transform Orientation'", nice. $\endgroup$ – frew Mar 25 at 14:17
  • $\begingroup$ @frew Sorry, probably not clear enough before edit. Thanks. $\endgroup$ – Robin Betts Mar 25 at 14:19
2
$\begingroup$

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 bpy.context)

>>> p1 = C.object

then select plank2 in 3D view,

>>> p2 = C.object

Check, correct planks assigned to variables p1 and p2

>>> p1, p2
(bpy.data.objects['Cube.036'], bpy.data.objects['Cube.037'])

Match transforms,

>>> 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.

$\endgroup$
  • $\begingroup$ Hi, I'm not familiar with coding, so I may not delve into this way at this time. A question I have though is when you say "Translate (move) plane 2 along local y by its y dimension it will be "side by side"" is that a manual move with G, because if so then I am relying upon by eye, but what I want is the lengthwise side faces of the "boards" to have their faces exactly "touch" each other, like with snapping, not just close or overlapping at all, but lengthwise side faces matching exact same plane as each other, thanks for the ideas. $\endgroup$ – frew Mar 25 at 13:46
  • $\begingroup$ "Now we translate plank2 by its y dimension in the local y axis direction", I think if the object y dimension is somewhat random, then I have to go and figure out that dimension somehow first, to have them sit side by side exactly. I like these options you present, but I was hoping for a very simple, step by step snapping solution. Thanks again for the ideas. Maybe I'll explore that further sometime. $\endgroup$ – frew Mar 25 at 14:03
  • $\begingroup$ Minor edit. Now they will be exactly side by side with different y dimensions. $\endgroup$ – batFINGER Mar 26 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.