# Geometry Nodes: aligning one vector to another

I have a vector A that continuously varies direction using simulation nodes. I try for vector B to always point antiparallel to A. My idea was to calculate the angle between vector A and B using the following formula:

To rotate B in the opposite direction, I thought to subtract the answer from 180 and then use this result as the rotation angle in a vector rotate node. However, I get stuck, because I don't know the correct settings of the vector rotate node.

I now have the following node tree:

Is it possible to use this method or should it be done in a different way? Thanks in advance :)

• I can't understand what you are trying to achieve. What does it mean, antiparallel? To reverse vector in opposite direction, just multiply it by (-1,-1,-1) Apr 13, 2023 at 19:46
• It means pointing in opposite direction. I don't want te reverse vector A in opposite direction but rotate B in the opposite direction of A.
– EwSa
Apr 13, 2023 at 19:54
• @Crantisz perhaps EwSa wants a rotational motion towards the desired vector, rather then immediately switching there. Without a rotational motion all you need is to use a Mix node to lerp, but for rotational take current vector and target vector to produce a cross product. This cross product is the axis of rotation in the Vector Rotate node (custom axis). Then rotate by some small angle, but remember to clamp the angle to at most current angle difference to avoid oscillating around that vector. Apr 13, 2023 at 19:55
• @MarkusvonBroady: tnx for your reply. To make it more clear: I have a velocity and a drag force. The drag force has to turn in the opposite direction of the velocity. The velocity could change direction so the drag force has to turn with it. I've tried the cross product of both vectors but this gives indeed the oscillating problem. Can you make clear what you mean with "clamp angle to at most current angle difference"?
– EwSa
Apr 13, 2023 at 20:01
• If you want it to behave physically with velocity etc. then you will get oscillation. The way oscillation is solved in simulations is just some kind of resistance usually simulated as simply multiplying the velocity by almost $1$ on each step, e.g. $0.99$ or $0.95$. This will still make an oscillation, just that the oscillation will die off. Otherwise you can base the resistance on the angle left, so with $1°$ left the multiplier would be $0.01$ Apr 13, 2023 at 20:06

the equation works. however, you are doing it wrong. (edit: looking back, you actually followed it correctly, except the fact that you converted it to degrees when you should of kept it as radians)

The equation

means A dot B, each divided by it's length, which is the same as normalizing them, so this is your equation: dot_product(normalize(A),normalize(B)), and then then take the arccosin, so: angle = arccosin(dot_product(normalize(A),normalize(B))). this will still leave you with the problem of no difference between negative and positive, so you compare the angles. so do something like this

I grabbed this image off discord since I'm not at pc; I hope it's good enough. instead of tangent use whatever axis you want (the axis is: around what axis are you measuring the angle around)

in truth there is already a node that does this in all 3 directions, and it's called align Euler to vector. (you might have to do some extra steps to get it to work exactly as you want, though.)

###### Edit:

Here is a simpler way (removing unnecessary operations and nodes) of the image above:
or
here you don't have to normalize because the arctan2 does.

and if you to compare the angle and rotate it around a specific axis do this:

• Tnx! This works like a charm :)
– EwSa
Apr 20, 2023 at 18:39
• And looks like a definitive reference for future questions like this one :) Apr 26, 2023 at 7:50

## Blender 4

Blender 4 introduces a new datatype Rotation, which represents a quaternion and is supported by the Mix node, making the rotations between two vectors very easy:

1. Convert Vectors to Eulers (Align Euler to Vector node).
2. Convert Eulers to Rotations.
3. Mix Rotations.
4. Convert the Rotations to what you need: either back to Eulers if you want to use it in Instance on Points node, or to Vectors using Rotate Vector node (it's the same as Vector Rotate except it takes a Rotation as input). As the rotated Vector, use either $$<1, 0, 0>$$, $$<0, 1, 0>$$ or $$<0, 0, 1>$$ depending if you used $$x$$, $$y$$, or $$z$$ alignment in p. 1.

Obviously for denormalized (length $$≠ 1$$) input vector(s), you may want to Vector Math: Scale the resulting vector by the Mix of input lengths…

• "Poor Man's Arrow" lol 😆 Oct 10, 2023 at 21:30
• Nice Markus! Tnx a lot for this supplement :)
– EwSa
Oct 11, 2023 at 14:02