# How can I rotate a vector to another one, using VEX?

## Recommended Posts

Hello guys,

Using VEX, how can I rotate a vector to another vector, by a blend value from zero to one (i.e 1=fully aligned, 0= not-aligned)?

Thanks for helping.

##### Share on other sites

Hi Masoud,

to blend orientations two orthogonal vectors are required for each point: one normal, one up. For this you could use the polyframe node or a cross() product.
maketransform() converts these vectors into a matrix that is to be turned into a quaternion().

```matrix3 xform = maketransform(v@up, v@N);
vector4 orient = quaternion(xform);```

slerp(), spherical linear interpolation, then blends between both orientations:

```float blend = chf('blend');
vector4 orient_1 = point(0, 'orient', 1);
vector4 orient_2 = point(0, 'orient', 2);
p@orient = slerp(orient_1, orient_2, blend);```

blend_orientations.hiplc

##### Share on other sites

Hi Konstantin;

Actually, I want to rotate scattered points' Normal to another direction (i.e. MyVector) using a blend amount.

At first, I tried the lerp() function but instead of rotation, it blends them.

Then I tried:

```float angle = chf("Angle");
v@N = qrotate(rot, @N);```

But it rotates the Normal around "My-Vector"!

Here is an image of what I need:

Edited by Masoud
##### Share on other sites

@Masoud Maybe it Helps!

Edited by Librarian
##### Share on other sites

Hi Tesan,

Than you.

Yes, it works fine:

```vector4 q1 = quaternion(@N);
vector4 q2 = dihedral(v@N, v@targetVector);
vector4 quat = slerp( q1, q2, chf("bias"));
v@N = qrotate(quat, v@N);```

##### Share on other sites

You are welcome @Masoud
Check This

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×