How to get ID of line closest to the given node using tcl?
Guys, how to get ID of line closest to the given node? Actually, I need to get IDs of 4 closest lines like in the situation shown in the figure below. I thought that I could create centroids of all possible lines, then find centroids that are closest to the given node, and then identify line IDs. But there is no function to get centroid of line. Thank you!
Best Answer
-
how about this API?
It would give you the distance and the line ID, but you need to give a list of lines as inoput.
hm_getdistancefromnearestline
Gets the distance of the given point from the nearest line with IDs specified as arguments.
Syntax
hm_getdistancefromnearestline point_xyz line_id_list
Type
HyperMesh Tcl Query Command
Description
Gets the distance of the given point from the nearest line with IDs specified as arguments.
Inputs
- point_xyz
- The list of x, y, z coordinates of the point.
- line_id_list
- List of line IDs.
Examples
The function returns a list consisting of two values. The first value is the distance to the closest line. The second value is ID of the closest line.
To get closest to the point with coordinates (10, 20, 30) point on the line with ID 13:
hm_getdistancefromnearestline [list 10 20 30] 13
To get closest line from the set with IDs 13 14 15:
hm_getdistancefromnearestline [list 10 20 30] [list 13 14 15]
To get closest to the node with ID 2 point on the line with ID 13:
hm_getdistancefromnearestline [hm_getvalue nodes id=2 dataname=coordinates] 13
0
Answers
-
how about this API?
It would give you the distance and the line ID, but you need to give a list of lines as inoput.
hm_getdistancefromnearestline
Gets the distance of the given point from the nearest line with IDs specified as arguments.
Syntax
hm_getdistancefromnearestline point_xyz line_id_list
Type
HyperMesh Tcl Query Command
Description
Gets the distance of the given point from the nearest line with IDs specified as arguments.
Inputs
- point_xyz
- The list of x, y, z coordinates of the point.
- line_id_list
- List of line IDs.
Examples
The function returns a list consisting of two values. The first value is the distance to the closest line. The second value is ID of the closest line.
To get closest to the point with coordinates (10, 20, 30) point on the line with ID 13:
hm_getdistancefromnearestline [list 10 20 30] 13
To get closest line from the set with IDs 13 14 15:
hm_getdistancefromnearestline [list 10 20 30] [list 13 14 15]
To get closest to the node with ID 2 point on the line with ID 13:
hm_getdistancefromnearestline [hm_getvalue nodes id=2 dataname=coordinates] 13
0 -
Adriano A. Koga_21884 said:
how about this API?
It would give you the distance and the line ID, but you need to give a list of lines as inoput.
hm_getdistancefromnearestline
Gets the distance of the given point from the nearest line with IDs specified as arguments.
Syntax
hm_getdistancefromnearestline point_xyz line_id_list
Type
HyperMesh Tcl Query Command
Description
Gets the distance of the given point from the nearest line with IDs specified as arguments.
Inputs
- point_xyz
- The list of x, y, z coordinates of the point.
- line_id_list
- List of line IDs.
Examples
The function returns a list consisting of two values. The first value is the distance to the closest line. The second value is ID of the closest line.
To get closest to the point with coordinates (10, 20, 30) point on the line with ID 13:
hm_getdistancefromnearestline [list 10 20 30] 13
To get closest line from the set with IDs 13 14 15:
hm_getdistancefromnearestline [list 10 20 30] [list 13 14 15]
To get closest to the node with ID 2 point on the line with ID 13:
hm_getdistancefromnearestline [hm_getvalue nodes id=2 dataname=coordinates] 13
Interesting! Yes, I can create one additional point and line, and then try to measure the distance between lines
hm_getdistancefromnearestline.
0 -
One more question: is it possible to get Line ID if I know the node ID which is on this line? Do we have some kind of function? Thank you!
0 -
Vladimir Gantovnik_21974 said:
Interesting! Yes, I can create one additional point and line, and then try to measure the distance between lines
hm_getdistancefromnearestline.
you don't need to create an extra point, as the fuction needs only the coordinates.
You can get the node coordinates with other hm commands and give them to this API.
0 -
Vladimir Gantovnik_21974 said:
One more question: is it possible to get Line ID if I know the node ID which is on this line? Do we have some kind of function? Thank you!
i don't know, honestly.
0 -
Adriano A. Koga_21884 said:
you don't need to create an extra point, as the fuction needs only the coordinates.
You can get the node coordinates with other hm commands and give them to this API.
Ok. It works! To close the question I give the final solution:
# consider node 71 set n 71 # get the coordinates of the node foreach {x y z} [join [hm_nodevalue $n]] {} puts "x=$x y=$y z=$z" # get all lines in the model *createmark lines 1 "all" set lines_list [hm_getmark lines 1] set results [hm_getdistancefromnearestline [list $x $y $z] $lines_list] set distance [lindex $results 0] set line_id [lindex $results 1] puts "min distance = $distance" puts "closest line ID = $line_id"
Output:
x=33.029 y=21.96 z=1.49 min distance = 3 closest line ID = 696
If I need the next closest line I will need to use operation (relative compliment) with sets and eliminate the first closest line from the all line sets set, and so on.
0 -
Adriano A. Koga_21884 said:
i don't know, honestly.
If it does not exist, Altair should create such a function Even if the node belongs to several lines it is still useful information. Line ID from node ID, surface ID from node ID, etc.
0 -
Adriano A. Koga_21884 said:
i don't know, honestly.
Ha-ha! I did it using the same function:
hm_getdistancefromnearestline
0