galagast Posted December 19, 2016 Share Posted December 19, 2016 I have a curve with a polyFrame SOP set to create tangentv (yellow). But I was hoping that the vectors were averaged (except for the first and last points). So far, I was able to wrangle something, which currently works for what I want (green). I was just wondering if there was a simpler method (just for learning purposes)? Any insights would be very helpful. Thanks! avg_tangents_v1.hiplc Quote Link to comment Share on other sites More sharing options...
Guest tar Posted December 19, 2016 Share Posted December 19, 2016 (edited) Bitangent - two edges? avg_tangents_v1.hiplc.hipnc Edited December 19, 2016 by tar Quote Link to comment Share on other sites More sharing options...
galagast Posted December 19, 2016 Author Share Posted December 19, 2016 (edited) Hey Marty, thanks for the reply. I did try those before.. but I noticed that it is missing some sort of normalization. As an example, if the "Two Edges" are of equal length, I get the desired result: But if they are not equal: The tangent leans more towards the longest edge. It would be great if the PolyFrame SOP maybe had a checkbox that would normalize the edges. I guess I could try and send an RFE a bit later after getting/hearing more feedback regarding this topic :-) Houdini Indie H15.5.673 avg_tangents_v2.hiplc Edited December 19, 2016 by galagast Quote Link to comment Share on other sites More sharing options...
eetu Posted December 19, 2016 Share Posted December 19, 2016 That's probably how I would've done it, but if you want something different you could piggyback on polyextrude. avg_tangents_e1.hip 1 Quote Link to comment Share on other sites More sharing options...
galagast Posted December 19, 2016 Author Share Posted December 19, 2016 Clever approach eetu! Quote Link to comment Share on other sites More sharing options...
acey195 Posted December 22, 2016 Share Posted December 22, 2016 (edited) or you can do it using your own Polyframe implementation: or the wrangle conversion I made of that (runs in primitive mode): float displace = ch("displace"); int closed = primintrinsic(0,"closed",@primnum); for(int i=0;i<@numvtx;i++) { int pt = vertexpoint(0,vertexindex(0,@primnum,i)); int pt0 = vertexpoint(0,vertexindex(0,@primnum,(i+1)%@numvtx)); int pt1 = vertexpoint(0,vertexindex(0,@primnum,(i-1)%@numvtx)); vector ptP = point(0,"P",pt); vector pt0P = point(0,"P",pt0); vector pt1P = point(0,"P",pt1); vector dir0 = normalize(pt0P-ptP); vector dir1 = normalize(ptP-pt1P); vector up = normalize(cross(dir0,-dir1)); vector avDir = normalize(dir0+dir1); if(!closed) { if(i==0) avDir = dir0; if(i==@numvtx-1) { avDir = -dir1; dir0 = dir1; } } float dot = dot(dir0,avDir); vector tangent = normalize(cross({0,1,0},avDir))/dot; setpointattrib(0,"P",pt,ptP+tangent*displace,"set"); } if you just want the tangent replace the last 3 lines with (ofcourse), depending of your H version you may need to pregenerate a N attribute: setpointattrib(0,"N",pt,normalize(cross({0,1,0},avDir))/dot); } Edited December 22, 2016 by acey195 4 Quote Link to comment Share on other sites More sharing options...
galagast Posted December 22, 2016 Author Share Posted December 22, 2016 (edited) Awesome Twan! These are great! Thank you so much I love that you added handling of open and closed curves. I also just realized that by doing that in primitive mode, you also covered handling of multiple line primitives! Cool! Lastly, on my earlier attempts, I was scratching my head trying to figure out why upon displacing the points, their distances seems to vary.. After looking at your vex code, I noticed that i just had to divide the tangent by the the dot product! >__< Edited December 22, 2016 by galagast learned a lot! Quote Link to comment Share on other sites More sharing options...
galagast Posted December 22, 2016 Author Share Posted December 22, 2016 @acey195: A small question regarding your code.. you created an up vector (in line 17), but did not use it elsewhere. I tried replacing line 32 from this: vector tangent = normalize(cross({0,1,0},avDir))/dot; to this: vector tangent = normalize(cross(up,avDir))/dot; But it seems it is not the way to go, as some displacements were flipped. I also tried to compare it against the result of a polyExtrude (with the same amount of displacement/extrusion): It is just a minor thing, it got me curious how polyExtrude does its tangent calculation. Quote Link to comment Share on other sites More sharing options...
acey195 Posted December 22, 2016 Share Posted December 22, 2016 If you have shape that is not aligned with the XZ plane, you could use the custom up vector, but then it does become important in which direction the curve is drawn. Or maybe I just put the cross product arguments in the wrong order. About the difference with the polyextrude... I have no idea Quote Link to comment Share on other sites More sharing options...
galagast Posted December 22, 2016 Author Share Posted December 22, 2016 (edited) Haha no worries man, I'll just play around this a bit more. I have already learned quite a lot from it. Thank you again EDIT: Setting the up vector to absolute seems to have fixed the flipping. (at line 17) vector up = abs(normalize(cross(dir0,-dir1))); I like that it produces a more sensible result in that the tangents are properly oriented, but it still does not match polyExtrude's version. Using a constant {0,1,0} for up is still a much closer match. Edited December 22, 2016 by galagast found fix for flipping Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.