Author Topic: line from a point perpendicular to a line  (Read 31064 times)

0 Members and 1 Guest are viewing this topic.

sinc

  • Guest
line from a point perpendicular to a line
« Reply #30 on: July 22, 2004, 01:26:57 AM »
What about:

Code: [Select]

(defun c:perp2ent (/ entity pt)
  (while (setq entity (car (entsel "\nSelect entity: ")))
    (while
      (setq pt (getpoint "\nSelect point to draw perpendicular from: "))
       (entmake
(list '(0 . "LINE")
      (cons 10 pt)
      (cons 11 (vlax-curve-getClosestPointTo entity pt))
) ;_ list
       ) ;_ entmake
    ) ;_ while
  ) ;_ while
  (princ)
) ;_ defun



It can get a little bit funky if you try and draw perps to splines or polylines that curve back in on themselves, but otherwise it works.

sinc

  • Guest
line from a point perpendicular to a line
« Reply #31 on: July 22, 2004, 01:43:41 AM »
Oh, and if you're past the end of the line/arc/whatever, it draws a line to the nearest endpoint...  I guess that's also why it gets funky if the splines/polylines curve back on themselves...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
line from a point perpendicular to a line
« Reply #32 on: July 22, 2004, 08:13:34 AM »
Wow that is cool.
I like it.... 8)
CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
line from a point perpendicular to a line
« Reply #33 on: July 22, 2004, 08:21:25 AM »
Ooops, one problem.
When i use this to rotate my view
Code: [Select]
^C^Cdview;;tw;90;;_ucs;w;_ucs;z;270;
It doesn't work. But I still like it.
Nice work.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
line from a point perpendicular to a line
« Reply #34 on: July 22, 2004, 08:40:13 AM »
Ok, it was an easy modification.
Works like a dream....
I replaced my old routine with this.
Thanks again.
CAB
Code: [Select]
;;  by sinc @ the Swamp  07/22/2004
;;  Repeatedly draws a line from a pick point perpendicular
;;  to a selected object
(defun c:perp2ent (/ entity pt)
  (while (setq entity (car (entsel "\nSelect entity: ")))
    (while
      (setq pt (getpoint "\nSelect point to draw perpendicular from: "))
       (entmake (list '(0 . "LINE") (cons 10 (trans pt 1 0))
          (cons 11 (vlax-curve-getClosestPointTo entity (trans pt 1 0)))) ;_ list
       ) ;_ entmake
    ) ;_ while
  ) ;_ while
  (princ)
) ;_ defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dan19936

  • Guest
Re: line from a point perpendicular to a line
« Reply #35 on: January 04, 2007, 08:53:11 PM »
I wasn't sure if sinc's routine was useful but I had saved it anyway. Today I'm doing a spiral stair and it is so much more productive than polar array to just divide & pick the perpendicular points.

Thanks Sinc! (and CAB)

Dan

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: line from a point perpendicular to a line
« Reply #36 on: January 04, 2007, 10:32:31 PM »
I still use that routine today. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: line from a point perpendicular to a line
« Reply #37 on: January 05, 2007, 09:59:17 AM »
That routine is sweet :)...here's my addition to CAB's version, inputs lines on same layer as entity picked.

Code: [Select]
(defun c:perp2ent (/ entity pt lyr)
  (while (setq entity (car (entsel "\nSelect entity: ")))
    (while
      (setq pt (getpoint "\nSelect point to draw perpendicular from: "))
       (entmake
(list '(0 . "LINE")
       (cons 8 (cdr (assoc 8 (entget entity))))
       (cons 10 (trans pt 1 0))
       (cons 11
     (vlax-curve-getClosestPointTo entity (trans pt 1 0))
       )
)
       )
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alisafei

  • Guest
Re: line from a point perpendicular to a line
« Reply #38 on: January 28, 2009, 03:05:06 PM »
can you add the distance of the point from that selected line.
i want to check how far that point lies from that selected object.
thanks in advance.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: line from a point perpendicular to a line
« Reply #39 on: January 28, 2009, 03:35:39 PM »
Welcome to TheSwamp.

Do you need the distance displayed on the command line or added to the drawing?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DEVITG

  • Bull Frog
  • Posts: 479
Re: line from a point perpendicular to a line
« Reply #40 on: January 28, 2009, 03:38:00 PM »
Hi Ronjonp .

Sad to say that  if the point is "OUTSIDE" the line , it will draw the line to the end of the start of the lines.


Location @ Córdoba Argentina Using ACAD 2019  at Window 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: line from a point perpendicular to a line
« Reply #41 on: January 28, 2009, 04:18:56 PM »
Hi Ronjonp .

Sad to say that  if the point is "OUTSIDE" the line , it will draw the line to the end of the start of the lines.




Not very pretty but this works:  8-)

Code: [Select]
(defun c:perp2ent (/ entity pt lyr ep sp ppt ang1 ang2 obj)
  (while (and (setq entity (car (entsel "\nSelect entity: ")))
              (setq obj (vlax-ename->vla-object entity))
         )
    (while (setq pt (getpoint "\nSelect point to draw perpendicular from: "))
      (setq sp   (vlax-curve-getstartpoint obj)
            ep   (vlax-curve-getendpoint obj)
            ppt  (vlax-curve-getclosestpointto entity (trans pt 1 0))
            ang1 (angle (vlax-curve-getpointatparam
                          obj
                          (+ (vlax-curve-getparamatpoint obj sp) 0.01)
                        )
                        sp
                 )
            ang2 (angle (vlax-curve-getpointatparam
                          obj
                          (* (vlax-curve-getparamatpoint obj ep) 0.99)
                        )
                        ep
                 )
      )
      (cond ((equal ppt sp 0.0001)
             (setq ppt (inters sp
                               (polar sp ang1 0.01)
                               pt
                               (polar pt (+ ang1 (/ pi 2.)) 0.01)
                               onseg
                       )
             )
             (if (= (vla-get-objectname obj) "AcDbLine")
               (vlax-put obj 'startpoint ppt)
             )
            )
            ((equal ppt ep 0.0001)
             (setq ppt (inters ep
                               (polar ep ang2 0.01)
                               pt
                               (polar pt (+ ang2 (/ pi 2.)) 0.01)
                               onseg
                       )
             )
             (if (= (vla-get-objectname obj) "AcDbLine")
               (vlax-put obj 'endpoint ppt)
             )
            )
      )
      (entmake (list '(0 . "LINE")
                     (cons 8 (cdr (assoc 8 (entget entity))))
                     (cons 10 (trans pt 1 0))
                     (cons 11 ppt)
               )
      )
    )
  )
  (princ)
)

« Last Edit: January 28, 2009, 04:34:04 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DEVITG

  • Bull Frog
  • Posts: 479
Re: line from a point perpendicular to a line
« Reply #42 on: January 28, 2009, 04:27:17 PM »
If work is pretty.

I did not notice that I 'm the original poster , about 4 years ago.

Thanks
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

alisafei

  • Guest
Re: line from a point perpendicular to a line
« Reply #43 on: January 29, 2009, 07:47:25 AM »
Welcome to TheSwamp.

Do you need the distance displayed on the command line or added to the drawing?


thanks for your reply admin. i wanted like this one
 
X cordinate of the point (Northing)
----------------------------------  distance between point and that line (may be polyline or something)
Y co-ordinate of the point (Easting)

like

N-1000.000
----------- 23.52m
E-2000.000


i think if the distance added to drawing will be better.
i use this type of command in our highway design works. if you have time, please try to update the code.
thanks again.

thanks.
« Last Edit: January 29, 2009, 07:50:40 AM by alisafei »

Hugo

  • Bull Frog
  • Posts: 422
Re: line from a point perpendicular to a line
« Reply #44 on: May 27, 2010, 10:41:49 AM »
Kan this be changed so that I can enter a fixed line length.

Kan man das so ändern, das ich eine fixe Linienlänge eingeben kann.

Danke