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

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 725
bounding box along direction
« on: August 21, 2023, 03:12:38 AM »
I need to know the red size in the second attached image.
Without rotating anything !
Is it possible ?
« Last Edit: August 21, 2023, 03:20:36 AM by domenicomaria »


ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Re: bounding box along direction
« Reply #2 on: August 21, 2023, 04:44:33 AM »
Rotate UCS and apply this routine to get BBox, then extract only width (red line)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: bounding box along direction
« Reply #3 on: August 21, 2023, 05:07:31 AM »
build a list of coordinates (curves must be approximated)
then either rotate every point around the common center or project them on a red line
then find min and max

some helper functions https://www.theswamp.org/index.php?topic=37319.msg423645#msg423645

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: bounding box along direction
« Reply #4 on: August 21, 2023, 05:19:33 AM »
Rotate UCS and apply this routine to get BBox, then extract only width (red line)...

Thank you Ribarm!
Works !
But I was hoping for a mathematical solution. . .
Because this routine does a number of very spectacular things,
while I'm looking for something that can't be seen,
that makes calculations "in secret" ...

But I realize that it is a very complicated thing!

I have to try to do something only for lines, circles and arcs...
It shouldn't be hard...

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: bounding box along direction
« Reply #5 on: August 21, 2023, 05:20:52 AM »
build a list of coordinates (curves must be approximated)
then either rotate every point around the common center or project them on a red line
then find min and max

some helper functions https://www.theswamp.org/index.php?topic=37319.msg423645#msg423645

VovKa you have allways great ideas ...
I will give it a try !
Grazie.
Ciao

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8766
  • AKA Daniel
Re: bounding box along direction
« Reply #6 on: August 21, 2023, 06:39:03 AM »
If that’s a polyline, made to represent an object, you can store a direction in XData when it’s created.
Then, you can get the direction at a later time, even if it’s been rotated 

dexus

  • Bull Frog
  • Posts: 210
Re: bounding box along direction
« Reply #7 on: August 21, 2023, 09:23:51 AM »
I tried to make an example by projecting the lines onto the line and getting the min and max. (like VovKa suggested)
It uses the code from http://www.lee-mac.com/entitytopointlist.html to make the pointlist.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bbang (/ pl lin pts)
  2.   (and
  3.     (setq pl (car (entsel "\nSelect polyline: ")))
  4.     (setq pts (LM:ent->pts pl 50.0)) ; Get point list
  5.     (setq line (car (entsel "\nSelect angle line: ")))
  6.     (setq line (entget line))
  7.     (setq line (list (cdr (assoc 10 line)) (cdr (assoc 11 line)))) ; Start and end point
  8.     (setq line (cons (mapcar '- (cadr line) (car line)) line)) ; Add relative point
  9.     (setq pts (mapcar (function (lambda (pt) (caddr (trans (mapcar '- pt (cadr line)) 0 (car line))))) pts)) ; get distances on line
  10.     (princ "\nDistance on line: ") (princ (- (apply 'max pts) (apply 'min pts))) ; Subtract shortest from longest to get the distance
  11.   )
  12.   (princ)
  13. )
« Last Edit: August 21, 2023, 09:55:43 AM by dexus »

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: bounding box along direction
« Reply #8 on: August 21, 2023, 09:42:47 AM »
@Dexus

It works very well !

it's enough for what I need !

that's exactly what vovKa suggested !

it's not perfect,
(because it doesn't analyze curves but only segments),
but for what I have to do,
it's fine.

Thank you all.


domenicomaria

  • Swamp Rat
  • Posts: 725
Re: bounding box along direction
« Reply #9 on: August 21, 2023, 09:54:03 AM »
@Dexus
. . . your modified version has a little problem . . .

dexus

  • Bull Frog
  • Posts: 210
Re: bounding box along direction
« Reply #10 on: August 21, 2023, 09:56:30 AM »
@Dexus
. . . your modified version has a little problem . . .
It was missing a bracket, should work now.  :-D

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: bounding box along direction
« Reply #11 on: August 21, 2023, 10:39:05 AM »
Please post your sample DWG. > Edit...
Code: [Select]
(defun c:test (/ ent line llp urp )
    (and
        (setq ent (car (entsel "\nSelect polyline: ")))
        (setq line (car (entsel "\nSelect angle line: ")))
        (progn
            (command "_.UCS" "_ENTITY" line)           
            (gc:UcsBoundingBox ent 'llp 'urp)
            (command "_.rectangle" "_non" llp "_non" urp)
            (command "_.UCS" "_P")           
        )
    )
    (princ)
)
;; gc:UcsBoundingBox by Gile
;; Returns the UCS coordinates of the object bounding box about current UCS
;;
;; Arguments
;; obj: an entity (ENAME or VLA-OBJCET)
;; _OutputMinPtSym: a quoted symbol (output)
;; _OutputMaxPtSym: a quoted symbol (output)


(defun gc:UcsBoundingBox ( obj _OutputMinPtSym _OutputMaxPtSym )
    (and (= (type obj) 'ename)
         (setq obj (vlax-ename->vla-object obj))
    )
    (vla-transformby obj (vlax-tmatrix (gc:TMatrixFromTo 1 0)))
    (vla-getboundingbox obj _OutputMinPtSym _OutputMaxPtSym)
    (vla-transformby obj (vlax-tmatrix (gc:TMatrixFromTo 0 1)))
    (set _OutputMinPtSym (vlax-safearray->list (eval _OutputMinPtSym)))
    (set _OutputMaxPtSym (vlax-safearray->list (eval _OutputMaxPtSym)))
)


;; gc:TMatrixFromTo by Gile
;; Returns the 4X4 transformation matrix from a coordinate system to an other one
;;
;; Arguments
;; from to: same arguments as for the 'trans' function


(defun gc:TMatrixFromTo ( from to )
    (append
        (mapcar
            (function
                (lambda   ( v o )
                    (append (trans v from to t) (list o))
                )
            )
           '(
                (1.0 0.0 0.0)
                (0.0 1.0 0.0)
                (0.0 0.0 1.0)
            )
            (trans '(0.0 0.0 0.0) to from)
        )
       '((0.0 0.0 0.0 1.0))
    )
)

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: bounding box along direction
« Reply #12 on: August 21, 2023, 11:16:44 AM »


VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: bounding box along direction
« Reply #14 on: August 21, 2023, 11:47:42 AM »
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 :)