Jump to content

Trying to draw a centerline between two contour lines


StarHunter

Recommended Posts

Hello,

 

I have a set of contour lines and I wish to draw a center line between every two contour lines.

I mean I need to draw a line that exactly cut the area between every two contour lines in half.

Is that possible??

Have a look at the contour lines

Thanks

 

cad1.jpg

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • StarHunter

    8

  • Lee Mac

    4

  • SEANT

    2

  • rkmcswain

    2

Top Posters In This Topic

Posted Images

I'm guessing that you do not have the application necessary to create contour lines at half of the interval of what you have? Not that this would necessary split the two lines, but it would be fairly close...

Link to comment
Share on other sites

Larry,

 

As you mentioned it, I was experimenting with that code - and perhaps there is a better way to write it... you see, that code just increments along one poly and gets the closest point to the other, I don't think this is the best way to perhaps approach the problem.

 

I'm not sure if this might be better?

 

(defun c:RollingBall ( / acc e1 e2 len inc )
 ;; © Lee Mac  ~  23.06.10
 (vl-load-com)

 (setq acc 100.) ;; Increase for greater accuracy

 (if (and (setq e1  (LM:SelectifFoo LM:isCurveObject "\nSelect First Object: "))
          (setq e2  (LM:SelectifFoo LM:isCurveObject "\nSelect Second Object: "))
          (setq len (vlax-curve-getDistatParam e1 (vlax-curve-getEndParam e1))
                inc (/ len acc)))
   (
     (lambda ( i / p1 pp1 p2 pp2 ls foo l2 )
       (setq l2 (vlax-curve-getDistatParam e2 (vlax-curve-getEndParam e2)))
       
       (setq foo
         (if (< (distance (vlax-curve-getStartPoint e1) (vlax-curve-getStartPoint e2))
                (distance (vlax-curve-getStartPoint e1) (vlax-curve-getEndPoint   e2)))

           (lambda ( x ) x )
           (lambda ( x ) (- l2 x))            
         )
       )
       
       (while (and (<= (setq i (+ i inc)) len)
                   (setq p1 (vlax-curve-getPointatDist e1 i))
                   (setq p2 (vlax-curve-getPointatDist e2 (foo i))))

         (setq pp1 (LM:ButLast p1) pp2 (LM:ButLast p2))
         
         (setq ls
           (cons
             (append
               (polar pp1 (angle pp1 pp2) (/ (distance pp1 pp2) 2.))
               (list (/ (+ (last p1) (last p2)) 2.))
             )
             ls
           )
         )
       )
       (LM:Polyline ls)
     )
     (- inc)
   )
 )
 (princ)
)


