StarHunter Posted June 22, 2010 Posted June 22, 2010 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 Quote
rkmcswain Posted June 22, 2010 Posted June 22, 2010 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... Quote
StarHunter Posted June 22, 2010 Author Posted June 22, 2010 No I don't. I was given the contour lines, I haven't made them. So what? I can't do it?? Quote
lpseifert Posted June 22, 2010 Posted June 22, 2010 try here http://www.cadtutor.net/forum/showthread.php?t=40271&highlight=cPoly or search the web for Rolling_Ball.lsp Quote
Lee Mac Posted June 23, 2010 Posted June 23, 2010 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))) ) Quote
StarHunter Posted June 23, 2010 Author Posted June 23, 2010 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... Then I tried the one you've just posted and I got this...something is wrong with the code I guess... Quote
Lee Mac Posted June 23, 2010 Posted June 23, 2010 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. Quote
StarHunter Posted June 23, 2010 Author Posted June 23, 2010 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 Quote
StarHunter Posted June 23, 2010 Author Posted June 23, 2010 Well, I tried it again. It worked this time but the results are pretty much like "cpoly" Quote
BIGAL Posted June 23, 2010 Posted June 23, 2010 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" )) Quote
SEANT Posted June 23, 2010 Posted June 23, 2010 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. Quote
eldon Posted June 23, 2010 Posted June 23, 2010 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 Quote
Lee Mac Posted June 23, 2010 Posted June 23, 2010 Thanks guys, my code was written for 2D :wink: Quote
Lee Mac Posted June 23, 2010 Posted June 23, 2010 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. Quote
SEANT Posted June 24, 2010 Posted June 24, 2010 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. Quote
StarHunter Posted June 24, 2010 Author Posted June 24, 2010 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... 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. Quote
StarHunter Posted June 24, 2010 Author Posted June 24, 2010 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? Quote
designerstuart Posted June 25, 2010 Posted June 25, 2010 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. Quote
rkmcswain Posted June 25, 2010 Posted June 25, 2010 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] Quote
Recommended Posts
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.