sample_direction_cone but on the maxangle instead of within?

   1410   3   1
User Avatar
Member
373 posts
Joined: June 2023
Offline
I have a vector X, and I'd like to randomly generate a vector Y so that the angle between X and Y is 60 degrees.

There is a VEX function sample_direction_cone that can generate a vector Y so that the angle between X and Y is no more than maxangle degrees.

But that's not what I need. I need the angle between X and Y to be exactly 60 degrees, not <= 60 degrees. How could I do that?
User Avatar
Member
9384 posts
Joined: July 2007
Offline
one of the ways
vector dir = {0,1,0};
float angle = radians(60);

vector rdir = sample_direction_cone(dir, PI/2, rand(@ptnum)); 
vector4 rot = quaternion(angle, normalize(cross(dir, rdir)));
v@N = qrotate(rot, dir);
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
5100 posts
Joined: Feb. 2012
Offline
Here is one way using matrices:

vector dir = @N;
float angle = radians ( ch("angle") );

float u = rand ( i + @ptnum * ( i + 14.2351 ) );
vector axis = sample_direction_cone ( dir, PI, u ); 

vector pdir = normalize ( cross ( dir, axis ) );
matrix M = ident ( );
rotate ( M, angle, pdir );

vector rdir = dir * M;

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
373 posts
Joined: June 2023
Offline
You people are VEX gods :o
  • Quick Links