(defun LM:SelectifFoo ( foo str / sel ent )
 ;; © Lee Mac  ~  12.06.10
 (while
   (progn
     (setq sel (entsel str))
     
     (cond
       (
         (vl-consp sel)

         (if (not (foo (setq ent (car sel))))
           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 ent
)

(defun LM:isCurveObject ( ent )
 ;; © Lee Mac  ~  12.06.10
 (not
   (vl-catch-all-error-p
     (vl-catch-all-apply
       (function vlax-curve-getEndParam) (list ent)
     )
   )
 )
)

(defun LM:Polyline ( lst / x )
 ;; © Lee Mac  ~  23.06.10
 (entmakex (list (cons 0 "POLYLINE") (cons 10 '(0 0 0))))  
 (mapcar
   '(lambda ( x )
      (entmakex
        (list (cons 0 "VERTEX") (cons 10 x))
      )
    )
   lst
 )
 (entmakex (list (cons 0 "SEQEND")))
)

(defun LM:butlast ( l )
 ;; © Lee Mac  ~  23.06.10
 (reverse (cdr (reverse l)))
)

Link to comment
Share on other sites

Hey guys, thanks for helping me out.

Lee when I tried your first code "cpoly" from the old thread it wasn't accurate at all.

Have a look...

 

cad2.jpg

 

Then I tried the one you've just posted and I got this...something is wrong with the code I guess...

 

cad3.jpg

Link to comment
Share on other sites

My first code would not deal very well with very curvy contours... my second code (just updated), needed to allow for curve direction.

 

Please try the above again.

Link to comment
Share on other sites

Lee when I select first object it says: "; error: no function definition: FOO"

I wanted to attach the drawing to try for yourself but the attachment min. size is 250Kb and I can't provide an external link because my posts are under 9

Link to comment
Share on other sites

The only way may be to draw perp lines from 1 polyline to another then join the midpoints which is I think in code above, same as what has been done in some of the batter routines that have been posted here. I think it was battertics

 

The problem may be spacing increment work on some plines where shape is similar v's others that have extreme bulges.

 

Re creating the contours would be simplest a phone call away ? Re engineering the contours by say bringing into Civ3d would provide an answer but you dont always get as good as the original model.

 

Another method draw the perp lines add more lines remove lines to improve then use a pline to approximate the new contour line but your actually calculating new midpoints. The pline represents the fence option to select line entities crossing. Hope that makes sense. (setq ss (ssget "F" ))

Link to comment
Share on other sites

It looks like the contours are at different elevations.

 

So, a stab at a suggested fix:

 

Instead of (/ (distance p1 p2) 2.), get the ProjectedDistance/2 for use with the polar function

 

Then set the new centerline.Elevation = (e1.Elevation + e2.Elevation) /2 . . . .sorry about the VBA notation.

Link to comment
Share on other sites

Sorry to cast a dampner on things, but with your contours being so dis-similar in shape, you may get the best result by drawing the intermediate contour yourself.

 

At least then you cannot blame someone's lisp that was not written for such an extreme case :cry:

Link to comment
Share on other sites

Ok, I have updated the code again - this time using Sean's suggestion.

 

It is untested, but please give it a try and let me know how you get on. :)

Link to comment
Share on other sites

The resulting poly definitely has the appropriate shape. It remains at Elevation = 0.0, however. Even though a 2D Polyline vertex allows for all three coordinates, I believe it ignores the Z Value. I think the elevation has to be set specifically.

 

This is an interesting interpolation challenge. Your algorithm works very well with the geometry one would expect from a usual topo contours. It even deals with overlaps, something I’m investigating from the .NET direction.

 

The wildly dissimilar curves, like curves 5 and 6 from the top in the OP, do seam a bit spotty. eldon’s comment is probably valid in that case.

Link to comment
Share on other sites

Hey guys, Sorry for my late reply I've been busy.

The good news is that I removed the contour elevations "made them all at zero" then I used the old "cpoly" code and it worked just fine and was so accurate too. Have a look...

 

cad5m.jpg

 

I'll then assigned the correct elevation for each contour.

I don't know how to thanks you guys you really helped me out and I really appreciate it.

Thanks everybody.

Link to comment
Share on other sites

btw, I need to know how to save the code to the program so I won't have to enter it every time I close and re-open the program.

I mean is there a way to make it just like the regular commands?

Link to comment
Share on other sites

There Is A Way To Do This...... You Need To Add it to your acad.lsp file or something. sorry, i'm not sure of the best way to do it, but it is do-able.

 

someone will tell you i'm sure.

Link to comment
Share on other sites

btw, I need to know how to save the code to the program so I won't have to enter it every time I close and re-open the program.

I mean is there a way to make it just like the regular commands?

 

Append or create a file named "acaddoc.lsp" in your support file search path.

This is an ASCII file, add one of the following lines, using the real path and file name:

(load "\\\\server\\share\\path\\filename.lsp") [color="Gray"]; <--- file on server[/color]
(load "c:\\mypath\\mylisp.lsp")[color="Gray"]; <--- file on local machine[/color]
(load "mylisp") [color="Gray"];<--- if the file is in the support file search path[/color]

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