Jump to content

Creating a boundary to a group of points


Tyke

Recommended Posts

If I have a group of AutoCAD points how can I create a bounding polyline around the points? Its similar to the rectangle perimeter problem but not as easy.

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • Tyke

    9

  • eldon

    4

  • alanjt

    4

  • CyberAngel

    1

Top Posters In This Topic

The first, and probably wrong, thing that comes to mind is--create a surface with the points. Once you remove the lines that don't enclose any points, the surface border will be the boundary you want. Import the boundary. Delete the surface.

Link to comment
Share on other sites

In Civil 3D you could create a DTM and export the boundary as an AutoCAD object, unfortunately I don't have Civil 3D on this particular machine :(

Link to comment
Share on other sites

I usually bite the bullet and create a polyline. The first point I snap onto using a .XY filter and set the Z to zero. Then continue the polyline by snapping on the Nodes around the perimeter, and closing the last length with Close. But then I am not afraid of hard work :D

Link to comment
Share on other sites

I usually bite the bullet and create a polyline. The first point I snap onto using a .XY filter and set the Z to zero. Then continue the polyline by snapping on the Nodes around the perimeter, and closing the last length with Close. But then I am not afraid of hard work :D

Reminds me of DOS based LIContour software. Had to individually pick each breakline point and go around the entire boundary, point by point, for the border.

Link to comment
Share on other sites

No code but a soloution, Maybe pick an approx centre point then calc the angle from this point to each point add to list, sort list by angle then away you go joining points.

Link to comment
Share on other sites

@ eldon:

 

But then I am not afraid of hard work :D
Point taken eldon and I think most of us are of the same mind here, but with sometimes more than 5000 points it becomes rather time consuming.

 

What CyberAngel said about creating a surface is probably the easiest and most efficient way when you have Civil 3D.

 

I'm working on a bit of code now that will do the job. As a starting point it takes the point with the lowest Y coordinate and then with a user defined length rotates a line until it finds a point very close to the line and adds it to a list. This newly found point is now taken as a start point and the whole procedure repeated until we either come back on our original starting point or we find no point after doing a full rotation. A polyline is then drawn from the points in the list and closed if we have reached the original starting point.

 

Pity there's not a similar command to Boundary that would do it.

 

ps alanjt - congrats on breaking the 5000 posts barrier :)

Link to comment
Share on other sites

Is the 5000 the number of points in the boundary? In which case the survey points could number 1500000.

 

If 5000 is the total number of points in the survey, then the boundary might take less than 300.

 

Even with the 5000 points in the boundary, that should take less than 2 hours manually. If the writing of the code and testing takes less than 2 hours, then you are on a winner :D

Link to comment
Share on other sites

5000 points is the number of survey points.

 

This is not a one-off, it will occur sporadically over the next few years, so I think the time taken to write the code will more than pay for itself in the long run. And its only for the two computers that don't have Civil 3D.

Link to comment
Share on other sites

5000 points is the number of survey points.

 

O.K. you have now got five minutes to write your code, because that is all the time you are saving :shock:

Link to comment
Share on other sites

Hi, Tyke! I really need your help.

I have contours as polylines or points with X,Y,Z coordinates and I can create a surface in AutoCAD Civil.

But I need to create a 3d solid and export to stl.

How can I do this?

Link to comment
Share on other sites

OK eldon, here's the first attempt. I must admit though I needed a bit more than five minutes.

 

The length of the line is entered at the start and depending on its length it can produce different results.

 

Link to comment
Share on other sites

abgailpp

I have contours as polylines or points with X,Y,Z coordinates and I can create a surface in AutoCAD Civil.

But I need to create a 3d solid and export to stl.

How can I do this?

 

This was discussed a while ago in the SolidWorks forum here. Have a look there.

 

Basically, there is no straight forward way in Civil 3D to create a solid from a surface. I'm not sure what format you need for your stl.

Link to comment
Share on other sites

OK eldon, here's the first attempt. I must admit though I needed a bit more than five minutes.

 

The length of the line is entered at the start and depending on its length it can produce different results.

 

I am very impressed, but not all surveys have points so nicely spaced. By the time you have looked at the results, there may be a bit of manual alterations to do which negates the time saving.

 

 

These hijacking of posts do create confusion with following a thread. Start your own thread abgailpp - where are your manners :shock:

Link to comment
Share on other sites

Point taken eldon, and these points and blocks were rather quickly put together, just as test data. I'll try it out next week on some real data, when I'm back in the office.

 

abgailpp did a duplicate post in SW Forum too :o

Link to comment
Share on other sites

I've had these subs saved for years. I take no credit, I'm only using Menzi's work to generate a list of points to create the LWPolyline...

 

