Jump to content

lines perpendicular to spline


Dario

Recommended Posts

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

 

acad.jpg

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

You can use short lisp-program:

 

spline_perp.gif

 

(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

Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

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

 

 

 

but I wanted this

 

 

 

acad3.jpg

 

 

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

>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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 9 years later...

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

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