{"id":401,"date":"2019-10-02T03:21:05","date_gmt":"2019-10-02T10:21:05","guid":{"rendered":"http:\/\/fx-td.com\/houdiniandchill\/?p=401"},"modified":"2019-10-02T03:21:06","modified_gmt":"2019-10-02T10:21:06","slug":"archived-post-by-sniperjake945","status":"publish","type":"post","link":"http:\/\/fx-td.com\/houdiniandchill\/2019\/10\/02\/archived-post-by-sniperjake945\/","title":{"rendered":"Archived post by SniperJake945"},"content":{"rendered":"<p class=\"\">I donno how many people here have every tried converting to and from barycentric coordinates, but assuming you can project your triangle so that all points lie on the x and y axis (this is easy peasy with dihedral), this is my favorite method of finding where a point is within a triangle:<br \/>\n&#8220;`c \/\/pts is the three points in your triangle matrix3 gen_bary_mat(vector pts[]){     matrix3 m = set(                 pts[0].x, pts[0].y, 1,                 pts[1].x, pts[1].y, 1,                 pts[2].x, pts[2].y, 1);     return m; } vector tri_pts[] = array({10, 4, 1}, {3,2,1}, {0, 10, 1}); vector test_pt = {6, 5, 1}; matrix3 bary_matrix = gen_bary_mat(tri_pts); vector bary_pt = test_pt * invert(bary_matrix);  \/\/solution by inversion, this is big brain  printf(&#8220;bary coords: %g \\n&#8221;, bary_pt); &#8220;`<\/p>\n<p class=\"\">this means u can pre-compute the transformation needed to project a point into bary coords<\/p>\n<p class=\"\">which is realllllllllllllllllllllllllllllllllllly fuckin nice if u need to do that a bunch<\/p>\n<p class=\"\">this also extends to tets as well, but it&#8217;d be a 4&#215;4 matrix instead of a 3&#215;3<\/p>\n<p class=\"\">it helps if everything is actually aligned to the z-1 axis, so if z is set to 1, then you can invert the solution as well to convert back to cartesian coordinates<\/p>\n<p class=\"\">i like to do my triangle projection with dihedral so u don&#8217;t have to worry about any kind of scaling being applied to the triangle, like so:<br \/>\n&#8220;`c \/\/this would gooooooooooooo in a prim wrangle, and then ud call the resulting trs matrix in a point wrangle to apply the positional changes \/\/big brain  matrix3 m = dihedral(<a href=\"mailto:v@N\" >v@N<\/a>, set(0,0,1)); matrix trs = m; matrix mov_to_orig = ident(); matrix mov_z = ident();<br \/>\ntranslate(mov_to_orig, <a href=\"mailto:v@P\" >v@P<\/a>); translate(mov_z, set(0,0,1));<br \/>\ntrs = invert(mov_to_orig) * m * mov_z; &#8220;`<\/p>\n<p class=\"\">iono how useful this is, but ive had to do this kind of stuff a lot on one of the projects im working on<\/p>\n<p class=\"\">so i thought id share it<\/p>\n<p class=\"\"><a href=\"https:\/\/en.wikipedia.org\/wiki\/Barycentric_coordinate_system#Conversion_between_barycentric_and_Cartesian_coordinates\">en.wikipedia.org\/wiki\/Barycentric_coordinate_system#Conversion_between_barycentric_and_Cartesian_coordinates<\/a> the matrix form comes from the bottom of this section. solution by inversion is just the easiest way of solving that system in houdini currently. especially since it&#8217;s a 3&#215;3<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I donno how many people here have every tried converting to and from barycentric coordinates, but assuming you can project your triangle so that all points lie on the x and y axis (this is easy peasy with dihedral), this is my favorite method of finding where a point is within a triangle: &#8220;`c \/\/pts &hellip; <a href=\"http:\/\/fx-td.com\/houdiniandchill\/2019\/10\/02\/archived-post-by-sniperjake945\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Archived post by SniperJake945<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/posts\/401"}],"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=401"}],"version-history":[{"count":0,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/posts\/401\/revisions"}],"wp:attachment":[{"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/media?parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/categories?post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fx-td.com\/houdiniandchill\/wp-json\/wp\/v2\/tags?post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}