Author Topic: bounding box along direction  (Read 4441 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: bounding box along direction
« Reply #15 on: August 21, 2023, 01:10:22 PM »
it's not perfect,
(because it doesn't analyze curves but only segments),
LM:ent->pts builds approximations for curves, so it's better than you think :)
... curves converted into segments ...
I have seen the point list that it makes...
and I have seen how It works (very well)
... however It Is an approximation ...
 however it Is more than enough, for what i need
« Last Edit: August 21, 2023, 02:09:53 PM by domenicomaria »


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1447
  • Marco
Re: bounding box along direction
« Reply #17 on: August 21, 2023, 03:08:10 PM »
See replay #1 and #11...  :knuppel2: :whistling:

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: bounding box along direction
« Reply #18 on: August 21, 2023, 05:21:35 PM »
Here is an exact solution for polylines.
It is a mathematical solution, no entity is changed at all.

Code - Auto/Visual Lisp: [Select]
  1. (defun _rot (p a)
  2.   (list
  3.     (- (* (car p) (cos a)) (* (cadr p) (sin a)))
  4.     (+ (* (car p) (sin a)) (* (cadr p) (cos a)))
  5.   )
  6. )
  7.  
  8. (defun _m2p (a b) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) a b))
  9.  
  10. (defun _pline_rotated_bb (e u / a b c d m o p r s a1 a2)
  11.         b (vlax-curve-getendparam e)
  12.   )
  13.   (while (<= a b)
  14.           r (_rot p (- u))
  15.           a1 (if a1 (mapcar 'min a1 r) r)
  16.           a2 (if a2 (mapcar 'max a2 r) r)
  17.           s (vlax-curve-getsecondderiv e a)
  18.           d (distance '(0.0 0.0) s)
  19.     )
  20.     (if
  21.       (> d 0.0)
  22.       (progn
  23.         (setq o (polar
  24.                   (setq m (vlax-curve-getpointatparam e (+ a 0.5)))
  25.                   (angle m (_m2p p (vlax-curve-getpointatparam e (rem (1+ a) b))))
  26.                   d
  27.                 )
  28.         )
  29.         (foreach x '(0.0 0.5 1.0 1.5)
  30.           (setq p (polar o (+ u (* x pi)) d))
  31.           (if
  32.             (and
  33.               (setq c (vlax-curve-getparamatpoint e p))
  34.               (< a c (1+ a))
  35.             )
  36.             (setq r (_rot p (- u))
  37.                   a1 (mapcar 'min a1 r)
  38.                   a2 (mapcar 'max a2 r)
  39.             )
  40.           )
  41.         )
  42.       )
  43.     )
  44.     (setq a (1+ a))
  45.   )
  46.   (list
  47.     (_rot a1 u)
  48.     (_rot (list (car a2) (cadr a1)) u)
  49.     (_rot a2 u)
  50.     (_rot (list (car a1) (cadr a2)) u)
  51.   )
  52. )
  53.  
  54. (defun c:test ( / *error* e u bb)
  55. ;;;  (setq *error* (err))
  56.   (if
  57.     (and
  58.       (setq e (ssget "_+.:S" '((0 . "*POLYLINE"))))
  59.       (setq u (getangle "\nSpecify rotation angle: "))
  60.       (setq bb (_pline_rotated_bb (ssname e 0) u))
  61.     )
  62.     (entmakex
  63.       (append
  64.        '(
  65.           (0 . "LWPOLYLINE")
  66.           (100 . "AcDbEntity")
  67.           (100 . "AcDbPolyline")
  68.           (90 . 4)
  69.           (70 . 1)
  70.         )
  71.         (mapcar
  72.          '(lambda (p)
  73.             (cons 10 p)
  74.           )
  75.           bb
  76.         )
  77.       )
  78.     )
  79.   )
  80. ;;;  (*error* nil)
  81.   (princ)
  82. )

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: bounding box along direction
« Reply #19 on: August 22, 2023, 02:41:45 AM »
See replay #1 and #11...  :knuppel2: :whistling:
Marco, I apologize.
I didn't really notice the answer #11 !  :whistling:

Bravo.
Very interesting !

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: bounding box along direction
« Reply #20 on: August 22, 2023, 02:49:09 AM »
@DEXUS
Quote
Here is an exact solution for polylines.
It is a mathematical solution, no entity is changed at all.

It works perfectly !

you are very good !

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: bounding box along direction
« Reply #21 on: August 22, 2023, 03:02:52 AM »
See replay #1 and #11...  :knuppel2: :whistling:
. . . and your code works also with line, circle, arc, ellipse . . .
. . . while fails with spline, insert . . .

dexus

  • Newt
  • Posts: 190
Re: bounding box along direction
« Reply #22 on: August 22, 2023, 03:22:34 AM »
@DEXUS
Quote
Here is an exact solution for polylines.
It is a mathematical solution, no entity is changed at all.

It works perfectly !

you are very good !
I would love to take credit, but it should be @Stefan :wink:

ribarm

  • Gator
  • Posts: 3187
  • Marko Ribar, architect
Re: bounding box along direction
« Reply #23 on: August 22, 2023, 03:56:31 AM »
I think Stefan will fail if reference entity is INSERT...
I've included all that's possible in my BBox.lsp... It'll try even with nested inserts that overlap each other...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: bounding box along direction
« Reply #24 on: August 22, 2023, 04:34:07 AM »
@ Dexus and Stefan !
Quote
I would love to take credit, but it should be @Stefan :wink:

I'm always very distracted !  :-)

Stefan, YOU you are very good !

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: bounding box along direction
« Reply #25 on: August 22, 2023, 04:36:02 AM »
I think Stefan will fail if reference entity is INSERT...
I've included all that's possible in my BBox.lsp... It'll try even with nested inserts that overlap each other...

The code of Stefan is only for polylines ...

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: bounding box along direction
« Reply #26 on: August 22, 2023, 04:39:39 AM »

Thanks. My wife would disagree :)
But she knows nothing about lisp

ribarm

  • Gator
  • Posts: 3187
  • Marko Ribar, architect
Re: bounding box along direction
« Reply #27 on: August 22, 2023, 05:01:33 AM »
I've just tried my BBox.lsp and it fails with INSERTs too... I've fixed it only not to exit with error and I think that it explodes blocks if it runs on them, so be careful with *.lsp... But for curves it should work well and in 3d UCS... HTH., M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

xdcad

  • Bull Frog
  • Posts: 424
Re: bounding box along direction
« Reply #28 on: November 20, 2023, 11:02:38 PM »
I think Stefan will fail if reference entity is INSERT...
I've included all that's possible in my BBox.lsp... It'll try even with nested inserts that overlap each other...

The code of Stefan is only for polylines ...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (if (setq ss (xdrx-ssget "\nSelect Draw Boundingbox Objects<Quit>:"))
  3.     (progn
  4.       (while (setq e (xdrx-entsel
  5.                        "\nPick a Direction Line<Quit>:"
  6.                        '((0 . "*polyline,line"))
  7.                      )
  8.              )
  9.         (setq xdir (xdrx-getpropertyvalue (car e) "firstderiv" (cadr e))
  10.               box  (xdrx-entity-box ss xdir)
  11.         )
  12.         (xdrx-polyline-make (xdrx-points-ucs2wcs box) t)
  13.         (xdrx-setpropertyvalue (entlast) "color" (xdrx-math-rand 1 220))
  14.       )
  15.     )
  16.   )
  17.   (princ)
  18. )

The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net

domenicomaria

  • Swamp Rat
  • Posts: 720
Re: bounding box along direction
« Reply #29 on: November 21, 2023, 02:31:18 AM »
anyway, when there is a solid hatch, there are allways problems...
... but it doesn't depend from your great xdrx-entity-box function ...
which maybe should be called xdrx-ss-box