hexagon logo

Find the closest node to a point

Hi everyone,
 
I am looking for a solution for finding the node of a mesh that is the closest node to a specific point.
Currently, my solution is to export the mesh and writing a specific small code in matlab for doing it but it is not very efficient.
 
Thank you in advance.
 
Best regards
  • There is an undocumented function in the utilities, give it try:
    Regards,
    Karl
    e.g::
     
    STRING node_list2[VIRTUAL]
     
    bv_get_closest_nodes_4.get( [0.5 0.6 0.7], 0.05,123, node_list2 )
     
    This should result in that the 123 closest nodes to location x=0.5, y=0.6, z=0.7
     
    So to find the closest node you may want to call:
     
    bv_get_closest_nodes_4.get( [0.5 0.6 0.7], 1.E8,1, node_list2 )
     
    Note that 1.E8 isn't used in this case. The tolerance is only used when max_find=0
  • Thank you. I obtain a weird result:
     
    $# The search will be done in an array with 439634 nodes.
    $# (PCL) Array too small Arg#,Size: [ 3 , 4 ]
    $# Call traceback...
    $#  Function COPY_NODES_SPECIAL_2
    $#  Function BV_GET_CLOSEST_NODES_4.GET, Line Number 200
    $# Execution aborted
     
    Does it mean that the function return no nodes?
  • I never has seen this kind of error. Maybe thery is a misundertanding about the usage.
     
    If you copy the following lines in a file with the extension ".ses" and run it with "file-session-play, you get 100 nodes around the center of a tetmeshed cube:
     
    STRING ids[VIRTUAL]
    asm_const_hpat_xyz("1","<1 1 1>","[0 0 0]","Coord 0",ids)
    $# 1 Hpat created: Hpat 1
     
    INTEGER fem_create_mesh_solid_num_nodes
    INTEGER fem_create_mesh_solid_num_elems
    STRING fem_create_mesh_s_nodes_created[VIRTUAL]
    STRING fem_create_mesh_s_elems_created[VIRTUAL]
    fem_create_mesh_sol_5( "Solid 1", "TetHybrid", "Tet10", 4, ["0.03", "0.1", @
    "0.2", "0.0"], 49232, 0, 1, 0, 1, 0.0049999999, "", "#", "#", "Coord 0", @
    "Coord 0", fem_create_mesh_solid_num_nodes, fem_create_mesh_solid_num_elems, @
    fem_create_mesh_s_nodes_created, fem_create_mesh_s_elems_created )
     
    db_commit()
     
    STRING node_list2[VIRTUAL]
    bv_get_closest_nodes_4.get( [0.5 0.5 0.5], 0.05,100, node_list2 )
    dump node_list2
     
  • There may be something of relevance in that old post- though it is slightly different. Hopefully @Karl Raedle​ , has given you some good guidance.
     
  • The undocumented function has a documented version:
     
    sgm_get_close_points() you can find it in the docs; the tricky thing with this function is you need to call it twice (first time to find out how many points there are) Then you redim your array to receive the result.
     
    sys_free_array(close_pts)
    sys_free_array(pt_dist)
    sys_allocate_array(close_pts,1,1) /* needed to stop error messages from PCL function */
    sys_allocate_array(pt_dist,1,1) 
     
    sgm_get_close_points(point, tol, 1, 0, 1, nclose, close_pts, pt_dist) /* get num_only */
     
    IF (nclose == 0) THEN RETURN
    sys_reallocate_array(close_pts,1,nclose) /* now can make the proper array */
    sys_reallocate_array(pt_dist,1,nclose)
     
    sgm_get_close_points(point, tol, 0, 0, 1, nclose, close_pts, pt_dist) /* get all data */
     
     
  • It occurs to me this will do the opposite; find a point closest to a node...
     
    But have no fear the next function is the docs is:
     
    sgm_node_on_point() you might similarly need to execute the function twice; first to count, then to get..