TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Fuccaro on January 23, 2007, 05:38:26 AM

Title: Center point "moved"
Post by: Fuccaro on January 23, 2007, 05:38:26 AM
I draw a circle with the center point at (10.5).
The elist is something like:
Code: [Select]
((-1 . <Entity name: 7efe7e40>) (0 . "CIRCLE”)… (10 10.0 5.0 0.0) (40 . 5.3) (210 0.0 0.0 1.0))
So far is fain.
If I rotate the circle about its Y axis with 180%%d I see the circle in exactly the same position as before.  But the elist tells me that the centerpoint is moved!

Code: [Select]
((-1 . <Entity name: 7efe7e40>) (0 . "CIRCLE")…(10 -10.0 5.0 1.22461e-015) (40 . 5.3) (210
1.22461e-016 0.0 -1.0))

Is it correct? How can I obtain the real position of the center?
Please help!
Thank you.
Title: Re: Center point "moved"
Post by: Kerry on January 23, 2007, 06:38:00 AM
not possible ...

Your rotation point was not the circle center.
Title: Re: Center point "moved"
Post by: Fuccaro on January 23, 2007, 07:11:12 AM
Try it yourself. I did it 3 times before I posted the question in the forum.
Thank you for answering me.
Title: Re: Center point "moved"
Post by: CAB on January 23, 2007, 07:26:26 AM
How did you rotate the circle, by what method?
Title: Re: Center point "moved"
Post by: CADaver on January 23, 2007, 08:01:21 AM
Notice he said "about the Y axis".  I used two different methods to rotate the circle, one was 3drotate, the other was reset the UCS to a "front" view, then rotate the circle, same results using osnap to the center of the circle each time.

I get before rotation about Y:
Code: [Select]
(
(-1 . <Entity name: 4007cd70>)
(0 . "CIRCLE")
(330 . <Entity name: 4007ccf8>)
(5 . "2E")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "0")
(100 . "AcDbCircle")
(10 10.0 5.0 0.0)
(40 . 5.3)
(210 0.0 0.0 1.0)
)
After rotation about Y:
Code: [Select]
(
(-1 . <Entity name: 4007cd70>)
(0 . "CIRCLE")
(330 . <Entity name: 4007ccf8>)
(5 . "2E")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "0")
(100 . "AcDbCircle")
(10 -10.0 5.0 -3.44505e-015)
(40 . 5.3)
(210 -1.22461e-016 -4.44089e-016 -1.0)
)
Title: Re: Center point "moved"
Post by: Fuccaro on January 23, 2007, 09:21:52 AM
Sorry for beeing not clear. I rotated the circle using the ROTATE3D command, around the Y axis passing trought the center of the circle.
Title: Re: Center point "moved"
Post by: gile on January 23, 2007, 09:25:15 AM
Hi,

All this seems correct.

