cross product: VEX vs Python

   4504   2   1
User Avatar
Member
15 posts
Joined: May 2014
Offline
I found a great post from a brilliant TD Marco Giordano working some normal magic.
http://www.marcogiordanotd.com/blog/cg-general/houdini-otl-normals-on-curve [marcogiordanotd.com]
He was kind enough to share is otl, which I promptly dissected to get a little more knowledge about the dark arts of vector math. My plan was to rebuild it using a Wrangle SOP…because…vex.

I streamlined the Python code he was using and converted it to vex and ended up getting troublesomely different results. See the attached hip file to see the steps I took and the results. Hopefully someone can illuminate and correct the issue. The speed difference between the two is remarkable. But it doesn't really matter if it doesn't work!

Attachments:
normalCrossTest.hip (80.3 KB)

User Avatar
Member
8582 posts
Joined: July 2007
Online
to just fix your code to compute with correct values you need to specify that @tan is vector using v@tan directly:

vector firstVec = {1,0,0};
vector cross1 = cross(firstVec,v@tan);
vector cross2 = cross(v@tan,cross1);
@N = normalize(cross2);
however if you want to have exactly the same result as that python code you have to iterate over points sequentially to avoid flipping (as next N depends on previous)
so change your AttribWrangle to Detail mode and use:
vector firstVec = {1,0,0};
for (int i=0;i<npoints(0);i++)
{
vector tan = point(0, “tan”, i);
vector cross1 = cross(firstVec,tan);
vector cross2 = cross(tan,cross1);
firstVec = normalize(cross2);
setpointattrib(0, “N”, i, firstVec);
}
considering that N attrib already exists, otherwise you would need to create it before or use addattribute to create it within wrangle;
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
15 posts
Joined: May 2014
Offline
Oh man, this is really a great breakdown.
Thanks so much for this. The python version was using the for loop, which I mistakenly assumed wasn't need in the vex version, now I realize the importance of the firstVec variable passing incrementally, which avoids the flipping.
I really appreciate it!
  • Quick Links