Jump to content

VEX: Point rotate around curve axis

Recommended Posts

Hi everyone,

With VEX, I try to rotate a point around the closest point of a curve.

It seems to work for the rotation but the axis is off! I have no idea how to fix that.

here is the file


Share this post

Link to post
Share on other sites

Hi Julien,

you need to first transform the point to its local coordinate space before applying the rotation. This is done via (@P-hit_P), then you apply the matrix and finally restore the transform to the world position by adding hit_P again.

vector @P;

// Get the nearest hit attributes
int hit_prim_id = -1;
vector hit_prim_uv;
vector hit_P = primuv(1,"P",hit_prim_id,hit_prim_uv);
vector hit_N = normalize(primuv(1,"N",hit_prim_id,hit_prim_uv));

// Rotate around the nearest hit point
matrix m = ident();
float angle = radians(ch('amount'));
rotate(m, angle, hit_N);
@P = (@P-hit_P) * m + hit_P;


I've gone ahead and updated your file. I've also switched to the xyzdist() instead of nearpoint() function to always get a smoothly interpolated Position and Normal.

If you have further questions let me know :)






  • Thanks 1

Share this post

Link to post
Share on other sites

Oh wow! That works perfectly! Thanks for all the explanations! :D :D

  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now