### 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 »

#### domenicomaria

• Swamp Rat
• Posts: 720
##### Re: bounding box along direction
« Reply #16 on: August 21, 2023, 02:46:00 PM »

#### 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...
« Last Edit: August 21, 2023, 04:30:28 PM by Marc'Antonio Alessi »

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

#### 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...
Marco, I apologize.
I didn't really notice the answer #11 !

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

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

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

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)

• 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.       (while (setq e (xdrx-entsel
4.                        "\nPick a Direction Line<Quit>:"
5.                        '((0 . "*polyline,line"))
6.                      )
7.              )
8.         (setq xdir (xdrx-getpropertyvalue (car e) "firstderiv" (cadr e))
9.               box  (xdrx-entity-box ss xdir)
10.         )
11.         (xdrx-polyline-make (xdrx-points-ucs2wcs box) t)
12.         (xdrx-setpropertyvalue (entlast) "color" (xdrx-math-rand 1 220))
13.       )
14.     )
15.   )
16.   (princ)
17. )

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