Dario Posted February 23, 2006 Share Posted February 23, 2006 I have one curve (spline) with 100 points (vertices). I have to construct lines perpendicular to all points in spline. In mathematics these lines are known as normals, lines perpendicular to curve tangents in all curve points. So what I have to do is to construct so many perpendicular lines that curve has points (red line on image). Lines don't have same lenght, because these values are something that I have calculated in excel. This can be done manually for each indivudual point but later I can increase whole procedure with coordinates of all first points and distances in perpendicular direction. something like this. : Quote Link to comment Share on other sites More sharing options...
CarlB Posted February 23, 2006 Share Posted February 23, 2006 I'm not sure what you need - normal line segments drawn at each point? If you have calculated the lines already in Excel, there probably is an easy way to use this data to draw the normals. Or you could do it using AutoCAD commands. Use the MEASURE command to place a block, which can be a short line, at equal intervals along the line. You can define the block( line segment) so that it is vertical with insert at midpoint, then when you MEASURE it along the spline it will align with the spline and be normal at each point. Quote Link to comment Share on other sites More sharing options...
Dario Posted February 24, 2006 Author Share Posted February 24, 2006 I'm not sure what you need - normal line segments drawn at each point? If you have calculated the lines already in Excel, there probably is an easy way to use this data to draw the normals. Or you could do it using AutoCAD commands. Use the MEASURE command to place a block, which can be a short line, at equal intervals along the line. You can define the block( line segment) so that it is vertical with insert at midpoint, then when you MEASURE it along the spline it will align with the spline and be normal at each point. Well, the problem is that I don't have all data in excel for constructing my perpendicular lines. I have only coordinates of starting points on spline and lenghts of lines in vertical direction of spline tangents in that points. Quote Link to comment Share on other sites More sharing options...
ASMI Posted February 24, 2006 Share Posted February 24, 2006 You can use short lisp-program: (defun c:sper(/ spSet ptLst Dr Ang sCurve oldEcho oldOsm) (vl-load-com) (defun *error* (msg) (setvar "CMDECHO" oldEcho) (setvar "OSMODE" oldOsm) (princ) ); end of *error* (setq oldEcho(getvar "CMDECHO") oldOsm(getvar "OSMODE") ); end setq (princ "\n*** Select Spline ***") (if (setq spSet (ssget "_:S" '((0 . "SPLINE")))) (progn (setq ptLst(mapcar 'cdr (vl-remove-if '(lambda(x)(/= (car x) 11)) (entget(ssname spSet 0)))) sCurve(vlax-ename->vla-object (ssname spSet 0)) ); end setq (setvar "OSMODE" 0) (foreach pt ptLst (setq Dr(vlax-curve-getFirstDeriv sCurve (vlax-curve-getParamAtPoint sCurve pt)) Ang(angtos(- pi(atan(/(car dr)(cadr dr))))) ); end setq (command "_.xline" "_a" Ang (trans pt 0 1) "") ); end foreach ); end progn ); end if (setvar "CMDECHO" oldEcho) (setvar "OSMODE" oldOsm) (princ) ); end of c:sper Quote Link to comment Share on other sites More sharing options...
Dario Posted February 25, 2006 Author Share Posted February 25, 2006 What this lisp algorithm does. Goes point by point on curve and construct perpendicular lines. Does it need some prepared data in file (e.g. lenghts of vertical lines)? Quote Link to comment Share on other sites More sharing options...
Dario Posted February 25, 2006 Author Share Posted February 25, 2006 What this lisp algorithm does. Goes point by point on curve and construct perpendicular lines. Does it need some prepared data in file (e.g. lenghts of vertical lines)? Because after I executed your sper I got this but I wanted this Is is possible to "tell" lisp to use predefined perpendicular direction to line (no to the both sides) and length of those lines, because they are different and calculated in excel (because those lenghts are already calculated in excel? I think I'm so close to solution thanks to you, I'm very thankfull. Quote Link to comment Share on other sites More sharing options...
ASMI Posted February 25, 2006 Share Posted February 25, 2006 >Dario I did not know a principle on which is length of lines should will be calculated in Excel, therefore have made their unlimited in both sides. However probably to manage and without Excel, in AutoLISP mathematical functions are incorporated all. The algorithm of the program is very simple. 1. Coordinates all of vertexes of a spline are calculated. You can copy it in a command line and select a spline: (mapcar 'cdr(vl-remove-if'(lambda(x)(/= (car x) 11))(entget(car(entsel))))) 2. Then for each of vertex calculates the first derivative, a corner of a perpendicular and constructs XLine. Quote Link to comment Share on other sites More sharing options...
ASMI Posted February 25, 2006 Share Posted February 25, 2006 >Dario Try this: (defun c:sper(/ spSet ptLst Dr Ang sCurve oldEcho oldOsm dataLst fPt curLen Ans) (vl-load-com) (defun *error* (msg) (setvar "CMDECHO" oldEcho) (setvar "OSMODE" oldOsm) (princ) ); end of *error* (setq oldEcho(getvar "CMDECHO") oldOsm(getvar "OSMODE") ); end setq (setvar "CMDECHO" 0) (princ "\n<<< Select Spline >>>") (if (setq spSet (ssget "_:S" '((0 . "SPLINE")))) (progn (setq ptLst(mapcar 'cdr (vl-remove-if '(lambda(x)(/= (car x) 11)) (entget(ssname spSet 0)))) sCurve(vlax-ename->vla-object (ssname spSet 0)) dataLst '() curLen T ); end setq (setvar "OSMODE" 0) (foreach pt ptLst (setq Dr(vlax-curve-getFirstDeriv sCurve (vlax-curve-getParamAtPoint sCurve pt)) Ang(- pi(atan(/(car dr)(cadr dr)))) dataLst(append dataLst (list(list(trans pt 0 1) ang))) ); end setq ); end foreach (while(and curLen dataLst) (setq curLen (getreal "\n>>> Specify perpendicular length: ") fPt(caar dataLst) Ang(cadar dataLst) ); end setq (if curLen (command "_.line" fPt (trans(polar fPt Ang curLen)0 1)"") ); end if (initget "Yes No") (setq Ans(getkword "\n>>> Mirror line? [Yes/No] <No>: ")) (if(null Ans)(setq Ans "No")) (if(= Ans "Yes") (progn (command "_.erase" (entlast) "") (command "_.line" fPt (trans(polar fPt(- Ang Pi)curLen)0 1)"") ); end progn ); end if (setq dataLst(cdr dataLst)) (if(not dataLst) (princ "\n*** End of Spline. Quit. ***") ); end if ); end while ); end progn ); end if (setvar "CMDECHO" oldEcho) (setvar "OSMODE" oldOsm) (princ) ); end of c:sper Quote Link to comment Share on other sites More sharing options...
Dario Posted March 3, 2006 Author Share Posted March 3, 2006 This was really helpfull and that's it what I wanted to do. Thank you very much, you are definitely lisp master and when I see what this code can do I have lot of ideas to increase job efficiency, but first of all I have to learn some lisp basics. Quote Link to comment Share on other sites More sharing options...
ASMI Posted March 3, 2006 Share Posted March 3, 2006 Quote Link to comment Share on other sites More sharing options...
vuongsurvey Posted May 21, 2015 Share Posted May 21, 2015 Dear sir ASMI, Because I live in Vietnam so my english which is very poor, forgive me for this. I need to edit your lisp running on my drawing, the object is spline magenta ... If possible, I would like to thank the generosity of sir, good sir happy This is your lisp that I use, and my drawings http://4share.vn/f/744045434d4d4c41/vuonggoc_spl.lsp http://4share.vn/f/5e6a6f6967676668/vuong goc spline.dwg Quote Link to comment Share on other sites More sharing options...
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.