Author Topic: How to get bigger and smaller distance  (Read 21393 times)

0 Members and 1 Guest are viewing this topic.

fools

  • Newt
  • Posts: 72
  • China
Re: How to get bigger and smaller distance
« Reply #15 on: March 07, 2007, 12:17:43 AM »
Code: [Select]
(DEFUN c:test (/ CURPA ENDPA ENT PTLST)
  ;;For SPLINE & POLYLINE
  (SETQ ent (CAR (ENTSEL)))
  (SETQ ptlst (list (vlax-curve-getStartPoint ent)))
  (SETQ EndPa (VLAX-CURVE-GETENDPARAM ent))
  (SETQ CurPa 0)
  (REPEAT 500
    (SETQ ptlst (CONS (VLAX-CURVE-GETPOINTATPARAM
      ent
      (SETQ CurPa (+ CurPa (* EndPa 0.002)))
    )
    ptlst
      )
    )
  )
  (MaxDist ptlst)
)

(DEFUN MaxDist (pts / pt dist maxd maxl)
  (SETQ maxd 0)
  (WHILE (SETQ pt  (CAR pts)
       pts (CDR pts)
)
    (FOREACH item pts     
      (COND ((< maxd (SETQ dist (DISTANCE item pt)))
     (SETQ maxd dist
   maxl (LIST pt item dist)
     )
    )
      )
    )
  )
  (list (trans (car maxl) 0 1) (trans (cadr maxl) 0 1) (caddr dist))
)

Code: [Select]
Command: TEST
 Select object:
  ((-2332.33 1544.77 137220.0) (-9607.41 -12451.1 137220.0) 15773.8)
« Last Edit: March 07, 2007, 12:33:42 AM by fools »
Good good study , day day up . Sorry about my Chinglish .

fools

  • Newt
  • Posts: 72
  • China
Re: How to get bigger and smaller distance
« Reply #16 on: March 07, 2007, 12:36:57 AM »
max
Good good study , day day up . Sorry about my Chinglish .

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to get bigger and smaller distance
« Reply #17 on: March 07, 2007, 12:38:57 AM »
Ahhhhh I see,

The question was "what size box will this fit in"  .. yes ?

or perhaps it isn't  :lol:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

zemleroi

  • Guest
Re: How to get bigger and smaller distance
« Reply #18 on: March 07, 2007, 12:42:01 AM »
Ahhhhh I see,

The question was "what size box will this fit in"  .. yes ?

Yes, that is it.

Adesu

  • Guest
Re: How to get bigger and smaller distance
« Reply #19 on: March 07, 2007, 12:55:00 AM »
Hi fools,
it's great too,thanks.

fools

  • Newt
  • Posts: 72
  • China
Re: How to get bigger and smaller distance
« Reply #20 on: March 07, 2007, 01:28:00 AM »
 :-) Hi Adesu , you are welcome.
Change for minor axis:
Code: [Select]
(DEFUN c:test (/ CURPA ENDPA ENT PTLST LST MAXPTS)
  ;;For SPLINE & POLYLINE
  (SETQ ent (CAR (ENTSEL)))
  (SETQ ptlst (LIST (VLAX-CURVE-GETSTARTPOINT ent)))
  (SETQ EndPa (VLAX-CURVE-GETENDPARAM ent))
  (SETQ CurPa 0)
  (REPEAT 500
    (SETQ ptlst (CONS (VLAX-CURVE-GETPOINTATPARAM
ent
(SETQ CurPa (+ CurPa (* EndPa 0.002)))
      )
      ptlst
)
    )
  )
  (SETQ MaxPts (MaxDist ptlst))
  ;;Major Line
  (COMMAND "line"
   (TRANS (CAR MaxPts) 0 2)
   (TRANS (CADR MaxPts) 0 2)
   ""
  )
  (SETQ lst nil)
  (FOREACH item ptlst
    (SETQ lst (CONS (LIST (PtOnLine (TRANS (CAR MaxPts) 0 2)
    (TRANS (CADR MaxPts) 0 2)
    (TRANS item 0 2)
  )
  item
    )
    lst
      )
    )
  )
  (SETQ lst (VL-SORT lst
     (FUNCTION (LAMBDA (p1 p2) (< (CAR p1) (CAR p2))))
    )
  )
  ;;Minor Axis
  (COMMAND "line"
   (TRANS (CADAR lst) 0 2)
   (TRANS (CADR (LAST lst)) 0 2)
   ""
  )
)

(DEFUN MaxDist (pts / pt dist maxd maxl)
  (SETQ maxd 0)
  (WHILE (SETQ pt  (CAR pts)
       pts (CDR pts)
)
    (FOREACH item pts     
      (COND ((< maxd (SETQ dist (DISTANCE item pt)))
     (SETQ maxd dist
   maxl (LIST pt item dist)
     )
    )
      )
    )
  )
  maxl
)

(defun PtOnLine (p1 p2 p3 / p c)
  (setq p p3)
  (apply '+
(mapcar '(lambda (b)
    (setq c (- (* (car p) (cadr b)) (* (cadr p) (car b)))
  p b
    )
    c
  )
(list p1 p2 p3)
)
  )
)
Good good study , day day up . Sorry about my Chinglish .

Adesu

  • Guest
Re: How to get bigger and smaller distance
« Reply #21 on: March 07, 2007, 01:44:26 AM »
Hi fools ,
Wow........it's fantastic and great.
Thanks a milions.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: How to get bigger and smaller distance
« Reply #22 on: March 07, 2007, 02:08:41 AM »