(defun c:ConvexHull (/ _lwpline ss i lst)

 (defun _lwpline (lst)
   (if (> (length lst) 1)
     (entmakex (append
                 (list '(0 . "LWPOLYLINE")
                       '(100 . "AcDbEntity")
                       '(100 . "AcDbPolyline")
                       (cons 90 (length lst))
                       '(70 . 1)
                 )
                 (mapcar (function (lambda (p) (list 10 (car p) (cadr p)))) lst)
               )
     )
   )
 )

 (if (and (setq ss (ssget '((0 . "POINT")))) (>= (setq i (sslength ss)) 3))
   (progn (repeat i (setq lst (cons (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))) lst)))
          (_lwpline (MeGetConvexHull lst))
   )
 )
 (princ)
)


; == Function MeGetConvexHull
; Calculates the convex hull from a 'cloud' of points.
; Arguments [Type]:
;   Lst = Point list 
[list]
; Return [Type]:
;   > Hull points 
[list]
; Notes:
;   - Algorithm by Graham
;
(defun MeGetConvexHull (Lst / FstCnt LstLen MinCnt NxtCnt TmpLst)
 (setq LstLen (length Lst)
       MinCnt 0
       FstCnt 1
 )
 (while (< FstCnt LstLen)
   (if (< (cadr (nth FstCnt Lst)) (cadr (nth MinCnt Lst)))
     (setq MinCnt FstCnt)
   )
   (setq FstCnt (1+ FstCnt))
 )
 (setq FstCnt 0)
 (while (< FstCnt LstLen)
   (if (and
         (equal (cadr (nth FstCnt Lst)) (cadr (nth MinCnt Lst)) 1E-
         (> (car (nth FstCnt Lst)) (car (nth MinCnt Lst)))
       )
     (setq MinCnt FstCnt)
   )
   (setq FstCnt (1+ FstCnt))
 )
 (setq TmpLst (MeSwapList Lst 0 MinCnt)
       TmpLst (vl-sort
                TmpLst
                (function
                  (lambda (e1 e2)
                    (<
                      (MeCalcTheta (nth 0 TmpLst) e1)
                      (MeCalcTheta (nth 0 TmpLst) e2)
                    )
                  )
                )
              )
       TmpLst (cons (last TmpLst) TmpLst)
       NxtCnt 3
       FstCnt 4
 )
 (while (<= FstCnt LstLen)
   (while (>=
            (MeGetCcw
              (nth NxtCnt TmpLst)
              (nth (1- NxtCnt) TmpLst)
              (nth FstCnt TmpLst)
            )
            0
          )
     (setq NxtCnt (1- NxtCnt))
   )
   (setq NxtCnt (1+ NxtCnt)
         TmpLst (MeSwapList TmpLst FstCnt NxtCnt)
         FstCnt (1+ FstCnt)
   )
 )
 (mapcar '(lambda (l) (nth l TmpLst)) (MeRepeatedList 0 (1- NxtCnt) 1))
)
;
; == Function MeSwapList
; Swaps 2 atoms in a list.
; Arguments [Type]:
;   Lst = List to swap 
[list]
;   Fst = Source position [iNT]
;   Nxt = Target position [iNT]
; Return [Type]:
;   > Swapped list 
[list]
; Notes:
;   None
;
(defun MeSwapList (Lst Fst Nxt / FstVal NxtVal TmpLst)
 (setq FstVal (nth Fst Lst)
       NxtVal (nth Nxt Lst)
       TmpLst (MeEditList 0 Fst NxtVal Lst)
 )
 (MeEditList 0 Nxt FstVal TmpLst)
)
;
; == Function MeCalcTheta
; Calculates a ordinal number between 2 points.
; Arguments [Type]:
;   Pt1 = First point 
[list]
;   Pt2 = Second point 
[list]
; Return [Type]:
;   > A value between 0 and 360 [REAL]
; Notes:
;   None
;
(defun MeCalcTheta (Pt1 Pt2 / X__Abs Y__Abs X__Dif Y__Dif TheVal)
 (setq X__Dif (- (car Pt2) (car Pt1))
       Y__Dif (- (cadr Pt2) (cadr Pt1))
       X__Abs (abs X__Dif)
       Y__Abs (abs Y__Dif)
       TheVal (if (equal (+ X__Abs Y__Abs) 0 1E-5)
                0
                (/ Y__Dif (+ X__Abs Y__Abs))
              )
 )
 (if (< X__Dif 0)
   (setq TheVal (- 2.0 TheVal))
   (if (< Y__Dif 0)
     (setq TheVal (+ 4.0 TheVal))
   )
 )
 (* 90.0 TheVal)
)
;
; == Function MeGetCcw
; Determines the direction of 3 points.
; Arguments [Type]:
;   Pt1 = First point 
[list]
;   Pt1 = Second point 
[list]
;   Pt3 = Third point 
[list]
; Return [Type]:
;   >  1 = ccw [iNT]
;   > -1 = cw [iNT]
;   >  0 = Colinear [iNT]
; Notes:
;   None
;
(defun MeGetCcw (Pt0 Pt1 Pt2 / X1_Dif X1_Sqr X2_Dif X2_Sqr Y1_Dif Y1_Sqr Y2_Dif Y2_Sqr
               )
 (setq X1_Dif (- (car Pt1) (car Pt0))
       Y1_Dif (- (cadr Pt1) (cadr Pt0))
       X2_Dif (- (car Pt2) (car Pt0))
       Y2_Dif (- (cadr Pt2) (cadr Pt0))
       X1_Sqr (* X1_Dif X1_Dif)
       Y1_Sqr (* Y1_Dif Y1_Dif)
       X2_Sqr (* X2_Dif X2_Dif)
       Y2_Sqr (* Y2_Dif Y2_Dif)
 )
 (cond
   ((> (* X1_Dif Y2_Dif) (* Y1_Dif X2_Dif)) 1)
   ((< (* X1_Dif Y2_Dif) (* Y1_Dif X2_Dif)) -1)
   ((or (< (* X1_Dif X2_Dif) 0) (< (* Y1_Dif Y2_Dif) 0)) -1)
   ((< (+ X1_Sqr Y1_Sqr) (+ X2_Sqr Y2_Sqr)) 1)
   (0)
 )
)
;
; == Function MeRepeatedList
; Fills a list with numbers from Srt to End, using increment of Inc.
; Arguments [Type]:
;   Srt = Start number [iNT] or [REAL]
;   End = End number [iNT] or [REAL]
;   Inc = Increment to use [iNT] or [REAL]
; Return [Type]:
;   > List containting all numbers between and including Srt and End
; Notes:
;   If End is not a repeated of End - Srt, End will not be included
;
(defun MeRepeatedList (Srt End Inc / TmpVal RetVal)
 (setq TmpVal (- Srt Inc))
 (while (< TmpVal End)
   (setq RetVal (append
                  RetVal
                  (list (setq TmpVal (+ TmpVal Inc)))
                )
   )
 )
 RetVal
)
;
; == Function MeEditList
; Delete, replace or append a list.
; Arguments [Type]:
;   Mde = Mode  1 append  [iNT]
;         Mode  0 replace [iNT]
;         Mode -1 delete  [iNT]
;   Pos = Position in list [iNT]
;   Val = New value [iNT/REAL/STR/LIST]
;   Lst = List 
[list]
; Return [Type]:
;   > Modified list 
[list]
; Notes:
;   - Delete and replace, require the position (Pos) in list.
;   - Append and replace, require the new value (Val).
;   - :vlax-null items are not allowed in the list argument
;
(defun MeEditList (Mde Pos Val Lst / Countr TmpLst TmpVal)
 (if (= Mde 1)
   (reverse (cons Val (reverse Lst)))
   (progn
     (setq Countr -1
           TmpVal (if (= Mde -1)
                    :vlax-null
                    Val
                  )
           TmpLst (mapcar
                    '(lambda (l)
                       (if (= Pos (setq Countr (1+ Countr)))
                         TmpVal
                         l
                       )
                     )
                    Lst
                  )
     )
     (vl-remove :vlax-null TmpLst)
   )
 )
)

 

As eldon has said, you are going to spend additional effort tweaking this since it's never going to be exact. Even creating a surface with contouring software (Civil 3D, etc.) will require you to clean up areas.

Link to comment
Share on other sites

Even creating a surface with contouring software (Civil 3D, etc.) will require you to clean up areas.

 

That's right alanjt, we do a clean up on almost all of our survey data and surfaces to create the optimum result. Nothing is perfect and there is always the exception. But a couple of minutes tweaking is preferable to a load of time doing all manually (OK eldon's not afraid of a bit of manual work :wink:)

Link to comment
Share on other sites

That's right alanjt, we do a clean up on almost all of our survey data and surfaces to create the optimum result. Nothing is perfect and there is always the exception. But a couple of minutes tweaking is preferable to a load of time doing all manually (OK eldon's not afraid of a bit of manual work :wink:)

Oh, I know. I was saying that so you wouldn't come back with "this isn't perfect man!". It cracks me up how some people think AutoCAD or any addons are some how magic.

Link to comment
Share on other sites

Oh, I know. I was saying that so you wouldn't come back with "this isn't perfect man!". It cracks me up how some people think AutoCAD or any addons are some how magic.

 

I thought they made an APP for that. :ouch:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...