0
$\begingroup$

The best way I can really explain this is, in a 2D space, two lines are parallel when you can draw a perpendicular line between both of them. In a 3D space, if you have two surfaces that are facing each other exactly, you could draw a normal between them (except when put into function, since both objects have normals, one of them would have to be the opposite of the other, so they could face each other).

For example:

example_1

It's easy enough to do in rotations like that, but with rotations like this, it's not as easy:

example_2

I want to rotate the cone so its base is 'parallel in 3D' and facing the side of the cube. The thing is though, I need a fairly quick method of doing this because I need to do this many, many times.

$\endgroup$
2
$\begingroup$

If you know the 3D coordinates of both unit-length normals $\hat n_1$ and $\hat n_2$ -- both expressed in the same coordinate system (e.g. global), and you want to rotate the object owner of $\hat n_2$, you have to rotate around axis:

$$ \hat u = \hat n_1 \times \hat n_2 $$

by an angle

$$ \alpha = \pi - (\hat n_1 \cdot \hat n_2) $$

In Python:

def rotateObjectSoNormalsOppose(obj, n1, n2):
    '''
    Rotate object so n2 is parallel and opposite to n1

    @param obj (bpy.type.Object) Object to rotate
    @param n1  (mathutils.Vector) Unit-left normal used as reference (in global coordinates)
    @param n2  (mathutils.Vector) Unit-left normal to rotate (in global coordinates)
    @return The rotated object
    '''
    # Compute axis of rotation
    u = n1.cross(n2)
    # Angle of rotation
    alpha = pi - acos(n1.dot(n2))
    # 3x3 rotation matrix
    rot = Matrix.Rotation(alpha, 3, u)

    # Get current orientation of object
    curr_orientation = obj.matrix_world
    # apply delta rotation to obtain the new orientation
    obj.matrix_world = curr_orientation @ rot.to_4x4()

    return obj

where rot is a 3x3 rotation matrix that will rotate the owner of $\hat n_2$ so that $\hat n'_2$ will be parallel but opposite to $\hat n_1$.

$\endgroup$
1
$\begingroup$

Depends on what exactly you are doing, but one idea might be to separate the objects. If they are rotated in object mode rather than edit mode, you can then use ctrl-C to copy the rotation of one to the other (if you activate the Copy Attributes add-on first).

If you have a load of elements like this combined and rotated within edit mode then I'm not sure how you would do it I'm afraid.

$\endgroup$
  • $\begingroup$ I'm trying to make a mesh of a head have tiny cones facing outwards from each face. Then I'm going to delete the face and so I have a spikey '3D silhouette' of the mesh. $\endgroup$ – thepufferfish Apr 17 at 3:40
  • $\begingroup$ Ah, well that's relatively easy. Just parent the cone to the head and then go to the Object menu in the properties window, expand Instancing sub-menu and select Faces. That's assuming you are using 2.80. In 2.79 it's Object/Duplication/Faces. $\endgroup$ – edna Apr 20 at 14:45
  • $\begingroup$ Mess around with the origin of the cone, to make it appear where you want,relative to the faces. Search for 'duplifaces' to find other info related to this, as it has been around for ages so the internet is probably awash with tutorials and things now that you know what to search for. $\endgroup$ – edna Apr 20 at 14:48

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.