# 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 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 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 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 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 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)

Here is a simpler way (removing unnecessary operations and nodes) of the image above: and if you to compare the angle and rotate it around a specific axis do this: 