DXF 10 code for a circle is defined according to its OCS (you can have a look about OCS here) (http://www.theswamp.org/index.php?topic=13526.0).

See the 210 DXF code of the rotated circle : (210 -1.22461e-016 -4.44089e-016 -1.0) instead of (210 0.0 0.0 1.0)

you can try these code lines on both rotated an non-rotated circle, the result should be the same :

(setq ent (car (entsel)) elst (entget ent))

Then

(trans (cdr (assoc 10 elst)) (cdr (assoc 210 elst)) 0)
or
(trans (cdr (assoc 10 elst)) ent 0)
Title: Re: Center point "moved"
Post by: CADaver on January 23, 2007, 12:04:57 PM
Hi Gile,
  My question is
(210 -1.22461e-016 -4.44089e-016 -1.0) instead of (210 0.0 0.0 1.0). 
and (10 -10.0 5.0 -3.44505e-015) instead of (10 10.0 5.0 0.0)

If I haven't moved the circle off its center point and I've rotated the UCS about the 0 Y axis, why should these points be different prior to (trans ?
Title: Re: Center point "moved"
Post by: gile on January 23, 2007, 01:04:38 PM
Quote
My question is
(210 -1.22461e-016 -4.44089e-016 -1.0) instead of (210 0.0 0.0 1.0).
and (10 -10.0 5.0 -3.44505e-015) instead of (10 10.0 5.0 0.0)

I don't know exactly why, but I saw it often with 3d rotations or 3D rotated UCS.

I suppose, as AutoCAD calculates in radians, it uses an approximation of pi (there can be only approximations of pi).
AutoCAD seems to have a precision of 16 decimal.

(rtos pi 1 16) returns "3.141592653589793" (rtos pi 2 17) returns the same.
If in WCS 0 is an effecive 0, rotating UCS of n*pi radians should make loose some précision and 0 become 3.44505e-015.

Knowing that I useally use a "fuzz" with points comparations :
(equal pt1 pt2 1e-9)
Note 1e-9 is equivalent to a micron for a kilometre.
Title: Re: Center point "moved"
Post by: Fuccaro on January 24, 2007, 05:16:57 AM
Thanks for all the answers!
I am wondering why this doesn't work:
Code: [Select]
(setq el (entget (car (entsel))))  ;select the circle
(setq el (subst '(210 0 0 1) (assoc 210 el) el))
(entmod el)
I will read the pages about the TRANS function -it seems to be what I need. Thanks again.
Title: Re: Center point "moved"
Post by: gile on January 24, 2007, 07:23:59 AM
Quote
I am wondering why this doesn't work:
Code:
(setq el (entget (car (entsel))))  ;select the circle
(setq el (subst '(210 0 0 1) (assoc 210 el) el))
(entmod el)

This does work.
It changes the circle normal from (-1.22461e-016 -4.44089e-016 -1.0) -which is very very closed to (0 0 -1)- to (0 0 1).
But the center point -10 DXF code- (-10.0 5.0 -3.44505e-015) isn't changed.

You can try this :
- In the WCS, draw a circle center on (10 5) radius 5.3
- Select the circle and put the cursor on the circle center grip
- On command prompt, you read 10.0,5.0,0.0
- Now, rotate the UCS 180° on Y axis (this UCS is similar to the 3d rotated circle OCS)
- Select the circle and put the cursor on the circle center grip
- On command prompt, you read -10.0,5.0,0.0 which is very very closed to -10.0,5.0,-3.44505e-015
- In this UCS, if you draw a circle which center is 10,5 it will have the same position as the one got with :
(setq el (subst '(210 0 0 1) (assoc 210 el) el))
(entmod el)

I hope this example illustrates better thee question than I can do in my poor English
Title: Re: Center point "moved"
Post by: ElpanovEvgeniy on January 24, 2007, 07:55:06 AM
1 http://www.theswamp.org/index.php?topic=14649.msg177029#msg177029
2 (c:flatten)
3 (vla-put-Normal (vlax-ename->vla-object(car(entsel)))(vlax-3d-point 0. 0. 1.))
Title: Re: Center point "moved"
Post by: CAB on January 24, 2007, 08:23:49 AM
Knowing that I useally use a "fuzz" with points comparations :
(equal pt1 pt2 1e-9)
Note 1e-9 is equivalent to a micron for a kilometre.

As an alternative you can use (< (distance pt1 pt2) 1e-9)
Title: Re: Center point "moved"
Post by: ElpanovEvgeniy on January 24, 2007, 08:45:49 AM
Excuse, I badly tested...
Code: [Select]
(defun ent-exact (/ e)
  ;; By ElpanovEvgeniy
  ;; (ent-exact)
  (if (setq e (car (entsel)))
    (progn
      (entmod
(mapcar
  (function
    (lambda (x)
      (if (or (<= 10 (car x) 59)
      (<= 110 (car x) 149)
      (<= 210 (car x) 239)
      (<= 460 (car x) 469)
      (<= 1010 (car x) 1059)
  )
(if (atom (cdr x))
  (cons (car x) (atof (rtos (cdr x) 2 8)))
  (cons (car x) (mapcar(function(lambda(x) (atof(rtos x 2 8)))) (cdr x)))
)
x
      )
    )
  )
  (entget e)
)
      )
      (entupd e)
    )
  )
  (princ)
)

add:
This program will work with any entities...
Title: Re: Center point "moved"
Post by: gile on February 01, 2007, 01:55:47 PM
If you are disturbed by this kind of real numbers -3.44505e-015 or lists (-1.22461e-016 -4.44089e-016 -1.0), you can use the little following routine to "round" them to a true zero. It works as well with real numbers, lists or nested lists of numbers.

(truezero -3.44505e-015) returns 0.0
(truezero '(-1.22461e-016 -4.44089e-016 -1.0)) returns (0.0 0.0 -1.0)

Code: [Select]
(defun truezero (l)
  (if (listp l)
    (mapcar 'truezero l)
    (if (< -1e-12 l 1e-12)
      0.0
      l
    )
  )
)
Title: Re: Center point "moved"
Post by: CADaver on February 01, 2007, 03:44:25 PM
oh I'm quite aware of fuzz factors and rounding routines, and the number themselves don't really bother me.  What is somewhat bothersome is the "RELOCATION" of the circle that should not be relocated, even a little.