Author Topic: How to get object inner a circle  (Read 3168 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
How to get object inner a circle
« on: October 29, 2007, 08:56:28 PM »
Hi Alls,
I have a problem, how to get object like text, line or circle, alls that object put inner a circle.
I want only one pick at a circle (white color),any idea ?

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: How to get object inner a circle
« Reply #1 on: October 29, 2007, 10:02:17 PM »
hmmm, the easiest way mathematically would be to create a vector of each corner of each objects bounding box <edit> from circle centre </edit>, get its magnitude and compare it with the radius of the circle.
mag <= circle radius = in circle
mag > circle radius = outside circle.

would that be close enough?
« Last Edit: October 29, 2007, 10:18:28 PM by MickD »
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

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

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: How to get object inner a circle
« Reply #2 on: October 29, 2007, 10:25:00 PM »
eg.

p1 would be the bottom left corner of objects' bbox p1.? where ? is the x, y or z coord typically.
cc is the circle centre.
v1 is the vector from cc to p1
mag1 is the magnitude v1

first get v1 (in 2d to keep it short) -

v1.x = cc.x - p1.x
v1.y = cc.y - p1.y

now calc the magnitude of v1
mag1 = sqrt((v1.x*v1.x) + (v1.y*v1.y))

now test -

if (mag1 < circRadius)
    return true.

hth
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get object inner a circle
« Reply #3 on: October 29, 2007, 10:28:28 PM »
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.

Adesu

  • Guest
Re: How to get object inner a circle
« Reply #4 on: October 29, 2007, 10:31:23 PM »
maybe i have solution like this.
Code: [Select]
(defun c:test (/ bp cnt objname p1 p2 p3 p4 rad ss sse ssex ssl ssnx ssx)
   (if
      (setq ss (car (entsel "\nPick a circle object")))
      (progn
         (setq sse (entget ss))
         (setq bp (cdr (assoc 10 sse)))
         (setq rad (cdr (assoc 40 sse)))
         (setq p1 (polar bp pi rad))
         (setq p2 (polar p1 (* pi 1.5) rad))
         (setq p3 (polar bp 0 rad))
         (setq p4 (polar p3 (* pi 0.5) rad))
         (setq ssx (ssget "_w" p2 p4))
         (setq ssl (sslength ssx))
         (setq cnt 0)
         (repeat
            ssl
            (setq ssnx (ssname ssx cnt))
            (setq ssex (entget ssnx))
            (setq objname (cdr (assoc 0 ssex)))
            (alert (strcat "\nThis object is " objname))
            (setq cnt (1+ cnt))
            ) ; repeat
         )    ; progn
      (alert "\nInvalid selected object,try again")
      )       ; if
   (princ)
   )          ; defun


eg.

p1 would be the bottom left corner of objects' bbox p1.? where ? is the x, y or z coord typically.
cc is the circle centre.
v1 is the vector from cc to p1
mag1 is the magnitude v1

first get v1 (in 2d to keep it short) -

v1.x = cc.x - p1.x
v1.y = cc.y - p1.y

now calc the magnitude of v1
mag1 = sqrt((v1.x*v1.x) + (v1.y*v1.y))

now test -

if (mag1 < circRadius)
    return true.

hth


qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: How to get object inner a circle
« Reply #5 on: November 04, 2007, 05:14:33 AM »
Last time I wrote a such like code
To move the text to the near circle center. It use the "cp" selection of some points on the circle, maybe you can use the "wp" selection method



Code: [Select]
;;; -----------------------------------------------------------------;
;;; Purpose: move the text inside circle to the center of the circle ;
;;; write by qjchen                                                  ;
;;; http://qjchen.yo2.cn                                             ;
;;; http://chenqj.blogspot.com                                       ;
;;; -----------------------------------------------------------------;
(defun c:test (/ std-sslist movetocenter)
  (command "_undo" "_be")
  (setting)
 
  (defun std-sslist (ss / n lst)
    (if (eq 'pickset (type ss))
      (repeat (setq n (fix (sslength ss))) ; fixed
(setq lst (cons (ssname ss (setq n (1- n))) lst))
      )
    )
  )
  (defun movetocenter (/ a x txtobj center_circle outline b bobject objss
res midpoint
      )
    (setq a (ssget '((0 . "circle"))))
    (setq a (std-sslist a))
    (foreach x a
      (setq txtobj nil)
      (setq pub x)
      (setq center_circle (assoc 10 (entget x)))
      (setq outline (objectpoint (entget x)))
      (setq b (ssget "_cp" outline '((0 . "TEXT"))))
      (setq bobject (ssname b 0))
      (setq objss (vlax-ename->vla-object bobject))
      (setq res (xyval1 objss))
      (setq midpoint (midp (list (nth 0 res) (nth 1 res)) (list
(nth 2 res)
(nth 3 res)
  )
     )
      )
      (command "move" bobject "" midpoint (cdr center_circle))
    )
  )
  (movetocenter)
  (resetting)
  (command "_undo" "_e")
)

;;; the subrountine is write by qjchen to get selection by circle
;;; and lwpolyline
(defun objectpoint (obj / name ori i r w_pl_lst wlist)
  (setq name (cdr (assoc 0 obj)))
  (cond
    ((= name "CIRCLE")
      (setq ori (cdr (assoc 10 obj)))
      (setq r (cdr (assoc 40 obj)))
      (setq i 0)
      (repeat 30
(setq wlist (append
      wlist
      (list (polar ori (* 2 pi (/ i 30.0)) r))
    )
)
(setq i (1+ i))
      )
    )
    ((= name "LWPOLYLINE")
      (defun w_pl_lst (ent / pt_list)
(foreach x ent
  (if (= (car x) 10)
    (setq pt_list (append
    (list (cdr x))
    pt_list
  )
    )
  )
)
pt_list
      )
      (setq wlist (w_pl_lst obj))
    )
  )
  wlist
)
;;; _ end of xyval
;;; ---The following codes are copy from Tony Hotchkiss at cadalyst
;;; Get the boundingbox of one object
(defun xyval1 (obj / minpt maxpt topy bottmy leftx rightx)
  (vla-GetBoundingBox obj 'minpt 'maxpt)
  (setq pt1 (vlax-safearray->list minpt)
pt2 (vlax-safearray->list maxpt)
topy (cadr pt2)
bottmy (cadr pt1)
leftx (car pt1)
rightx (car pt2)
  )        ; _ end of setq
  (list leftx bottmy rightx topy)
)
;;; The error function
(defun err (s)
  (if (= s "Function cancelled")
    (princ "\nALIGNIT - cancelled: ")
    (progn
      (princ "\nALIGNIT - Error: ")
      (princ s)
      (terpri)
    )        ; _ end of progn
  )        ; _ end of if
  (resetting)
  (princ "SYSTEM VARIABLES have been reset\n")
  (princ)
)
;;; err
;;; setting and resetting the system variables
(defun setv (systvar newval / x)
  (setq x (read (strcat systvar "1")))
  (set x (getvar systvar))
  (setvar systvar newval)
)
;;; setv
(defun setting ()
  (setq oerr *error*)
  (setq *error* err)
  (setv "BLIPMODE" 0)
  (setv "CMDECHO" 0)
  (setv "OSMODE" 0)
)
;;; setting
(defun rsetv (systvar)
  (setq x (read (strcat systvar "1")))
  (setvar systvar (eval x))
)
;;; rsetv
(defun resetting ()
  (rsetv "BLIPMODE")
  (rsetv "CMDECHO")
  (rsetv "OSMODE")
  (setq *error* oerr)
)
;;; -------------------------------------------------------
(defun midp (p1 p2)
  (mapcar
    '(lambda (x)
       (/ x 2.)
     )
    (mapcar
      '+
      p1
      p2
    )
  )
)
;;; The following code taken from Mr.Tony Hotchkiss at Cadalyst
(defun err (s)
  (if (= s "Function cancelled")
    (princ "\nregion clean - cancelled: ")
    (progn
      (princ "\nregion clean - Error: ")
      (princ s)
      (terpri)
    )        ; _ end of progn
  )        ; _ end of if
  (resetting)
  (princ "SYSTEM VARIABLES have been reset\n")
  (princ)
)
;;; err
;;; setting and resetting the system variables
(defun setv (systvar newval / x)
  (setq x (read (strcat systvar "1")))
  (set x (getvar systvar))
  (setvar systvar newval)
)
;;; setv
(defun setting ()
  (setq oerr *error*)
  (setq *error* err)
  (setv "BLIPMODE" 0)
  (setv "CMDECHO" 0)
  (setv "OSMODE" 0)
)
;;; setting
(defun rsetv (systvar)
  (setq x (read (strcat systvar "1")))
  (setvar systvar (eval x))
)
;;; rsetv
(defun resetting ()
  (rsetv "BLIPMODE")
  (rsetv "CMDECHO")
  (rsetv "OSMODE")
  (setq *error* oerr)
)

http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: How to get object inner a circle
« Reply #6 on: November 04, 2007, 06:29:54 AM »
Nice coding qjchen,
Hey I just noticed, your pretty close to where I live.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: How to get object inner a circle
« Reply #7 on: November 04, 2007, 08:53:07 AM »
Thanks, Daniel

I am in Guangzhou, China.

Guangzhou is also named Canton.

Are you in HongKong?

:)
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8706
  • AKA Daniel
Re: How to get object inner a circle
« Reply #8 on: November 05, 2007, 01:03:56 PM »
Are you in HongKong?

Yes sir,
Guangzhou is a very nice city,
I go there often