Grdraw Arc passing by 3 points (UCS) with N segments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
; **
; * ba:3pgrarc grdraw an arc with n segments - Bilal
; * p1, p2 and p3 1st, 2nd and 3rd points (UCS)
; * n segments number
; **
;========================================================================================
(defun ba:3pgrarc ( p1 p2 p3 n / lst cen rds pc s ps va arcangle pa a ang plst ang* x y px p p0 )
;========================================================================================
;Get center and radius of the arc passing by p1, p2, p3
(if (setq lst (circleBy3Points p1 p2 p3))
(progn
(setq cen (car lst) rds (cadr lst) pc (mid p1 p3))
(if (equal cen pc 1e-9)
(setq s (* (distance p1 p2)(cos (atan (distance p2 p3) (distance p2 p1))))
ps (mapcar '+ p1 (mapcar '(lambda (u) (* u s)) (vx1 (mapcar '- p3 p1))))
va (vx1 (mapcar '- ps p2))
pa (mapcar '+ cen (mapcar '(lambda (u) (* rds u)) va))
arcangle pi
)
(if (inters p1 p3 p2 cen)
(progn
(setq arcangle (* 2 (atan (distance p1 pc) (distance cen pc))))
(setq pa (mapcar '+ cen (mapcar '(lambda (u) (* rds u)) (vx1 (mapcar '- cen pc)))))
)
(progn
(setq arcangle (* 2 (atan (distance p1 pc) (- (distance cen pc)))))
(setq pa (mapcar '+ cen (mapcar '(lambda (u) (* rds u)) (vx1 (mapcar '- pc cen)))))
)
)
)
;Initial values
(setq a (/ arcangle n) ang 0.0 plst nil)
(repeat n
(setq ang (+ ang a)
ang* (- (/ arcangle 4.0) (/ ang 2.0))
x (- (distance p1 pc) (* (distance pa pc) (/ (sin ang*) (cos ang*))))
y (/ (+ rds (* rds (cos (- (/ arcangle 2) ang)))) (cos ang*))
px (mapcar '+ p1 (mapcar '(lambda (u) (* u x)) (vx1 (mapcar '- p3 p1))))
p (mapcar '+ pa (mapcar '(lambda (u) (* u y)) (vx1 (mapcar '- px pa))))
plst (cons p plst)
)
)
(setq plst (reverse plst))
;grdraw segments
(setq p0 p1)
(foreach p plst (grdraw p0 (setq p0 p) 1))
)
)
;------------------
);Endof//ba:3pgrarc
;------------------
;; Midpoint - Lee Mac
;; Returns the midpoint of two points
(defun mid ( a b )
(mapcar (function (lambda ( a b ) (/ (+ a b) 2.0))) a b)
)
;; V^V
;; Cross product of two vectors
(defun v^v (u v)
(list
(- (* (cadr u) (caddr v)) (* (caddr u) (cadr v)))
(- (* (caddr u) (car v)) (* (car u) (caddr v)))
(- (* (car u) (cadr v)) (* (cadr u) (car v)))
)
);V^V
; * Circle by 3 points - Gile
; * Returns the center (UCS) and radius of the circle defined by 3 points (UCS).
(defun circleBy3Points (p1 p2 p3 / v1 v2 norm m1 m2 cen)
(setq v1 (mapcar '- p2 p1)
v2 (mapcar '- p3 p2)
norm (v^v v1 v2)
m1 (mid p1 p2)
m2 (mid p2 p3)
cen (inters
m1 (mapcar '+ m1 (v^v v1 norm))
m2 (mapcar '+ m2 (v^v v2 norm))
nil
)
)
(list cen (distance cen p1))
)
;; Unit Vector - Lee Mac
;; Args: v - vector in R^2 or R^3
(defun vx1 ( v )
( (lambda ( n ) (if (equal 0.0 n 1e-10) nil (mapcar '/ v (list n n n))))
(distance '(0.0 0.0 0.0) v)
)
)
Trigonometric calculation are based on the this figure
Link copied