(setq
vlist (append vlist (list (car vlist)))
segno (1- (length vlist)) ; no of segments 没有的部份
n 0
Ttl_Area 0.0 ; total area 总面积
Mx 0.0 ; Sum of moment to basex line X方向归纳
My 0.0 ; Sum of moment to basey line Y方向归纳
basex (car (nth 0 vlist)) ; arbitrary axes (will reduce error for large numbers)任意轴(减少数字的大小误差)
basey (cadr (nth 0 vlist))
)
(repeat segno
(setq
p1 (nth n vlist) ; process current segment 当前第一行
p2 (nth (1+ n) vlist)
x1 (car p1)
y1 (cadr p1)
x2 (car p2)
y2 (cadr p2)
; For the triangle 三角形的
t_x (- (* (+ x2 x2 x1) 0.333333) basex) ; cg of trianlge 三角形的中心
t_y (- (* (+ y1 y1 y2) 0.333333) basey)
t_area (* (- y2 y1) (- x2 x1) 0.5) ; area of triangle 三角形的面积
t_xm (* t_area t_x) ; moment to Basex 到X
t_ym (* t_area t_y) ; moment to basey 到Y
; For the rectangle 矩形的
r_x (- (/ (+ x1 x2) 2) basex) ; CG of rectangle 矩形的中心
r_y (- (/ (+ basey y1) 2) basey)
r_area (* (- x2 x1) (- y1 basey)) ; area of rectangle 矩形的面积
r_xm (* r_area r_x) ; moment to basex
r_ym (* r_area r_y) ; moment to basey
Ttl_Area (+ Ttl_Area t_area r_area)
Mx (+ Mx t_xm r_xm) ; adds up moments to basex
My (+ My t_ym r_ym) ; adds up moments to basey
n (1+ n)
)
)
(list (+ (/ Mx Ttl_Area) basex) (+ (/ My Ttl_Area) basey) 0.0)
)