Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Quick Way to Read Angle Dimensions

1 view
Skip to first unread message

Mark

unread,
Jul 27, 1998, 3:00:00 AM7/27/98
to
Looking for a quick way to read Angle Dimensions by a short lisp
ditty. Anybody have one on hand?

-Rick

Josh Crawford

unread,
Jul 27, 1998, 3:00:00 AM7/27/98
to

Mark wrote:

Here you go...this is by John Fleming of the Fleming Group...he posted
this 7-26-98 after I posted my version. Mine was quick and simple but
only worked where the extrusion vector (210) equals (0.0 0.0 1.0).
John's works (better) on arbitrary UCS's as well...


From: Jon Fleming <jo...@fleming-group.com>
Newsgroups: autodesk.autocad.customization
Subject: Re: How to extract the angle from an angle
dimension?
Date: Sun, 26 Jul 1998 10:23:15 EDT
Organization: The Fleming Group


;;; A function to obtain the angle measured by an angular
;;; dimension

;;; Argument; the Entity name of an angular dimension.
;;; (the calling routine is responsible for
;;; ensuring that the Entity Name refers to
;;; an angular dimension).

;;; Return Value: the angle measured by the dimension,
;;; in radians.

(defun GetAngDimMeasure (DimEName / DimEList DimAngle DimLinePointAngle
P0 P1 P2 P10 P13 P14 P15 P16 70Code Extrusion
)
;; Get the Entity Association list of the dimension
(setq DimElist (entget DimEName)
;; Get the extrusion vector
Extrusion (cdr (assoc 210 DimEList))
;; Get all the defining points of the dimension,
;; converting from WCS to OCS where required,
;; and discard all the Z coordinates (so we're
;; working on a 2D problem in the OCS Z=0 plane)
P10 (DropZCoordinate
(trans (cdr (assoc 10 DimEList)) 0 Extrusion)
) ; end DropZCoordinate
P13 (DropZCoordinate
(trans (cdr (assoc 13 DimEList)) 0 Extrusion)
) ; end DropZCoordinate
P14 (DropZCoordinate
(trans (cdr (assoc 14 DimEList)) 0 Extrusion)
) ; end DropZCoordinate
P15 (DropZCoordinate
(trans (cdr (assoc 15 DimEList)) 0 Extrusion)
) ; end DropZCoordinate
) ; end setq
;; Check the dimension type ...
(if (= 2 (logand 7 (setq 70Code (cdr (assoc 70 DimEList)))))
(progn
;; It's a two-line type of angular dimension.
;; We'll need the 16 group
(setq P16 (DropZCoordinate (cdr (assoc 16 DimEList)))
;; We need to calculate the vertex of the angle.
P0 (inters P10 P15 P13 P14 NIL)
) ; end setq
;; From the other two defining points for each
;; line, pick the one that is farthest from P0
;; to use in calculating the angle
(if (> (distance P0 P10) (distance P0 P15))
(setq P1 P10)
(setq P1 P15)
) ; end if
(if (> (distance P0 P13) (distance P0 P14))
(setq P2 P13)
(setq P2 P14)
) ; end if
;; Calculate a tentative value for the angle we want
(setq DimAngle (2D3PointAngle P0 P1 P2)
;; And the angle from the line from the
;; vertex to P1 to the line from the
;; vertex to the dimension line definition
;; point
DimLinePointAngle (2D3PointAngle P0 P1 P16)
) ; end setq
;; If the dimension line definition point is within
;; the pie-slice defined by the P0-P1 line and the
;; P0-P2 line, or if it's in the mirror image of
;; that pie-slice (and we have to check differently
;; depending on the sign of DimAngle) ...
(if (minusp DimAngle)
(if (or (and (minusp DimLinePointAngle)
(> DimLinePointAngle DimAngle)
) ; end and
(and (not (minusp DimLinePointAngle))
(> DimLinePointAngle (+ DimAngle pi))
) ; end and
) ; end or
;; We've got the correct angle except for sign
(abs DimAngle)
;; Else we need to correct the angle
(+ pi DimAngle)
) ; end if
;; DimAngle is positive ...
(if (or (and (not (minusp DimLinePointAngle))
(< DimLinePointAngle DimAngle)
) ; end and
(and (minusp DimLinePointAngle)
(< DimLinePointAngle (- DimAngle pi))
) ; end and
) ; end or
;; Then we've got the correct angle, return it
DimAngle
;; Else we have to adjust the angle and return it
(- pi DimAngle)
) ; end if
) ; end if
) ; end progn
(progn
;; It's a three-point type of angular dimension,
;; the vertex is at the point specified by the
;; 15 group and we don't have any choice about
;; which other three points we use to calculate
;; the angles
(setq DimAngle (2D3PointAngle P15 P13 P14)
;; And the angle from the line from the
;; vertex to P13 to the line from the
;; vertex to the dimension line definition
;; point
DimLinePointAngle (2D3PointAngle P15 P13 P10)
) ; end setq
;; If the dimension line definition point is within
;; the pie-slice defined by DimAngle (and we have to
;; check differently depending on the sign of
;; DimAngle) ...
(if (minusp DimAngle)
(if (or (not (minusp DimLinePointAngle))
(< DimLinePointAngle DimAngle)
) ; end or
;; We need to correct the angle
(+ (* 2.0 pi) DimAngle)
;; Else we have the correct angle except for sign
(abs DimAngle)
) ; end if
;; DimAngle is positive ...
(if (or (minusp DimLinePointAngle)
(> DimLinePointAngle DimAngle)
) ; end or
;; We need to correct the angle
(- (* 2.0 pi) DimAngle)
;; Else we have the correct angle
DimAngle
) ; end if
) ; end if
) ; end progn
) ; end if
) ; end defun

