AutoCAD
(Clarify documentation)
m (Reverted edits by 190.191.160.148 (Talk); changed back to last version by Tom Haws)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
;;; WIKI-3PTTOBULGE
+
;| WIKI-3PTTOBULGE
 
Returns the bulge of an arc defined by three points, PNT1, PNT2, and PNT3
; End AutoLISP comment mode if on |;
 
(DEFUN
 
WIKI-3PTTOBULGE (PNT1 PNT2 PNT3 / ANG1 ANG2 ANG3 BULGE CHORD DELTA DELTA1 R)
 
;| Returns the bulge of an arc defined by three points, PNT1, PNT2, and PNT3
 
 
If point 2 is nil, returns 0.
 
If point 2 is nil, returns 0.
 
Edit the source code for this function at </pre>
 
Edit the source code for this function at </pre>
Line 12: Line 9:
 
WIKI-ASIN
 
WIKI-ASIN
 
WIKI-TAN
 
WIKI-TAN
  +
 
Theory:
 
/\
 
/ \
 
/ \
 
/ \
 
/ delta \
 
/ \
 
/ R
 
/ \
 
/ \
 
/ \
 
/ \
 
/ \
 
/ __chord___ ----- 1
 
3 ------ | *
 
. ANG2 B _.*
 
- 2 - ._|..-
  +
  +
  +
 
Bulge = 2*B/chord
 
Bulge = tan(delta/4)
 
Theory (in classic triangle geometry terms):
 
We want to find the radius, R.
 
Points 1, 2, and 3 form a triangle with sides 1, 2, and 3 opposite them.
 
A unique circle passes through the three points.
 
Sides 1, 2, and 3 are all chords of the circle.
 
Side 2 (opposite point 2) is the chord of this segment of the circle.
  +
 
It happens to be true that angle 2 doubled plus delta equals 360 or 2pi.
 
This is intuitive when point 2 is at the midpoint of the circle segment.
 
Consider how angle 2 acts in the following cases:
 
Delta Angle 2
 
0 180
 
90 135
 
180 90
 
270 45
 
360 0
  +
 
But it is also true when point 2 is not at the midpoint.
 
Therefore delta = 2*pi - 2*ang2 = 2*(pi-ang2) = 2*(ang1 + ang3)
 
and delta/2=pi-ang2 (equation 1)
  +
 
A line from the center of the circle is a perpendicular bisector of any of the three lines
 
Therefore (side2/2)/R=sin(delta/2). (equation 2)
 
We'd like to get R just in terms of side2 and ang2. Luckily we have this trig identity,
 
sin(pi-theta)=sin(theta), (equation 3)
 
so we can say from equations 1 and 3 that sin(delta/2)=sin(pi-ang2)=sin(ang2) (equation 4)
 
and from equations 2 and 4 that (side2/2)/R=sin(ang2). (equation 5)
 
Solving for R we get R=side2/(2*sin(ang2)). (equation 6)
 
That gives us R in terms of things we know.
 
In fact, from the law of sines (a/sin(A)=b/sin(B)=c/sin(C)), since 2R=side2/sin(ang2),
 
in geometry triangle terms (where "a" is a triangle side and "A" is its opposite angle),
 
R=a/(2*sin(A)) for any of the three points/angles/opposite sides
 
|;
 
|;
 
(DEFUN
;;;
 
 
WIKI-3PTTOBULGE (PNT1 PNT2 PNT3 / ANG1 ANG2 ANG3 BULGE CHORD DELTA DELTA1 R)
;;; /\
 
;;; / \
 
;;; / \
 
;;; / \
 
;;; / delta \
 
;;; / \
 
;;; / R
 
;;; / \
 
;;; / \
 
;;; / \
 
;;; / \
 
;;; / \
 
;;; / __chord___ ----- 1
 
;;; 3 ------ | *
 
;;; . ANG2 B _.*
 
;;; - 2 - ._|..-
 
;;;
 
;;;
 
;;;
 
;;;Bulge = 2*B/chord
 
;;;Bulge = tan(delta/4)
 
;;;Theory (in classic triangle geometry terms):
 
;;; We want to find the radius, R.
 
;;; Points 1, 2, and 3 form a triangle with sides 1, 2, and 3 opposite them.
 
;;; A unique circle passes through the three points.
 
;;; Sides 1, 2, and 3 are all chords of the circle.
 
;;; Side 2 (opposite point 2) is the chord of this segment of the circle.
 
;;;
 
;;; It happens to be true that angle 2 doubled plus delta equals 360 or 2pi.
 
;;; This is intuitive when point 2 is at the midpoint of the circle segment.
 
;;; Consider how angle 2 acts in the following cases:
 
;;; Delta Angle 2
 
;;; 0 180
 
;;; 90 135
 
;;; 180 90
 
;;; 270 45
 
;;; 360 0
 
;;;
 
;;; But it is also true when point 2 is not at the midpoint.
 
;;; Therefore delta = 2*pi - 2*ang2 = 2*(pi-ang2) = 2*(ang1 + ang3)
 
;;; and delta/2=pi-ang2 (equation 1)
 
;;;
 
;;; A line from the center of the circle is a perpendicular bisector of any of the three lines
 
;;; Therefore (side2/2)/R=sin(delta/2). (equation 2)
 
;;; We'd like to get R just in terms of side2 and ang2. Luckily we have this trig identity,
 
;;; sin(pi-theta)=sin(theta), (equation 3)
 
;;; so we can say from equations 1 and 3 that sin(delta/2)=sin(pi-ang2)=sin(ang2) (equation 4)
 
;;; and from equations 2 and 4 that (side2/2)/R=sin(ang2). (equation 5)
 
;;; Solving for R we get R=side2/(2*sin(ang2)). (equation 6)
 
;;; That gives us R in terms of things we know.
 
;;; In fact, from the law of sines (a/sin(A)=b/sin(B)=c/sin(C)), since 2R=side2/sin(ang2),
 
;;; in geometry triangle terms (where "a" is a triangle side and "A" is its opposite angle),
 
;;; R=a/(2*sin(A)) for any of the three points/angles/opposite sides
 
;;;
 
 
(COND
 
(COND
 
((NOT PNT2) 0)
 
((NOT PNT2) 0)

Latest revision as of 19:04, 24 April 2009

;| WIKI-3PTTOBULGE
Returns the bulge of an arc defined by three points, PNT1, PNT2, and PNT3
   If point 2 is nil, returns 0.
   Edit the source code for this function at 
  3pttobulge (AutoLISP function)
   External function references:
   WIKI-ASIN
   WIKI-TAN

Theory:                                             
                 /\                          
                /  \                         
               /    \                        
              /      \                       
             / delta  \                      
            /          \                     
           /            R                    
          /              \                   
         /                \                  
        /                  \                 
       /                    \                
      /                      \               
     /       __chord___ ----- 1
    3 ------      |          *
       .    ANG2   B    _.* 
           - 2 - ._|..-



Bulge = 2*B/chord
Bulge = tan(delta/4)
Theory (in classic triangle geometry terms):
 We want to find the radius, R.
 Points 1, 2, and 3 form a triangle with sides 1, 2, and 3 opposite them.
 A unique circle passes through the three points.
 Sides 1, 2, and 3 are all chords of the circle.
 Side 2 (opposite point 2) is the chord of this segment of the circle.

 It happens to be true that angle 2 doubled plus delta equals 360 or 2pi.
 This is intuitive when point 2 is at the midpoint of the circle segment.
 Consider how angle 2 acts in the following cases:
  Delta   Angle 2
    0       180  
   90       135  
  180        90  
  270        45  
  360         0

 But it is also true when point 2 is not at the midpoint.
 Therefore delta = 2*pi - 2*ang2 = 2*(pi-ang2) = 2*(ang1 + ang3)
 and delta/2=pi-ang2                                                           (equation 1)

 A line from the center of the circle is a perpendicular bisector of any of the three lines
 Therefore (side2/2)/R=sin(delta/2).                                           (equation 2)
 We'd like to get R just in terms of side2 and ang2.  Luckily we have this trig identity,
  sin(pi-theta)=sin(theta),                                                    (equation 3)
 so we can say from equations 1 and 3 that sin(delta/2)=sin(pi-ang2)=sin(ang2) (equation 4)
 and from equations 2 and 4 that (side2/2)/R=sin(ang2).                        (equation 5)
 Solving for R we get R=side2/(2*sin(ang2)).                                   (equation 6)
 That gives us R in terms of things we know.
 In fact, from the law of sines (a/sin(A)=b/sin(B)=c/sin(C)), since 2R=side2/sin(ang2),
 in geometry triangle terms (where "a" is a triangle side and "A" is its opposite angle),
 R=a/(2*sin(A)) for any of the three points/angles/opposite sides
|;
(DEFUN
   WIKI-3PTTOBULGE (PNT1 PNT2 PNT3 / ANG1 ANG2 ANG3 BULGE CHORD DELTA DELTA1 R)
  (COND
    ((NOT PNT2) 0)
    (T
     (SETQ
       CHORD
        (DISTANCE PNT1 PNT3)
       ANG2
        (- (ANGLE PNT2 PNT1) (ANGLE PNT2 PNT3))
       ;;We use the theory above to write an expression for R
       ;;using chord and ang2
       ;;Sin of ang2 (and thus R) will be negative if the arc is clockwise.
       R
        (/ CHORD (* 2 (SIN ANG2)))
       DELTA1
        (* 2 (WIKI-ASIN (/ CHORD (* 2 R))))
       ANG1
        (ABS (- (ANGLE PNT1 PNT3) (ANGLE PNT1 PNT2)))
       ANG1
        (ABS
          (IF (> ANG1 PI)
            (- ANG1 (* 2 PI))
            ANG1
          )
        )
       ANG3
        (ABS (- (ANGLE PNT3 PNT1) (ANGLE PNT3 PNT2)))
       ANG3
        (ABS
          (IF (> ANG3 PI)
            (- ANG3 (* 2 PI))
            ANG3
          )
        )
       DELTA
        (* 2 (+ ANG1 ANG3))
       BULGE
        (* (IF (MINUSP R)
             -1
             1
           )
           (WIKI-TAN (/ DELTA 4.0))
        )
     )
    )
  )
)