Author Topic: [ Help ] What about Arc starting angle and the X-axis of the OCS ?  (Read 4575 times)

0 Members and 1 Guest are viewing this topic.

chlh_jd

  • Guest
Hi , ALL .
I have some 3D ARC ( See the dwg post ) ,  the current UCS is OCS .
I want to determine the Point position to the Arc , But never been able to calculate the correct relative coordinates though base on center and it's norm (dxf 210) .
Arc's entity list has start angle (dxf 50) and end angle (dxf 51) , what about the start angle and the X-axis of the OCS ?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: [ Help ] What about Arc starting angle and the X-axis of the OCS ?
« Reply #1 on: October 14, 2012, 05:19:24 AM »
Hi,

I think you misunderstand what is OCS as defined in AutoCAD.
In your drawing, the UCS is not similar to the arc OCS : the UCS Z axis is parallel to the OCS Z axis but not  X and Y ones, the origin is different too.

When using the UCS command with the Object option on an arc AutoCAD defines a new UCS which origin is the arc center, the Z axis is the arc normal and the X axis is defined from center to start point or end point according to the picked point on the arc.

Entities OCS (for entities which have one) is not defined the same way. The origin is always the same as the WCS one, the Z axis is the entity normal and the X (and Y) axis is defined using the "Arbitrary Axis Algorithm".
See in the Developer's guide > DXF Reference > Advanced DXF issues >
Object Coordinate Systems (OCS)
Arbitrary Axis Algorithm

You can see this thread too

PS: Using the ZAxis option of the UCS command and passing it the WCS origin and the entity normal, sets the  UCS to the entity OCS.
« Last Edit: October 14, 2012, 05:32:25 AM by gile »
Speaking English as a French Frog

chlh_jd

  • Guest
Re: [ Help ] What about Arc starting angle and the X-axis of the OCS ?
« Reply #2 on: October 14, 2012, 05:45:43 AM »
Hi,

I think you misunderstand what is OCS as defined in AutoCAD.
In your drawing, the UCS is not similar to the arc OCS : the UCS Z axis is parallel to the OCS Z axis but not  X and Y ones, the origin is different too.

When using the UCS command with the Object option on an arc AutoCAD defines a new UCS which origin is the arc center, the Z axis is the arc normal and the X axis is defined from center to start point or end point according to the picked point on the arc.

Entities OCS (for entities which have one) is not defined the same way. The origin is always the same as the WCS one, the Z axis is the entity normal and the X (and Y) axis is defined using the "Arbitrary Axis Algorithm".
See in the Developer's guide > DXF Reference > Advanced DXF issues >
Object Coordinate Systems (OCS)
Arbitrary Axis Algorithm

You can see this thread too

PS: Using the ZAxis option of the UCS command and passing it the WCS origin and the entity normal, sets the  UCS to the entity OCS.
Thanks Gile a lot .
I'v see your post about OCS again and again , But still do not understand the OCS (my lack of knowledge) .
I look at that link you to the OCS first ask you if unclear , Thank you again .

chlh_jd

  • Guest
Re: [ Help ] What about Arc starting angle and the X-axis of the OCS ?
« Reply #3 on: October 14, 2012, 07:30:29 AM »
Is startangle of 3DARC accordding the OCS ? :x
Is the following codes to get OCS 3x3matrix correct ?
Code: [Select]
(defun getOcsmatrix (norm)
  ;; Norm of entity (dxf 210 )
  ((lambda (x)
     (list x
   (v2u (v^v x norm))
   norm))
    (if (equal norm (list 0 0 1) (1/ 64.))
      (v2u (v^v (list 0 1 0) norm))
      (v2u (v^v (list 0 0 1) norm)))
    )
  )
