DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Obtaining Z values for points on and between contours

Started by aqua, September 13, 2008, 03:40:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aqua

Designcad 13.13


The macro listed below can identify the GPS coordinates for a proposed pipeline the user adds.
It requires a GPS referenced drawing (Using UTM WGS84 coordinates)
It writes the information out to a txt file, which is then open for display in GPSU
A pipeline terrain profile can then be viewed in GPSU

At present, the Z value is 0, however in GPSU, we can assign a Z value to each point using DEM data
(DEM is Digital Elevation Model data - collected by the 2000 Space Shuttle Mission)

What I would like to do is create the Z value using the contours in the drawing.
Contours are lines or curves in the drawing - on layer 118
Contours will have a Z value

So for each point that was set, the appropriate Z value would need to be calculated by using the closest contours.


Does anyone know how this can be done?

I can email a drawing if that would help.

Regards Frank







'FTM-14/9/2008
' This macro asks the user for a string, then allows them to set a number of points.
' The string and XYZ value of the point are written out to a text file
' Note: Current Z value is 0, Want to calculate this from Contour lines on layer 118

'Make GPS Go-To layer visible and editable
layer(103)=6

'file to open
open "o", 1, "c:\Program Files\Aquaflow\Textinfo\GPSinfo.txt"

temp$ = "H  GPSinfo GO-TO file for:", sys$(2)
Print#1, temp$
Print#1, "H  SOFTWARE NAME & VERSION"
Print#1, "I  GPSU 4.88    REGISTERED to 'Aquaflow Solutions'"
Print#1, "S DateFormat=d/mm/yy"
Print#1, "S Units=M,M"
Print#1, "S SymbolSet=2"
Print#1, "H R DATUM"
Print#1, "M E               WGS 84 100  0.0000000E+00  0.0000000E+00 0 0 0"
Print#1, "H  COORDINATE SYSTEM"
Print#1, "U UTM UPS"
Print#1, "F ID----  Zne Easting Northing Alt(m)"


'Ensure nothing is selected
sys(80) = 0

'Turn on Silent Mode
sys(36)=1

'Ensure working plane has been reset
>UnWorkplane
{
  }
>FitToWindow
{
  }

'Turn off Silent Mode
sys(36)=0


Zone$ = 0
Input "Enter UTM GPS zone for site, example 55H", Zone$
if ZONE$ = "" then end
zn = 1
zn = sys(999)
if zn = 1 then end
'



Start:
Precision 3
sys(41)=1
setpoint "Set up to 200 GPS points for the pipeline. Press Enter when finished." 200
Dim X(200), Y(200), Z(200)
for a = 1 to Sys(1)
PointVal X(a), Y(a), Z(a) a
next a

'Turn on Silent Mode
sys(36)=1

npts = Sys(1)
For i = 1 to npts
Pointval x(i) y(i) z(i) i
Next i
sys(3)=103
>Line
{
  <Color 0,219,255
<Type 0
For i = 1 to npts
<Pointxyz [X(i), Y(i), Z(i)]
Next i
}

Name = 0
for a = 1 to Sys(1)
temp$ = X(a), Y(a), Z(a)
Name = Name + 1
xc = 0
xc = x(a)
yc = 0
yc = y(a)


Precision 0
Pointname = 0
pointname = a
pointname$ = pointname
Precision 4
temp2$ = "W ",pointname$,"     ", Zone$," ", xc, yc,0
Print #1, temp2$
xc2 = xc+2.5
temp3$ = xc2, yc, 0
sys(3)=103
layer(103)=6
>POINTMARK
{
  <Color 255,0,0
  <pointxyz [Temp$]
  <Size 5.0000
  <Type 3
  }
Precision 0
Text$ = a
Precision 3
>ID_TEXT3D
  {
  <PointXYZ [TEMP3$]
  <Style 0
  <Justification 0
  <Size [10]
  <Angle 0.0000
  <Font "Arial"
  <Text [Text$]
  }
next a

Numberofwaypoints = name

Precision 0
Name = 0
'Scroll through to gather 1 etc for route
for a = 1 to Sys(1)
PointVal X(a), Y(a), Z(a) a
Name = Name + 1
For i = 1 to Name
id = i
next i
'Write out the "R 01" line
'Temp$ = "R 01  1 -", id
Temp$ = "R 01  1 -", Numberofwaypoints
Print #1, Temp$
'Write out the "F ID---" line
Temp2$ = "F ID----"
Print #1,Temp2$
'Generate a W 1 + i line
'For i2 = 1 to Name
For i2 = 1 to Numberofwaypoints
id2 = i2
Temp3$ = "W", id2
Print #1, Temp3$
Next i2

'Turn off Silent Mode
sys(36)=0

Close #1
sys(41)=0

>Regenerate
{
}

Textdrawingpath$ = "c:\Program Files\Aquaflow\Textinfo\GPSinfo.txt"
pr$ = "C:\Program Files\Aquaflow\Folders\GPS Utility\gpsu420.exe "
cmd$ = pr$, Textdrawingpath$
Run cmd$

bdeck

Hi Aqua

You could poke a vertical line through a surface connect grid, but that method is fraught with peril.

Here's how I would do it (Easier and Less perilous method)

a)    Draw a vertical line at the target xy coordinates.

b)    Construct a vertical plane coincident with the vertical line and roughly normal to the contours. Pick the nearest 2 or 3 contours on either side of the vertical line. On one of those 4 or 6 contours pick the nearest point to the vertical line to define the plane as "normal".   ( you could make multiple planes and do a weighted average on the results)

c)  Convert contours to curves to simplify point placement process.

d)    Draw a New curve, using the <lineplane[x,y,z,xp,yp,zp] parameter to set points where each contour curve penetrates the vertical plane.

e)   find the z value of the intersection of the vertical line to the new curve

Regards

BD


(Edited to reflect improved methods)
Critical functions:

Alias ENT_POINT  &H010E 
Alias ENT_SELECTED  &H010C 

for i= 1 to 4          'find a point on each contour
   n=i+firstcurve-1
   entity n
   query ent_point 1, x(i),y(i),z(i)   
               ' Curves: use any point, so long as curve crosses plane only once.
               ' Polylines: you must pick the correct point.
next i

>Curve     ' create New curve on vertical plane
{
   <LinePlane [x(1), y(1), z(1), xp, yp, zp]
   <LinePlane [x(2), y(2), z(2), xp, yp, zp]   
   <LinePlane [x(3), y(3), z(3), xp, yp, zp]
   <LinePlane [x(4), y(4), z(4), xp, yp, zp]
}

gosub MoveTrimTargetsToBack

>Intersect-2                  find intersection of vertical line and new curve
{
<pointxyz [x0, y0, z0]      ' point on vertical line
<pointxyz [x(1),y(1),z(1)]      ' point on new curve
}
getxyz x,y,z     '   *******     z  is final result    ***************
gosub cleanup
end

MoveTrimTargetsToBack:
    >deselect
    {
    }
    entity sys(9)-2          'select vertical line
    change ent_selected, 1
    update

    entity sys(9)          'new curve entity no
    change ent_selected, 1
    update
    >movetoback        ' move trim targets to back so that pointxyz will find them
    {
    }
return

cleanup:
    entity sys(9)          ' add vertical plane to selection  (it is now the last item on list)
    change ent_selected, 1
    update
    >delete    'delete new curve, vertical line, and plane to return drawing to prior state
    {
    }
return




Alternative code for linear interpolation.

>Lineplane
{
     >pointxyz [x2,y2,z2]      ' any point on second contour
     >pointxyz [xp,yp,zp]      ' any unique point on plane
}
getxyz  xx, yy, zz           ' get location of intercept

>Line           ' create sloping line on vertical plane, and between two contours
{
   <pointxyz [x(1), y(1), z(1)]      'point on first contour defines plane
   <poinyxyz [xx, yy, zz]             'point on second contour at plane intercept
}

gosub MoveTrimTargetsToBack

>Intersect-2                  find intersection of vertical line and new curve
{
<pointxyz [x0, y0, z0]      ' point on vertical line
<pointxyz [x(1),y(1),z(1)]      ' point on new sloping line
}
getxyz x,y,z     '   *******     z  is final result    ***************

gosub cleanup