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"

88 REPLIES 88
Reply
Message 1 of 89
libarraSCXGZ
3598 Views, 88 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.

88 REPLIES 88
Message 21 of 89
john.uhden
in reply to: Sea-Haven

@Sea-Haven ,

Umm, what YouTube video?

John F. Uhden

Message 22 of 89

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 89

@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 89

@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 89

@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 89
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 89

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 89

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 89
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 89

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 89
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. 

 

 

Message 32 of 89

Just wondering if anyone has found a solution to this problem? 

How about just a solution for finding the path of a given % slope across a single 3DFACE?

Message 33 of 89

Did you look into some of the NOT FREE solutions, often they are very reasonably priced, use a couple of times and have paid for themselves in terms of work time.

Message 34 of 89

I have not looked into any other non-free solutions.  I am a retired civil engineer with over 50 years experience and I have never had occasion to use such a routine.  All the roads I have ever designed were always laid out in plan view first and profiles were generated to fit the ground as best as possible.  I wrote my own civil engineering/land surveying software for AutoCAD (ARX programs) and I still like to do a little programming to keep my mind working properly. 

Message 35 of 89

Look at post 29 image that is what your trying to achieve. A direction line matching slope.

 

1st step there is formula for get XYZ on a plane.

2nd step is do a repeated angle search is it = grade.

3rd step is find next 3dface.

 

Message 36 of 89

"Look at post 29 image that is what your trying to achieve. A direction line matching slope.

1st step there is formula for get XYZ on a plane.

2nd step is do a repeated angle search is it = grade.

3rd step is find next 3dface."

I thought post #29 was suggesting a method to find the adjacent triangle??

My TIN is written so that I do not have any problem finding the XYZ of the start point on the triangle surface or finding the adjacent triangle, I just need help finding the line with the correct slope crossing the triangle.

Are you suggesting an iterative method to find the correct slope?  That may work but may be rather time consuming.

Message 37 of 89

You are correct given a direction need to look at the XYZ of the intersecting edge of the 3dface, and then work out grade, from prior point. There may be a fast way to work out a new point given 2 pts with XYZ, rather than using a angle approach. I would look at midpoint of opposite edge as 1st point if doing iteration method.

 

The paid for solutions are probably written as ARX for speed.

Message 38 of 89

I have been working on that assumption also.  Once I select a point in a triangle, I calculate the slope from that point to each vertex.  From the slopes I can calculate which side ( if any) to intersect.  As you suggested, I decided to first find the midpoint of the side, calculate the slope from the start point to the mid point, then determine which side contains the desired slope, then use the same procedure to continue to divide that side until the desired slope is obtained.  One problem that I have found is that the starting triangle may have two sides that contain the correct slope intersect point.  I think that once I pick the direction for the first slope line, I can eliminate that problem on subsequent triangles.

Message 39 of 89

@autoid374ceb4990 ,

Treating it as a challenge, I have been working on building an existing profile from your sea of 3DFaces.

3DFaces don't get along with vlax-curve functions, so I have had to convert the faces to 3DPolys.  It's more complicated than I had thought, but I think I'm getting closer.

John F. Uhden

Message 40 of 89
Sea-Haven
in reply to: john.uhden

Looking into this found paulbourke.net/geometry/pointlineplane/linesegments.lisp

Scroll down look at the XY common lisp solution can then find the Z value on the face line.

 

As the above uses points just read the 3 points of the 3dface no need to convert.

 

 

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report