Page 1 of 1

Drawing vertical line between points with same xy in different z

Posted: Sun May 29, 2022 4:51 pm
by najafi
Hi
I'm new in GiD modelling :) .
Is there any script or macro that I being able to automatically draw vertical line (i.e. in z direction) between points with same x,y in different z?
All points in different depth (z direction) have the same x and y coordinate.

Note that I don't want to use the extrude feature when copying points to another z level to draw vertical lines, because the distance between points in the last layer is not identical. In other words, points in z=0 have a 0.85 degree inclination but the ones in z=-14.8m level have zero degree inclination.

Here is the screenshot of xy and xz views:
Image

Thanks,
Abolfazl

Re: Drawing vertical line between points with same xy in different z

Posted: Mon May 30, 2022 12:11 pm
by escolano
It doesn't exists any tool to automatically create the lines you want.

You must create your own Tcl scripting proc that ask for the points to get its coordinates, and find the clusters of points 'close with a tolerance in x,y', sort each cluster by z and create the new lines connecting them

to ask the GiD points can use something like this

Code: Select all

foreach point_id [GiD_Geometry list point] {
   set xyz [lrange [GiD_Geometry get  point $point_id] 1 3]
   set coordinates($point_id) $xyz   
}
and can create a new straight line knowing the ids of its endpoints with

Code: Select all

set layer [GiD_Layers get to_use]
GiD_Geometry create line append stline $layer $ini_point $end_point

Re: Drawing vertical line between points with same xy in different z

Posted: Mon May 30, 2022 6:04 pm
by najafi
Thank you so much.
I'll try it and let you know the result.

Re: Drawing vertical line between points with same xy in different z

Posted: Sun Jun 05, 2022 11:26 am
by escolano
This is a complete code to create the lines joining vertical points-np
to be used can for example save to a .tcl file, like C:/temp/CreateVerticalLines.tcl and load it in GiD writting
-np- source C:/temp/CreateVerticalLines.tcl
and then invoke the creation proc with
-np- CreateVerticalLines

Code: Select all

#for a big amount of points the bruteforce search O(n^2) will be too expensive
#can use some spatial search like vtkKdTree O(n log n) (see <GiD>\plugins\Geometry\voro\voro.tcl as example)
proc FindVerticalPointsBruteForce { coordinates_dict point_start_id tolerance2 } {
    set vertical_point_ids [list]
    set xy [dict get $coordinates_dict $point_start_id]
    foreach point_id [dict keys $coordinates_dict] {
        if { [MathUtils::VectorDistance2 $xy [dict get $coordinates_dict $point_id]] <= $tolerance2 } {
            lappend vertical_point_ids $point_id
        }
    }
    if { [llength $vertical_point_ids] > 1 } {
        #sort by z increasing
        set vertical_points_and_z [list]
        foreach vertical_point_id $vertical_point_ids {
            set z [lindex [GiD_Geometry get  point $vertical_point_id] 3]
            lappend vertical_points_and_z [list $vertical_point_id $z]
        }
        set vertical_point_ids [list]
        foreach item [lsort -index 1 -real $vertical_points_and_z] {
            lappend vertical_point_ids [lindex $item 0] 
        }
    }
    return $vertical_point_ids
}

proc CreateVerticalLines { } {
    set coordinates_dict [dict create]    
    foreach point_id [GiD_Geometry list point] {
        set xy [lrange [GiD_Geometry get  point $point_id] 1 2]
        dict set coordinates_dict $point_id $xy         
    }
    set layer_to_use [GiD_Layers get to_use]    
    foreach point_id [dict keys $coordinates_dict] {
        if { [dict exists $coordinates_dict $point_id] } {
            set vertical_point_ids [FindVerticalPointsBruteForce $coordinates_dict $point_id 1e-25]
            set ini_point ""
            foreach end_point $vertical_point_ids {
                if { $ini_point != "" } {
                    GiD_Geometry create line append stline $layer_to_use $ini_point $end_point
                } 
                set ini_point $end_point   
            }
            #remove from coordinates_dict the points already clustered
            foreach vertical_point_id $vertical_point_ids {
                dict unset coordinates_dict $vertical_point_id                
            }
        }
    }
    GiD_Redraw 
}