;;------------------
(defun v2u (v / d)
 (setq d (sqrt (apply (function +) (mapcar (function *) v v))))
 (if (/= d 0)   
   (mapcar (function (lambda (x) (/ x d))) v)   
   )
)
(defun v^v (v1 v2)
  (list (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
(- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
(- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
  ) 
)
Can we get the start or endpoint without vlax-curve functions though this five params :
   1. Center (in WCS , dxf 10 )
   2. Radia  (dxf 40)
   3. Norm ( dxf 210 )
   4. StartAng (dxf 50)
   5. EndAng (dxf 51)
« Last Edit: October 14, 2012, 07:35:25 AM by chlh_jd »

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: [ Help ] What about Arc starting angle and the X-axis of the OCS ?
« Reply #4 on: October 14, 2012, 08:04:22 AM »
Consider the following function:

Code - Auto/Visual Lisp: [Select]
  1. ;; Arc Endpoints  -  Lee Mac
  2. ;; Returns the endpoints of an Arc expressed in WCS
  3.  
  4. (defun LM:ArcEndpoints ( ent / cen nrm rad )
  5.     (setq ent  (entget ent)
  6.           nrm  (cdr (assoc 210 ent))
  7.           cen  (cdr (assoc 010 ent))
  8.           rad  (cdr (assoc 040 ent))
  9.     )
  10.     (mapcar
  11.         (function
  12.             (lambda ( ang )
  13.                 (trans (mapcar '+ cen (list (* rad (cos ang)) (* rad (sin ang)) 0.0)) nrm 0)
  14.             )
  15.         )
  16.         (list (cdr (assoc 50 ent)) (cdr (assoc 51 ent)))
  17.     )
  18. )
« Last Edit: October 14, 2012, 08:08:43 AM by Lee Mac »

chlh_jd

  • Guest
Re: [ Help ] What about Arc starting angle and the X-axis of the OCS ?
« Reply #5 on: October 14, 2012, 09:06:23 AM »
Consider the following function:

Code - Auto/Visual Lisp: [Select]
  1. ;; Arc Endpoints  -  Lee Mac
  2. ;; Returns the endpoints of an Arc expressed in WCS
  3.  
  4. (defun LM:ArcEndpoints ( ent / cen nrm rad )
  5.     (setq ent  (entget ent)
  6.           nrm  (cdr (assoc 210 ent))
  7.           cen  (cdr (assoc 010 ent))
  8.           rad  (cdr (assoc 040 ent))
  9.     )
  10.     (mapcar
  11.         (function
  12.             (lambda ( ang )
  13.                 (trans (mapcar '+ cen (list (* rad (cos ang)) (* rad (sin ang)) 0.0)) nrm 0)
  14.             )
  15.         )
  16.         (list (cdr (assoc 50 ent)) (cdr (assoc 51 ent)))
  17.     )
  18. )
Nice routine , Lee . 
This help me to understand the startangle in 3DARC .
Thank you very much . :-)

David Bethel

  • Swamp Rat
  • Posts: 656
Re: [ Help ] What about Arc starting angle and the X-axis of the OCS ?
« Reply #6 on: October 14, 2012, 09:06:50 AM »
Or maybe both the top and bottom end points:

Code: [Select]
;;;RETURNS BOTTOM AND TOP ENDPOINTS OF AN EXTRUDED ARC IN WCS

(defun arc_ends (en / ed c z r s e u p1 p2 p3 p4)
    (setq ed (entget en)
           c (cdr (assoc 10 ed))
           z (cdr (assoc 39 ed))
           r (cdr (assoc 40 ed))
           s (cdr (assoc 50 ed))
           e (cdr (assoc 51 ed))
           u (cdr (assoc 210 ed))
          p1 (trans (polar c s r) u 0)
          p2 (trans (polar c e r) u 0)
          p3 (if z (trans (polar (list (car c) (cadr c) (+ (caddr c) z)) s r) u 0))
          p4 (if z (trans (polar (list (car c) (cadr c) (+ (caddr c) z)) e r) u 0)))

(list (list p1 p2) (list p3 p4)))

-David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: [ Help ] What about Arc starting angle and the X-axis of the OCS ?
« Reply #7 on: October 14, 2012, 09:12:49 AM »
Nice routine , Lee . 
This help me to understand the startangle in 3DARC .
Thank you very much . :-)

Thank you, you're very welcome.  :-)

chlh_jd

  • Guest
Re: [ Help ] What about Arc starting angle and the X-axis of the OCS ?
« Reply #8 on: October 14, 2012, 10:12:07 AM »
This is bothering me for several days function today finally solved , Thanks Gile and Lee Mac !  :-)
Code: [Select]
;;
(defun Pt@Arc  (Pt Arc / c r norm ans ane p@ ang r@ tor )
  ;; Pt@Arc
  ;; Function : To determine a given point's position with the Arc .
  ;; Args :
  ;;       Pt -- Point in WCS
  ;;       ARC -- ARC entity list or a 5 items list which orderly items are Arc_center Arc_radia Arc_Norm StartAngle Endangle .
  ;;
  ;; Returs :
  ;;   A number —— in the Arc Circle .
  ;; -1 —— startpoint
  ;;          0  —— midpoint
  ;;         1  —— endpoint
  ;; ∈(-1 , 0) —— in the Arc between midpoint and endpoint
  ;; ∈( 0 , 1) —— in the Arc between midpoint and endpoint
  ;;∈( - ∞ , -1) —— In Reverse extended arc
  ;; ∈( 1 , + ∞) —— In extended arc
  ;;
  ;;  A list  —— not in arc_circle ,
  ;;    the Scaling relative coordinates in the ucs :
  ;;        base on Arc center , Xdir is Center-->Startpoint , Zdir is norm , Scaled by Arc_Radia .
  ;;
  ;; by GSLS(SS) 2012-10-14
  ;; thanks Gile and Lee Mac for help .
  ;;
 
  (if (vl-consp (car Arc))
    (setq c    (dxf 10 Arc)
  r    (dxf 40 Arc)
  norm (dxf 210 Arc)
  Ans  (dxf 50 Arc)
  Ane  (dxf 51 Arc))
    (if (= (length Arc) 5)
      (setq c (trans (car Arc) 0 0)
    r (cadr Arc)
    norm (caddr Arc)
    Ans (cadddr Arc)
    Ane (last Arc))))
  (if (and (vl-consp Pt) c r norm ans ane)
    (progn     
      (setq p@ (pt- (trans pt 0 norm) c));_trans Pt from wcs to Arc plan '( center Norm)  --> P@   
      (setq p@ (mxv (list (list (cos ans) (sin ans) 0.)
    (list (- (sin ans)) (cos ans) 0.)
    (list 0. 0. 1.))
    p@));_trans p@ from Arc c-norm-UCS to c-startpoint-Ucs
      (cond ((< ans ane)
     (setq ane (- ane ans)
   ans 0)
     )
    ((> ans ane)
     (setq ane (+ ane (- _2pi ans))
   ans 0))
    ) 
      (setq ang (angle (list 0 0 0) p@)
    r@ (distance (list 0 0 0) p@)
    tor (/ 1e-8 r))
      (cond ((and (equal r@ r 1e-8) (equal (last p@) 0 1e-8));_In arc circle 
     (cond ((or (equal ang _2pi tor) (equal ang 0 tor)) -1);_Startpoint
   ((equal ang ane tor) 1);_endpoint
   ((equal ang (/2 ane) tor) 0);_midpoint
   ((< 0 ang ane) (1- (/ ang ane 0.5)));_∈(-1 , 0) between startpoint and midpoint
   ((<= ang (+ (/2 ane) pi)) (/ ang ane 0.5));_∈( 0 , 1 ) between midpoint and endpoint
   (t (/ (- ang (/2 ane) _2pi) (/2 ane)));_other number ∈( - ∞ , -1) In Reverse extended arc ;
    ;_∈( 1 , + ∞) In extended arc
   ))
    (t (pt* p@ (1/ r)));_otherwise , not in arc_circle , return the Scaling relative coordinates in the ucs :
    ;_ base on Arc center , Xdir is Center-->Startpoint , Zdir is norm , Scaled by Arc_Radia .
    ))))
;;; Use functions ---------------------------------------------
(setq _2pi (* 2. pi))
(defun dxf (n l) (cdr (assoc n l)))
;;Matrix multiplied by Vector
(defun mxv(m v)(mapcar(function(lambda (r)(vxv r v)))m))
;; Reciprocal
(defun 1/ (a) (cond ((numberp a) (if(zerop a)nil(/ 1. a)))
    ((vl-consp a) (mapcar (function 1/) a))))
;; devide
(defun /2 (a) (cond ((numberp a) (/ a 2.))
    ((vl-consp a) (mapcar (function /2) a))))
;; 2 Vectors Subtraction
(defun pt- (p2 p1)
  (mapcar (function -) p2 p1))

;;; Test function .
(defun c:test (/ en ent pt res)
  ;; to check point position to Arc . 
  (setq en (car (entsel "\nSelect an Arc :"))
ent (entget en))
  (command "UCS" "OB" en)
  (command "_PLAN" "" "")
  (if en
    (while (setq pt (getpoint "\nSelect a point:"));_getpoint must in the arc plan , otherwise will get not want points .
      (setq pt (trans pt 1 0))
      (setq res (Pt@Arc pt ent))     
      (setq res (vl-princ-to-string res))
      (alert res)))
  (princ)
  ) 
« Last Edit: October 14, 2012, 10:17:39 AM by chlh_jd »