I'm reading in a cad file from a dxf and I need to be able to draw an arc between two arbitrary points with a bulge value. I'm using THREE.Line to draw segments of the arc.
This page describes some of the necessary calculations in lisp but doesn't explain the center-point calculation very well. I also don't know what angle
function does in the example code (Maybe the angle between two points using 0,0 as an origin?). Here is the code there:
;; Bulge to Arc - Lee Mac
;; p1 - start vertex
;; p2 - end vertex
;; b - bulge
;; Returns: (<center> <start angle> <end angle> <radius>)
(defun LM:Bulge->Arc ( p1 p2 b / a c r )
(setq a (* 2 (atan b))
r (/ (distance p1 p2) 2 (sin a))
c (polar p1 (+ (- (/ pi 2) a) (angle p1 p2)) r)
)
(if (minusp b)
(list c (angle c p2) (angle c p1) (abs r))
(list c (angle c p1) (angle c p2) (abs r))
)
)
I understand how a
(ie theta) and r
(radius) are calculated, but I don't understand the center-point calculation and I need it (I think) to figure the segments for my arc. Can anyone help explain the math and/or provide some javascript code?
A coworker was able to figure out what to do here:
In the lisp code, the angle a
(aka theta) was just simplified to 2atan(b)
as opposed to 4atan(b)
because later we only need half the angle for some calculations of the center point c
and radius r
, not the whole angle.
The lisp angle
function finds the angle of a vector (in this case, p1 -> p2
) where 0 is the positive x axis, pi / 2
is positive y axis, and so forth. That angle of that chord, plus the angle between the cord and vector p1 -> c
, which is (pi - pi/2 - a)
, gives us enough to do a polar coordinate calculation to find the coordinates of the center point c
.