Masoud Posted April 23 Share Posted April 23 Hi everyone, I'm trying to find the closest point on a primitive that's near a specific location, and then create a new point at that position. I’d appreciate any ideas to fix my codes. Thanks for helping. Add Point to Prim.hip Quote Link to comment Share on other sites More sharing options...
Librarian Posted April 23 Share Posted April 23 (edited) // RunOver: Detail vector a = point(1, "P", 0); vector b = point(1, "P", 1); vector ab = normalize(b - a); vector c = point(2, "P", 0); vector d = point(2, "P", 1); vector cd = normalize(d - c); vector ac = c - a; float d1 = (dot(ab, ac) - dot(ac, cd) * dot(ab, cd)) / (1 - dot(ab, cd) * dot(ab, cd)); vector p1 = a + ab * d1; int pt1 = addpoint(0, p1); float d2 = (dot(ab, ac) * dot(ab, cd) - dot(cd, ac)) / (1 - dot(ab, cd) * dot(ab, cd)); vector p2 = c + cd * d2; int pt2 = addpoint(0, p2); int prim = addprim(0, "polyline"); addvertex(0, prim, pt1); addvertex(0, prim, pt2); setpointattrib(0, "Cd", pt1, set(1,0.5,0)); setpointattrib(0, "Cd", pt2, set(1,0.5,0)); //printf('d1:' + sprintf('%g', d1) + '\n'); @Masoud Maybe Edited April 23 by Librarian Quote Link to comment Share on other sites More sharing options...
Masoud Posted April 24 Author Share Posted April 24 (edited) Hi Tesan, Thanks for sharing your code. When I run it on my end, the result looks like what’s shown in the image below. However, I’m having trouble understanding your key points and the intended workflow. It would be really helpful if you could attach your sample scene as well. That way, I can ensure I’m working with the same setup and getting the same results you're seeing. Also, I’m planning to run this over thousands of lines, so having a clear reference would really help streamline the process. Thanks in advance! Edited April 24 by Masoud Quote Link to comment Share on other sites More sharing options...
hannes603 Posted April 28 Share Posted April 28 find_near_prim_add_point_carve_simple.mp4 here a version without the code add_point_to_nearest_prim_simple_xyz_dist_carve.hip Quote Link to comment Share on other sites More sharing options...
Masoud Posted April 29 Author Share Posted April 29 Thank you, Hannes. I'm looking for the simplest and most efficient way to insert a point using VEX code. Specifically, if I can find a way to insert a point directly on an edge, that would effectively solve my problem. It seams inserting an extra point on an edge is so difficult in Houdini..! Quote Link to comment Share on other sites More sharing options...
hannes603 Posted April 29 Share Posted April 29 (edited) 6 hours ago, Masoud said: Thank you, Hannes. I'm looking for the simplest and most efficient way to insert a point using VEX code. Specifically, if I can find a way to insert a point directly on an edge, that would effectively solve my problem. It seams inserting an extra point on an edge is so difficult in Houdini..! not sure how to do it in vex.... but with the carve node its fairly simple.. https://www.sidefx.com/forum/topic/61435/ people on side fx : ''not worth the hassle*addPointOnCurve.hip Edited April 29 by hannes603 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.