Author Topic: Maximum distance between two LWPolylines  (Read 1985 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 494
Maximum distance between two LWPolylines
« on: November 08, 2017, 03:45:58 AM »
Hi

How to find maximum distance of any two points between two LWPolylines. Both polylines are are Zero Elevation.

One way is to break any one polyline into 100 (or more) segments (points) and then loop through the points and find the minimum distance with other polyline (using vlax-curve-getClosestPointTo), storing all values in a list and then finally taking the maximum value of all the distances.

However, this approach is largely dependent upon the number of segments. Is there any other direct way to do it ?

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Maximum distance between two LWPolylines
« Reply #1 on: November 08, 2017, 04:25:28 PM »
Can you post an example picture of the problem for context?

I'd probably start with the bounding boxes of both lines and see which points lie on the boundary of both boxes. You can then loop through this smaller collection of points to find the greatest distance. See below (points to use in blue circles):

"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Maximum distance between two LWPolylines
« Reply #2 on: November 08, 2017, 04:27:14 PM »
or perhaps even one for both?

"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Maximum distance between two LWPolylines
« Reply #3 on: November 08, 2017, 04:39:39 PM »
Don't think that will work:

Found some info on this HERE to get furthest point from a point.
« Last Edit: November 08, 2017, 04:47:31 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Maximum distance between two LWPolylines
« Reply #4 on: November 08, 2017, 04:49:18 PM »
Don't think that will work:

Found some info on this HERE to get furthest point from a point.

Yep, good catch!
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

ahsattarian

  • Newt
  • Posts: 112
Re: Maximum distance between two LWPolylines
« Reply #5 on: August 01, 2021, 06:22:09 AM »
Try This  :



Code - Auto/Visual Lisp: [Select]
  1. (defun c:a ()
  2.   (setq fuzzy 0.00001)
  3.   (defun sub1 ()
  4.     (setq i (1+ i))
  5.     (setq zarib (float (expt 2 i)))
  6.     (setq p1 (vlax-curve-getpointatparam obj (- m (/ (- k2 k1) zarib))))
  7.     (setq p2 (vlax-curve-getpointatparam obj (+ m (/ (- k2 k1) zarib))))
  8.     (if (func (distance po p1) (distance po p2))
  9.       (setq pt p1)
  10.       (setq pt p2)
  11.     )
  12.     (setq m (vlax-curve-getparamatpoint obj pt))
  13.     (cond ((> (distance p1 p2) (* (getvar "viewsize") fuzzy)) (sub1)))
  14.   )
  15.   (defun sub2 ()
  16.     (redraw)
  17.     (setq func (eval >))
  18.     (setq m (* (+ k1 k2) 0.5))
  19.     (setq i 1)
  20.     (sub1)
  21.     (setq pt1 pt)
  22.     (grdraw po pt1 1 1)
  23.     (setq func (eval <))
  24.     (setq m (* (+ k1 k2) 0.5))
  25.     (setq i 1)
  26.     (sub1)
  27.     (setq pt2 pt)
  28.     (grdraw po pt2 3 1)
  29.     (grdraw po pt3 4 1)
  30.     (setq t1 "\r Maximum Distance  :  ")
  31.     (setq t2 (rtos (distance po pt1) (getvar "lunits") 6))
  32.     (setq t3 " - Minimum Distance  :  ")
  33.     (setq t4 (rtos (distance po pt2) (getvar "lunits") 6))
  34.     (setq t5 " - Closest Distance  :  ")
  35.     (setq t6 (rtos (distance po pt3) (getvar "lunits") 6))
  36.     (princ (strcat t1 t2 t3 t4 t5 t6))
  37.   )
  38.   (setq s (car (entsel "\n Select Shape : ")))
  39.   (redraw s 3)
  40.   (setq obj (vlax-ename->vla-object s))
  41.   (setvar "cursorsize" 5)
  42.   (defun *error* (msg) (setvar "cursorsize" 100) (redraw s 4) (princ)) ;| #error |;
  43.   (setq g 1)
  44.   (while (= g 1)
  45.     (setq gr (grread t 15 0)) ;|  #grread  |;
  46.     (setq code (car gr))
  47.     (setq po (cadr gr))
  48.     (cond
  49.       ((= code 5) (sub2)) ;|  Bedune Click  |;
  50.       ((= code 3) (sub2) (setq g 0)) ;|  Click Beshe  |;
  51.       ((= code 2) (setq g 0)) ;|  Type Beshe  |;
  52.       ((= code 25) (setq g 0)) ;|  #mouse #right-click  |;
  53.     )
  54.   )
  55.   (redraw s 4)
  56.   (princ)
  57. )




ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Maximum distance between two LWPolylines
« Reply #6 on: June 27, 2022, 11:45:35 PM »
Hi @Ah...
I saw your vids on youtube...
Very nice, but what for?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube