Get point id from coordinates

Moderator: GiD Team

JFlock_BE
Posts: 6
Joined: Thu Jul 11, 2019 6:57 am

Get point id from coordinates

Postby JFlock_BE » Wed Apr 22, 2020 3:47 pm

Hello,

Is it possible to know if there is a point at a given coordinates x,y,z (taken into account a given tolerance) in tcl ?
If yes, is it possible to get its id ?

Thanks for your help !
User avatar
escolano
Posts: 1628
Joined: Thu Sep 18, 2014 3:31 pm

Re: Get point id from coordinates

Postby escolano » Thu Apr 23, 2020 9:02 pm

No, it doesn't exists any GiD_Tcl command to get the closest or a list of points or other entities close to a center in a radius
Also we don't provide Tcl commands to wrap any 'finding structure' (like octree, kd-tree, bin, etc.) to do this kind of 3D space find efficiently

You must ask with Tcl entities data, and do this find by yourself, by brute-force (a loop over all entities) or using some more advanced data structure.

for small models or few finds the brute force solution could be enough

Note:
In the voro plugin once i have auxiliary used an vtkKdTree object (provided by the vtk Tcl package that we include in GiD to import/export vtk files)
to find points using this data structure.
Can see my code at <GiD>\plugins\Geometry\voro\voro.tcl
find inside the "vtkKdTree" word"
JFlock_BE
Posts: 6
Joined: Thu Jul 11, 2019 6:57 am

Re: Get point id from coordinates

Postby JFlock_BE » Fri Apr 24, 2020 10:17 am

Thanks for your answer, this is what I was thinking unfortunately.

I will check the voro plugin !

Thanks again !
User avatar
escolano
Posts: 1628
Joined: Thu Sep 18, 2014 3:31 pm

Re: Get point id from coordinates

Postby escolano » Fri Apr 24, 2020 10:40 am

A bruce-force version is easy to write, e.g:

Code: Select all

proc GetClosestPointBruteForce { x y z tolerance } {
    set min_point_id -1
    set coordinate_find [list $x $y $z]   
    set mind_d2 1e30
    foreach poin_id [GiD_Geometry list point] {
        set point_xyz [lrange [GiD_Geometry get point $poin_id] 1 3]
        set d2 [MathUtils::VectorDistance2 $point_xyz $coordinate_find]
        if { $mind_d2>$d2 } {
            set mind_d2 $d2
            set min_point_id $poin_id
        }
    }
    if { $min_point_id != -1} {
        set mind_d [expr sqrt($mind_d2)]
        if { $mind_d > $tolerance } {
            set min_point_id -1
        }
    }
    return $min_point_id
}
JFlock_BE
Posts: 6
Joined: Thu Jul 11, 2019 6:57 am

Re: Get point id from coordinates

Postby JFlock_BE » Fri Apr 24, 2020 2:13 pm

Thanks for that, it could be usefull !

But most of the time, there are a lot of nodes (for instance, the model on which I currently work has more than 11 000 nodes... ) So I will try the solution with the vtkKdTree objects.

I was thinking also to use the GiD collapse function to know if there are points on a given coordinate (create new points wiht the given x,y,z and then collapsing all points and check if some points are deleted or not) but is it possible to get the id of deleted entities after collapsing ?


Thanks for your time.
User avatar
escolano
Posts: 1628
Joined: Thu Sep 18, 2014 3:31 pm

Re: Get point id from coordinates

Postby escolano » Fri Apr 24, 2020 7:36 pm

11000 nodes is a relativelly small model
Note: my example code was made for geometry point, not for mesh nodes (must do some change to ask for mesh nodes)
JFlock_BE
Posts: 6
Joined: Thu Jul 11, 2019 6:57 am

Re: Get point id from coordinates

Postby JFlock_BE » Mon Apr 27, 2020 7:11 am

Yes 11k nodes is relatively small but I meant 11k points befor meshing, my fault sorry.

Many thanks for all your help.

Return to “Geometry”

Who is online

Users browsing this forum: No registered users and 1 guest