{"id":429,"date":"2019-11-21T11:44:29","date_gmt":"2019-11-21T19:44:29","guid":{"rendered":"http:\/\/fx-td.com\/houdiniandchill\/?p=429"},"modified":"2019-11-21T11:50:54","modified_gmt":"2019-11-21T19:50:54","slug":"archived-post-by-thomas-helzle-2","status":"publish","type":"post","link":"http:\/\/fx-td.com\/houdiniandchill\/2019\/11\/21\/archived-post-by-thomas-helzle-2\/","title":{"rendered":"Archived post by Thomas Helzle"},"content":{"rendered":"<p class=\"\">In case anybody is interested: I adapted the adjustPrimLength from groom.h to work in the other direction: &#8220;`void adjustPrimLengthInv(const int geo, prim; const float currentlength, targetlength) {     float diff = targetlength &#8211; currentlength;     int points[] = primpoints(geo, prim);     if(diff < 0)     {         vector lastpos = 0;         float length = 0;         int numpt = len(points);\n        for(int idx = numpt-1; idx >= 0; idx&#8211;)         {             int pt = points[idx];             vector pos = point(geo, &#8220;P&#8221;, pt);             if(idx < numpt-1)             {                 float seglength = distance(pos, lastpos);\n                if(length+seglength > targetlength)                 {                     float frac = (targetlength-length)\/seglength;<br \/>\n                    vector newpos = lerp(lastpos, pos, frac);                     setpointattrib(0, &#8216;P&#8217;, pt, newpos, &#8216;set&#8217;);                                          for(int i=idx-1; i>=0; i&#8211;) {                         removepoint(geo, points[i]);                     }<br \/>\n                    break;                 }<br \/>\n                length += seglength;             }<br \/>\n            lastpos = pos;         }     } }&#8220;`<\/p>\n<p class=\"\">So between the normal version and this one I can scale polylines smoothly from both sides.<\/p>\n<p class=\"\">Oh and I removed the extension part, I never want the lines to become longer. So below is the modified and simplified standard version:<\/p>\n<p class=\"\">&#8220;`void adjustPrimLength(const int geo, prim; const float currentlength, targetlength) {     float diff = targetlength &#8211; currentlength;     int points[] = primpoints(geo, prim);     if(diff < 0)     {         vector lastpos = 0;         float length = 0;\n        foreach(int idx; int pt; points)         {             vector pos = point(geo, \"P\", pt);             if(idx > 0)             {                 float seglength = distance(pos, lastpos);<br \/>\n                if(length+seglength > targetlength)                 {                     float frac = (targetlength-length)\/seglength;<br \/>\n                    vector newpos = lerp(lastpos, pos, frac);<br \/>\n                    int ptnum = addpoint(geo, newpos);<br \/>\n                    for(int i=idx; i<len(points); i++)                         removepoint(geo, points[i]);\n                    addvertex(geo, prim, ptnum);\n                    break;                 }\n                length += seglength;             }\n            lastpos = pos;         }     } }```<\/p>\n<p class=\"\">Just put it in a primitive wrangle, grab your currentlength with: `float currentlength = primintrinsic(0, &#8216;measuredperimeter&#8217;, @primnum);` and cut away&#8230; \ud83d\ude42<\/p>\n<p class=\"\">Oh and this is in actual lengths, so if you want to cut away half your line, targetlength would be currentlength * 0.5&#8230;<\/p>\n<p class=\"\">I love doing all this in a wrangle since it&#8217;s more flexible than carve<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In case anybody is interested: I adapted the adjustPrimLength from groom.h to work in the other direction: &#8220;`void adjustPrimLengthInv(const int geo, prim; const float currentlength, targetlength) { float diff = targetlength &#8211; currentlength; int points[] = primpoints(geo, prim); if(diff < 0) { vector lastpos = 0; float length = 0; int numpt = len(points); for(int &hellip; <a href=\"http:\/\/fx-td.com\/houdiniandchill\/2019\/11\/21\/archived-post-by-thomas-helzle-2\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Archived post by Thomas Helzle<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/posts\/429"}],"collection":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/comments?post=429"}],"version-history":[{"count":0,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/posts\/429\/revisions"}],"wp:attachment":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/media?parent=429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/categories?post=429"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/tags?post=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}