Masoud Posted Wednesday at 04:18 PM Share Posted Wednesday at 04:18 PM 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 Wednesday at 07:59 PM Share Posted Wednesday at 07:59 PM (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 Wednesday at 08:15 PM by Librarian Quote Link to comment Share on other sites More sharing options...
Masoud Posted 21 hours ago Author Share Posted 21 hours ago (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 21 hours ago by Masoud 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.