Seeking your kind help on a VEX question...
I have a vector, and I'd like to find the ortho axis which is nearest to it, and whether it faces in the positive or negative direction on that axis - ie: one of six results.
Can anyone suggest a VEX solution, or point me in the right direction? (pun happily accepted : )
With thanks.
Which ortho axis is closest to this vector?
170 2 0- Mike_A
- Member
- 272 posts
- Joined: 8月 2018
- Online
- viklc
- Member
- 218 posts
- Joined: 5月 2017
- Offline
You could simply compare the distance to each ortho axis:
printf('------------ \n'); vector p = point(1, 'P', 0); addpoint(0, 0); addpoint(0, p); addprim(0, 'polyline', 0, 1); vector ort_axis = 0; float min_dist = 0; for (int i = 0; i < 6; ++i) { vector tmp = 0; tmp[i / 2] = (i % 2 * 2) - 1; float tmp_dist = distance(p, tmp); if (min_dist < tmp_dist) { min_dist = tmp_dist; ort_axis = floor(tmp * -1); } } printf('%d \n', ort_axis );
- animatrix_
- Member
- 4697 posts
- Joined: 2月 2012
- Online
Hi,
You can use the dot product to do this:
You can use the dot product to do this:
vector v = normalize ( chv("vec") ); vector dirs [ ] = array ( {1, 0, 0}, {0, 1, 0 }, {0, 0, 1} ); float maxdv = -1; vector nearestdir = 0; for ( int i = 0; i < len ( dirs ); ++i ) { float dv = dot ( v, dirs[ i ] ); float adv = abs ( dv ); if ( adv > maxdv ) { maxdv = adv; nearestdir = dv > 0 ? dirs [ i ] : -dirs [ i ]; } } int pt = addpoint ( 0, nearestdir ); setpointattrib ( 0, "N", pt, nearestdir );
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
-
- Quick Links