Navneet Arora Posted August 26, 2016 Share Posted August 26, 2016 hey guys, I need to figure out a way through which i can find the closest point distance between two different scattered surfaces. For example : There are some point scattered on a grid and a sphere. Then these points on grid need to go to the sphere and lock themselves but on the basis of closest distance found. If one point finds then closest neighbour on the target position then that point on the target position gets unavailable for other points to search for as it has been found by the source point. So this way we can tell the remaining points to search for next closest target. I have tried some ways using point cloud but it didnt help . Can somebody help me with this? Quote Link to comment Share on other sites More sharing options...
Juraj Posted August 26, 2016 Share Posted August 26, 2016 seems like a Sop Solver + Attrib Wrangle excrercise when I get some time during weekend I will try to assemble something Quote Link to comment Share on other sites More sharing options...
Navneet Arora Posted August 26, 2016 Author Share Posted August 26, 2016 sure man would love to see what you come up with. i think potential solution lies within point cloud and while loop. Quote Link to comment Share on other sites More sharing options...
Farmfield Posted August 26, 2016 Share Posted August 26, 2016 The functionality you are after is basically how the "connect adjacent pieces" SOP works in point mode - and you could probably mod that SOP to do what you are after. Quote Link to comment Share on other sites More sharing options...
Navneet Arora Posted August 26, 2016 Author Share Posted August 26, 2016 4 minutes ago, Farmfield said: The functionality you are after is basically how the "connect adjacent pieces" SOP works in point mode - and you could probably mod that SOP to do what you are after. hey johnny, could you show a demo file which could incorporate that? i mean i need to have point attracted to closest distance of target object Quote Link to comment Share on other sites More sharing options...
fencer Posted August 26, 2016 Share Posted August 26, 2016 (edited) how about this direction one_only_v001.hip Edited August 26, 2016 by fencer 1 Quote Link to comment Share on other sites More sharing options...
Atom Posted August 26, 2016 Share Posted August 26, 2016 (edited) What about something like this. It makes a unique 1:1 connection between two scatter sets based upon distance. It assumes each scatter has the same number of points. It creates a target_location, target_distance and target_id attributes on the source points. You can use these attributes to make a line between the source and the target or conduct further processing. source_node = hou.pwd() source_geo = source_node.geometry() target_node = hou.pwd().inputs()[1] #hou.node('/obj/sphere_target_points/scatter1') target_geo = target_node.geometry() source_count = len(source_geo.points()) target_count = len(target_geo.points()) attr_location = source_geo.addAttrib(hou.attribType.Point, "target_location", (0.0, 0.0, 0.0)) attr_distance = source_geo.addAttrib(hou.attribType.Point, "target_distance", 1000000.0) attr_target_id = source_geo.addAttrib(hou.attribType.Point, "target_id", -1) if target_count >= source_count: # We need at least as many targets as we have source points. (caveat #1). lst_target_id_taken = [] for j,source_point in enumerate(source_geo.points()): # Scan every target point looking for the smallest distance. v = source_point.attribValue('P') p1 = hou.Vector3((v[0],v[1],v[2])) current_distance = source_point.attribValue('target_distance') for i, target_point in enumerate(target_geo.points()): if i in lst_target_id_taken: # Already taken, skip. pass else: # Could be our nearest target. v = target_point.attribValue('P') p2 = hou.Vector3((v[0],v[1],v[2])) dist = p1.distanceTo(p2) if dist < current_distance: candidate_location = p2 candidate_distance = dist candidate_id = i current_distance = dist source_point.setAttribValue("target_location", candidate_location) source_point.setAttribValue("target_distance", candidate_distance) source_point.setAttribValue("target_id", candidate_id) lst_target_id_taken.append(candidate_id) ap_source_target_distance_1a.hiplc Edited August 26, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
bonsak Posted August 26, 2016 Share Posted August 26, 2016 Here's another variant. Not super fast but it works. Tried to get removepoint() to work in a wrangle instead of delete inside the solver couldn't make it work. Thought maybe removepoint() would be faster than the delete nodes. -b closest-point.hiplc Quote Link to comment Share on other sites More sharing options...
Malf Posted August 27, 2016 Share Posted August 27, 2016 Also another way to go about it. One wrangle running in detail mode is finding the point to match to and then the one below is doing a simple position lerp. Hope it helps. Cheers Jake. matchClosestPoint.hipnc Quote Link to comment Share on other sites More sharing options...
Juraj Posted August 27, 2016 Share Posted August 27, 2016 Hi, here is my try with very simple crowd-like particle system jt_closest_crowd.hipnc Quote Link to comment Share on other sites More sharing options...
Navneet Arora Posted August 29, 2016 Author Share Posted August 29, 2016 On 8/26/2016 at 10:31 PM, Atom said: What about something like this. It makes a unique 1:1 connection between two scatter sets based upon distance. It assumes each scatter has the same number of points. It creates a target_location, target_distance and target_id attributes on the source points. You can use these attributes to make a line between the source and the target or conduct further processing. source_node = hou.pwd() source_geo = source_node.geometry() target_node = hou.pwd().inputs()[1] #hou.node('/obj/sphere_target_points/scatter1') target_geo = target_node.geometry() source_count = len(source_geo.points()) target_count = len(target_geo.points()) attr_location = source_geo.addAttrib(hou.attribType.Point, "target_location", (0.0, 0.0, 0.0)) attr_distance = source_geo.addAttrib(hou.attribType.Point, "target_distance", 1000000.0) attr_target_id = source_geo.addAttrib(hou.attribType.Point, "target_id", -1) if target_count >= source_count: # We need at least as many targets as we have source points. (caveat #1). lst_target_id_taken = [] for j,source_point in enumerate(source_geo.points()): # Scan every target point looking for the smallest distance. v = source_point.attribValue('P') p1 = hou.Vector3((v[0],v[1],v[2])) current_distance = source_point.attribValue('target_distance') for i, target_point in enumerate(target_geo.points()): if i in lst_target_id_taken: # Already taken, skip. pass else: # Could be our nearest target. v = target_point.attribValue('P') p2 = hou.Vector3((v[0],v[1],v[2])) dist = p1.distanceTo(p2) if dist < current_distance: candidate_location = p2 candidate_distance = dist candidate_id = i current_distance = dist source_point.setAttribValue("target_location", candidate_location) source_point.setAttribValue("target_distance", candidate_distance) source_point.setAttribValue("target_id", candidate_id) lst_target_id_taken.append(candidate_id) ap_source_target_distance_1a.hiplc hey , thanks for finding time and trying this. i tried using this but it doesnt seem to work as it doesnt seem to snap to closest point, can you try once and let me know if i am wrong? Quote Link to comment Share on other sites More sharing options...
Navneet Arora Posted August 29, 2016 Author Share Posted August 29, 2016 On 8/27/2016 at 9:07 AM, Malf said: Also another way to go about it. One wrangle running in detail mode is finding the point to match to and then the one below is doing a simple position lerp. Hope it helps. Cheers Jake. matchClosestPoint.hipnc Hey Malf, Thanks for the time you put into this, But the points seem to cris cross each other which shouldn't be the case if we are looking for closest point. otherwise it is a good method. Quote Link to comment Share on other sites More sharing options...
Navneet Arora Posted August 29, 2016 Author Share Posted August 29, 2016 On 8/26/2016 at 8:52 PM, Juraj said: seems like a Sop Solver + Attrib Wrangle excrercise when I get some time during weekend I will try to assemble something Awesome technique it is, not what iam looking for but definitely worth a watch, Kudos Mate!. 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.