- ;;参数:lst:点表,格式((x1 y1)(x2 y2)(x3 y3)(x4 y4)(x5 y5))
- ;;返回:面积值,顺时针为负,逆时针为正
- ;|
- (defun c:tst()
- (setq lst (list
- '(28.375 314.517)
- '(397.730 127.575)
- '(944.173 155.364)
- '(1058.016 319.569)
- '(622.885 544.405)
- '(139.688 438.303)
- )
- )
- (princ (rtos (lst_area lst) 2 6))
- )
- |;
- ;;by:半边书生
- (defun lst_area(lst / nn ss x1 y1 x2 y2)
- ;...公式:Area=1/2*(x1*y2-x2*y1+x2*y3-x3*y2+... ...+xn*x1-x1*yn)
- (setq nn 0 ss 0)
- ;将首点坐标插入到尾点以后
- (setq lst (append lst (list (car lst))))
- ;开始循环求值
- (while (< nn (- (length lst) 1))
- (setq x1 (car (nth nn lst))
- y1 (cadr (nth nn lst))
- x2 (car (nth (1+ nn) lst))
- y2 (cadr (nth (1+ nn) lst))
- )
- (setq ss (+ ss (* x1 y2) (* -1 x2 y1)))
- (setq nn (1+ nn))
- )
- ;除以2得面积
- (setq ss (/ ss 2))
- );end
|