|
An Explanation of Elliptical Arcs DXF Group Code 41 for LISP and ADS ObjectARX
LISP 和 ADS ObjectARX 的椭圆弧 DXF 组代码 41 的说明
[code](defun c:e_arc( / a b slope ang q1 q2 q3 q4 qmode x y a2)
;assuming 0,0 is at the center of the ellipse, major axis in x direction
(setq ang (getangle '(0.0 0.0) "Choose start angle: "))
(setq a 1
b 0.5
slope (/ (sin ang) (cos ang))
q1 (/ pi 2.0)
q2 pi
q3 (/ (* 3 pi) 2.0)
q4 (* 2.0 pi)
qmode 'q1
);setq
(entmake (setq ent '((0 . "ELLIPSE")
(100 . "AcDbEntity")
(100 . "AcDbEllipse")
(10 0.0 0.0 0.0)
(11 1.0 0.0 0.0)
(40 . 0.5)
(62 . 1))
);setq
);entmake
;line equation is y = mx + 0, where m is the slope and 0 is the y-intercept
;ellipse equation is x^2/a^2 + y^2/b^2 = 1
;solve line and ellipse equations simultaneously to find x and y values
(setq y (/ (* a b slope) (sqrt (+ (* (* slope slope) (* a a)) (* b b))))
);setq
;minor axis circle equation is x^2 + y^2 = b^2
;solve circle equation where y = value calculated above
(setq x (sqrt (- (* b b) (* y y))))
;calculate start angle trigonometrically
(setq cos_a2 (/ x b)
sin_a2 (/ y b)
);setq
(if (/= cos_a2 0)
(setq a2 (atan (/ sin_a2 cos_a2)))
(setq a2 q1 qmode 'q1)
);if
;make a2 insensitive to quadrant
(cond ((and (> ang q1) (< ang q2))
(setq a2 (- pi (abs a2)) qmode 'q2
);setq
);statement 1
((and (> ang q2) (< ang q3))
(setq a2 (+ (abs a2) pi) qmode 'q3
);setq
);statement 2
((and (> ang q3) (< ang q4))
(setq a2 (abs (- (* 2 pi) (abs a2))) qmode 'q4
);setq
);statement 3
;special cases: angle = 0, 90, 180, 270 or 360 deg
((or (= ang 0) (= ang q1))
(setq qmode 'q1)
);statement 4
((= ang q2)
(setq a2 pi qmode 'q1)
);statement 5
((= ang q3)
(setq a2 (- (/ pi 2.0) pi) qmode 'q1)
);statement 6
(t nil);default statement
);cond
(command "zoom" "c" "0,0" 3)
(setq ent (append ent (list (cons 41 a2) (cons 42 (+ a2 (/ pi 2.0))))))
(setq ent (subst '(62 . 5) (assoc 62 ent) ent))
(entmake ent)
(setq a2
(cond ((= qmode 'q1) a2)
((= qmode 'q2) a2)
((= qmode 'q3) (- a2 q4))
((= qmode 'q4) (- a2 q4))
(t nil)
);cond
);setq
(princ "\nParametric angle in radians: ")
(princ a2)
(princ "\nParametric angle in degrees: ")
(princ (/ (* 180 a2) pi))
(princ)
);e_arc[/code] |
|