;| subrotina auxiliar, calcula a área de um polígono
fechado, mas sem dividir por 2, nem retirar o sinal
Obs: pts é a lista de corrdenadas, ex:
((x1 y1) … (xn yn)) |;
(defun ia_proclpt (pts)
(setq pts (append pts (list (car pts))))
(– (apply
‘+
(mapcar
‘*
(mapcar ‘car pts)
(cdr (mapcar ‘cadr pts))))
(apply
‘+
(mapcar
‘*
(mapcar ‘cadr pts)
(cdr (mapcar ‘car pts))))))
;|retorna true para poligonos
horientados no sentido horário
e false para anti-horário |;
(defun isclockwise (pts)
(< (ia_proclpt pts) 0))
;|calcula a área de um polígon
o por triangulação|;
(defun getarealpt (pts)
(/ (abs (ia_proclpt pts)) 2))
;calcula o centroide de um polígono
(defun get-centroid (pts / x y qtd sf n
p1 p2 x1 x2 y1 y2 area)
(setq qtd (length pts)
area (/ (ia_proclpt pts) 2)
pts (append pts (list (car pts)))
x 0
y 0
n 0)
(repeat qtd
(setq p1 (nth n pts)
n (1+ n)
p2 (nth n pts)
x1 (car p1)
x2 (car p2)
y2 (cadr p2)
y1 (cadr p1)
sf (– (* x1 y2) (* x2 y1))
x (+ x (* (+ x1 x2) sf))
y (+ y (* (+ y1 y2) sf))))
(list (/ x (* 6 area))
(/ y (* 6 area))))