Search - User list
Full Version: Snap normal to nearest 45 degree angle in vex?
Root » Houdini Lounge » Snap normal to nearest 45 degree angle in vex?
Hey I'm pretty new to houdini and am trying to figure out what I think is probably a pretty basic setup.

If I have pointA and pointB and I calculate the normal from pointA to pointB as

vector posA = point(0, “P”, pointA);
vector posB = point(0, “P”, pointB);

vector dir = normalize(posA - posB);

this gives me the normal. how could I then snap that normal to the nearest 45 degree angle in x,y,z?

I hope what I'm asking makes sense. thanks

You can do something like this:

float getAngleBetweenVectors(vector v0; vector v1)
    vector v0n = normalize(v0);
    vector v1n = normalize(v1);
    return atan2(length(cross(v0n,v1n)), dot(v0n, v1n));

vector axes[]={{1,0,0},{0,1,0},{0,0,1}};

float ax = getAngleBetweenVectors(@N, axes[0]);
float ay = getAngleBetweenVectors(@N, axes[1]);
float az = getAngleBetweenVectors(@N, axes[2]);

float angles[] = array(ax, ay, az);

@N = axes[argsort(angles)[0]];
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB