Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help Needed lisp Routine for Creating 3D Polylines with Specified Slope"

30 REPLIES 30
Reply
Message 1 of 31
libarraSCXGZ
959 Views, 30 Replies

Help Needed lisp Routine for Creating 3D Polylines with Specified Slope"

Hi everyone,

I need to develop a LISP routine that allows creating a 3D polyline with a user-specified slope. The goal is for the user to select a starting point, and then the polyline should continue along the surface, following the slope until it reaches a point where the maximum slope at that point is less than the design slope.

I have to carry out feasibility studies for roads and irrigation canals, and it is tedious to do it manually.

Here is a reference of what I need to do:


https://filesnj.carlsonsw.com/mirror/manuals/Carlson_2007/online/index.html?page=source%2FSite_Road_...

 

Could you help me with some basic LISP code to help me study and move forward with this? My knowledge of LISP is basic, but any help would be appreciated.

30 REPLIES 30
Message 21 of 31
john.uhden
in reply to: Sea-Haven

@Sea-Haven ,

Umm, what YouTube video?

John F. Uhden

Message 22 of 31

I believe the video in question  is the one referenced in message #9 by Sea-Haven.  The video shows a Civil3D routine calculating a polyline of constant slope across the surface of a TIN, but does not really explain the math involved, which I would not expect it to explain in detail.   I think what Sea-Haven is trying to do is create a LISP routine to do the same thing.

Message 23 of 31

@autoid374ceb4990 ,

Ya know, I think that if the OP has either 3DFaces or a TIN of lines, that he can draw a LWPolyline over them anywhere and we can use the polyline as a fence to collect all the ssnamex points and...

either build a profile and with a couple of tools either get or put slope lines,

OR

just label the slopes in plan view every so often with slopes to the nearest whole %.

John F. Uhden

Message 24 of 31

@john.uhden:

I think that without an organized TIN the OP cannot create an automatic routine to do more than one triangle at a time.  With just a drawing containing a lot ( millions ??) of 3DFACEs I think he will be stuck with doing one triangle at a time.  I think I have found a solution for a single 3DFACE.  Select the triangular 3DFACE and pick a point inside the triangle.  Calculate the elevation of the pick point and then calculate the slope of the lines from the pick point to each vertex, call the vertices A,B,C and the slope of the 3 lines P-A, P-B, P-C.  Call the desired slope 2%.  If the desired slope (2%) lies between P-A and P-B, then the slope intersect point lies on the triangle side A-B.  Check all three sides and if the 2% point does not lie between any of the three, there is no solution for this triangle.  I think the OP should be able to do this one triangle at a time.  The problem with trying to construct a continuous polyline would be (I think) finding the adjoining triangle to test.  I have a routine that works for finding the adjacent triangle with my TIN format but I am not sure how you would do this with just an unorganized group of 3DFACEs.

Message 25 of 31

@autoid374ceb4990 wrote, "I think that without an organized TIN the OP cannot create an automatic routine to do more than one triangle at a time. "

I believe that your thinking needs some improvement.

Give me a 2002 dwg with either 3DFaces or 3D lines or both, and I'll show you.

John F. Uhden

Message 26 of 31
Sea-Haven
in reply to: john.uhden

Sorry John disagree think of an alignment it walks along a path and finds the next triangle. Starting with a point then doing a radial check for the next touch 3dface is the tricky part.

 

Years ago with make a TIN slow computer would see the tin spiralling out from a central point. Need something similar. The end point is on two faces or have got to an edge. 

 

Any civ3d surface convert to 3dfaces same with land desktop. For sample.

Message 27 of 31

If you have a mesh surface made of 3DFACE, here is a routine that will hide the edges of the 3Dfaces which will be greater than the value entered as a percentage.
The resulting display will allow you to see the path that you can take without exceeding your slope value and see if there will be no discontinuity in the path, that is to say there is always an adjacent 3dface edge.

 

(defun C:Mask_PerCent ( / ss ref_spl n ent dxf_ent lst dxf_70)
  (setq ss (ssget '((0 . "3DFACE"))))
  (cond
    (ss
      (initget 5)
      (setq ref_slp (getreal "\nHide the edges of 3DFACEs whose slope (in %) is greater than ?: "))
      (repeat (setq n (sslength ss))
        (setq
          ent (ssname ss (setq n (1- n)))
          dxf_ent (entget ent)
          lst
          (list
            (cdr (assoc 10 dxf_ent))
            (cdr (assoc 11 dxf_ent))
            (cdr (assoc 12 dxf_ent))
            (cdr (assoc 13 dxf_ent))
          )
          dxf_70 0
        )
        (mapcar
          '(lambda (x y i / d_x d_z slop)
            (setq
              d_x (distance (list (car x) (cadr x)) (list (car y) (cadr y)))
              d_z (abs (- (caddr x) (caddr y)))
              slop (if (zerop d_x) 9.0E16 (* (/ d_z d_x) 100.0))
            )
            (if (> slop ref_slp)
              (setq dxf_70 (+ dxf_70 i))
            )
          )
          lst
          (append (cdr lst) (list (car lst)))
          '(1 2 4 8)
        )
        (entmod (subst (cons 70 dxf_70) (assoc 70 dxf_ent) dxf_ent))
      )
    )
  )
  (prin1)
)
Message 28 of 31

John:

I have attached a drawing with about 4000 3DFACEs. It is a lot older than 2002, but you should be able to read it.

 

Message 29 of 31
Sea-Haven
in reply to: john.uhden

@autoid374ceb4990 No need for 4000 triangles to just write something.

 

Thinking some more do a radial search for the next closest object need a max length search as crossing 200 triangles will slow things down. Once you find object can get the segment crossed radially and check the z1->z2 calculated is equal to slope. Maybe start at about 1 degree steps. so around 180 max goes. Once working decrease increment.

 

SeaHaven_0-1722817171803.png

@john.uhden a smaller bit saved as R12.

 

 

 

Message 30 of 31

I understand that you do not need 4000 triangle just to write some code, but when you deal with LIDAR data you may have several million triangles, so you need code that will not bog down with a lot of closely spaced triangles.

Message 31 of 31
Sea-Haven
in reply to: libarraSCXGZ

Cheat is the way to get around the size of the TIN. Do a "Select" and select relevant area of triangles, then CTrl+C, open a blank dwg, paste to original coordinates. Run the lisp, then Ctrl+C the pline solution. Paste into the true dwg. Throw away dummy dwg. 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta