Author Topic: Perp Point to Object Perpindicular to Polyline  (Read 2813 times)

0 Members and 1 Guest are viewing this topic.

bchapman

  • Guest
Perp Point to Object Perpindicular to Polyline
« on: November 22, 2011, 10:23:45 PM »
Title confusing enough?  I need to figure out how to get the coordinate of a point along a polyline that is perpendicular to any adjacent object I select. Not sure this is possible... I've been rackin' my brain for the last few days... only thing I could think of would be to generate coords for each vertex of the adjacent polylines, and the do some sort of process of elimination by distance.  Any thoughts would (or better, a routine), would be helpful.

Thanks!

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Perp Point to Object Perpindicular to Polyline
« Reply #1 on: November 22, 2011, 10:53:11 PM »
Look at vlax-curve-getClostestPointTo and/or vlax-curve-getClosestPointToProjection.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

bchapman

  • Guest
Re: Perp Point to Object Perpindicular to Polyline
« Reply #2 on: November 23, 2011, 11:09:33 AM »
Thanks Alan, understood.  I've used it before.  I know how to come up with all the coordinates, what I'm struggling with is how to limit the final coordinates I need to the closest first and last vertice of the adjacent polylines, rather then selecting them all.  Any thoughts on this matter?

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Perp Point to Object Perpindicular to Polyline
« Reply #3 on: November 23, 2011, 11:38:25 AM »
Maybe something along the lines of:

  • Collect a list of Vertex Coordinates (vlax-curve-getpointatparam / DXF Group 10)
  • Iterate over the list of Vertex Coordinates, using vlax-curve-getclosestpointto to get the closest point on the vertical line to the vertex.
  • Sort the set of Closest Points and Vertices by distance between Closest Point and Vertex.
  • Take the first two points in the sorted list.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Perp Point to Object Perpindicular to Polyline
« Reply #4 on: November 23, 2011, 11:47:34 AM »
Here's a hacked together example of the above described method:

Code: [Select]
(defun c:test ( / e1 e2 lst p1 p2 )
    (if
        (and
            (setq e1 (car (entsel "\nSelect LWPolyline: ")))
            (eq "LWPOLYLINE" (cdr (assoc 0 (entget e1))))
            (setq e2 (car (entsel "\nSelect Vertical Line: ")))
            (wcmatch (cdr (assoc 0 (entget e2))) "*LINE")
        )
        (progn
            (setq lst
                (vl-sort
                    (apply 'append
                        (mapcar
                            (function
                                (lambda ( pair / pt )
                                    (if (= 10 (car pair))
                                        (list
                                            (list
                                                (setq pt (vlax-curve-getclosestpointto e2 (cdr pair)))
                                                (distance pt (cdr pair))
                                            )
                                        )
                                    )
                                )
                            )
                            (entget e1)
                        )
                    )
                   '(lambda ( a b ) (< (cadr a) (cadr b)))
                )
            )
            (setq p1 (caar  lst)
                  p2 (caadr lst)
            )
            (foreach x (list p1 p2)
                (entmake (list '(0 . "POINT") (cons 10 x)))
            )
        )
    )
    (princ)
)

The two required points are bound to variables 'p1' and 'p2', I have created points as an example.

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Perp Point to Object Perpindicular to Polyline
« Reply #5 on: November 23, 2011, 11:55:08 AM »
I knew you couldn't resist writing it  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Perp Point to Object Perpindicular to Polyline
« Reply #6 on: November 23, 2011, 11:56:04 AM »
I knew you couldn't resist writing it  :-D
saved me the trouble. :-P
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Perp Point to Object Perpindicular to Polyline
« Reply #7 on: November 23, 2011, 11:58:57 AM »
Me too  :lmao:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Perp Point to Object Perpindicular to Polyline
« Reply #8 on: November 23, 2011, 12:04:23 PM »
I knew you couldn't resist writing it  :-D

 :-D  After I'd explained how to do it I just couldn't resist  :-P

bchapman

  • Guest
Re: Perp Point to Object Perpindicular to Polyline
« Reply #9 on: November 23, 2011, 02:35:40 PM »
Would have taken me days... Thanks lee... are you available for contract? Not sure your site is clear.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Perp Point to Object Perpindicular to Polyline
« Reply #10 on: November 23, 2011, 06:24:35 PM »
Would have taken me days... Thanks lee... are you available for contract? Not sure your site is clear.

You're welcome. Send me an email through the Contact Form on my site and we can discuss it further if you like  :-)