Hi fools!
Your program finds not the smallest external container...

fools

  • Newt
  • Posts: 72
  • China
Re: How to get bigger and smaller distance
« Reply #23 on: March 07, 2007, 02:52:31 AM »
 :-) HI  Evgeniy , you are right!
The minor axis isn't the smallest external container.
Because I got the major axis, I want to draw a line perpendicular to it.
It's only for make a rectangle,not the smallest external container.

Good good study , day day up . Sorry about my Chinglish .

Adesu

  • Guest
Re: How to get bigger and smaller distance
« Reply #24 on: March 07, 2007, 07:01:15 PM »
:-) HI  Evgeniy , you are right!
The minor axis isn't the smallest external container.
Because I got the major axis, I want to draw a line perpendicular to it.
It's only for make a rectangle,not the smallest external container.



I'm not yet understand,how you both create a drawing rectangular out from object.

fools

  • Newt
  • Posts: 72
  • China
Re: How to get bigger and smaller distance
« Reply #25 on: March 13, 2007, 07:50:26 AM »
I'm not yet understand,how you both create a drawing rectangular out from object.
The rectangular isn't made by my code.I draw it after got the four points.
Good good study , day day up . Sorry about my Chinglish .

Adesu

  • Guest
Re: How to get bigger and smaller distance
« Reply #26 on: March 13, 2007, 07:52:27 PM »
I'm not yet understand,how you both create a drawing rectangular out from object.
The rectangular isn't made by my code.I draw it after got the four points.

Oh....I see,my question now become clear,thanks for your info.

zemleroi

  • Guest
Re: How to get bigger and smaller distance
« Reply #27 on: March 19, 2007, 02:04:53 PM »
Hello

When I try to use this code on a 3-dimensional polyline (a polyline on an inclined plane: see attached file), the function gives the size of the bounding box with 3 dimensions. Is it possible to measure a two dimensional bounding box on the plane that the object is on?

Dmitri

Code: [Select]
(defun c:test (/ E LST MA MI)
 (if (setq e (car (entsel "\n Select object: ")))
  (progn (setq e   (vla-copy (vlax-ename->vla-object e))
               lst nil
         ) ;_  setq
         (repeat 1000
          (vla-GetBoundingBox e 'mi 'ma)
          (setq
           lst (cons (mapcar (function -) (vlax-safearray->list ma) (vlax-safearray->list mi))
                     lst
               ) ;_  cons
          ) ;_  setq
          (vla-rotate e (vlax-3d-point 0. 0.) (/ pi 1000.))
         ) ;_  repeat
         (vla-Delete e)
   (princ "\n Bounding box object with minimal length: ")
   (princ (assoc (car (apply 'mapcar (cons 'min lst))) lst))
   (princ)
  ) ;_  progn
 ) ;_  if
) ;_  defun

test function:
Code: [Select]
Command: test
 Select object:
 Bounding box object with minimal length: (2427.69 12609.7 13950.0)
[/quote]

gile

  • Gator
  • Posts: 2505
  • Marseille, France
Re: How to get bigger and smaller distance
« Reply #28 on: March 19, 2007, 04:15:12 PM »
Hi,

Vla-getBoundingBox always returns the bounding-box about WCS.
I wrote a routine to draw the bounding-box of an object about current UCS (see attached file)
Adapted from it here's one to get the coordinates of the bounding-box of a 2D object about its OCS (if different from WCS)
Thanks again to Doug Broad for matrix handling

Edit: change 'norm' from variable to argument.

Code: [Select]
(defun OCS-Bbox (obj norm / minpt maxpt)
  (vl-load-com)
  (vla-TransformBy
    obj
    (vlax-Tmatrix
      (append
(mapcar
  '(lambda (v o)
     (append (trans v norm 0 t) (list o))
   )
  (list '(1 0 0) '(0 1 0) '(0 0 1))
  (trans '(0 0 0) 0 norm)
)
(list '(0 0 0 1))
      )
    )
  )
  (vla-getBoundingBox obj 'minpt 'maxpt)
  (vla-TransformBy
    obj
    (vlax-tmatrix
      (append
(mapcar
  '(lambda (vector origin)
     (append (trans vector 0 norm t) (list origin))
   )
  (list '(1 0 0) '(0 1 0) '(0 0 1))
  (trans '(0 0 0) norm 0)
)
(list '(0 0 0 1))
      )
    )
  )
  (list (vlax-safearray->list minpt)
(vlax-safearray->list maxpt)
  )
)
« Last Edit: March 23, 2007, 05:15:40 PM by gile »
Speaking English as a French Frog

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get bigger and smaller distance
« Reply #29 on: March 20, 2007, 11:19:08 AM »
Gile,
I was trying to get this to work with your routine but the spline has no Normal property.
Did i miss something?

Code: [Select]
(defun c:test (/ E LST MA MI cnt ang)
  (if (setq e (car (entsel "\n Select object: ")))
    (progn
      (setq e   (vla-copy (vlax-ename->vla-object e))
            cnt 1000
            ang (/ pi cnt)
      )
      (repeat cnt
        (setq lst (cons (OCS-Bbox e) lst))
        (vla-rotate e (vlax-3d-point 0. 0.) ang)
      )
      (vla-delete e)
      (princ "\n Bounding box object with minimal length: ")
      (princ (assoc (car (apply 'mapcar (cons 'min lst))) lst))
      (princ)
    )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.