;;; A 2D function to calculate the angle
;;; from:
;;; the line from Point A to Point B
;;; to:
;;; the line from Point A to Point C

;;; Arguments:
;;; PA: Point A, a list of two reals
;;; PB: Point B, a list of two reals
;;; PB: Point C, a list of two reals
;;; All three points must be distinct.

;;; Return Value:
;;; The angle, in radians, ranging from
;;; -(pi + epsilon) to pi inclusive.

(defun 2D3PointAngle (PA PB PC / Magnitude VectorAB VectorAC)
;; Get a unit vector from point A towards point B
(setq Magnitude (distance PA PB)
VectorAB (mapcar '(lambda (C) (/ C Magnitude))
(mapcar '- PB PA)
) ; end mapcar
;; and a unit vector from point A towards point C
Magnitude (distance PA PC)
VectorAC (mapcar '(lambda (C) (/ C Magnitude))
(mapcar '- PC PA)
) ; end mapcar
CosTheta (apply '+ (mapcar '* VectorAB VectorAC))
;; And SINCE THE VECTORS ARE 2D the Z component
;; of the cross product is the sine of the angle
) ; end setq
;; Since the two vectors are unit vectors,
;; their dot product is the cosine of the
;; angle. Since the two vector are ALSO
;; 2D (the Z component is zero), the Z component
;; of their cross product is the sine of the angle.
;; This is the only place where the vectors MUST
;; be 2D to get the correct answer. Use (atan)
;; with two arguments to get a full 360 degree
;; range in the return value.
(atan (- (* (car VectorAB) (cadr VectorAC))
(* (cadr VectorAB) (car VectorAC))
) ; end -
(apply '+ (mapcar '* VectorAB VectorAC))
) ; end atan
) ; end defun

;;; Function to convert a 3D point to a 2D point
;;; by discarding the Z coordinate

(defun DropZCoordinate (Point)
(list (car Point) (cadr Point))
) ; end defun

jrf


--
Later,
Josh
jo...@mindspring.com

"I'm a perfectionist...I'm just not very good at it."

0 new messages