明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1275|回复: 2

用二阶行列式法计算点表面积,带符号

  [复制链接]
发表于 2018-2-7 23:02 | 显示全部楼层 |阅读模式
  1. ;;参数:lst:点表,格式((x1 y1)(x2 y2)(x3 y3)(x4 y4)(x5 y5))
  2. ;;返回:面积值,顺时针为负,逆时针为正
  3. ;|
  4. (defun c:tst()
  5.   (setq lst (list
  6.                 '(28.375 314.517)
  7.                 '(397.730 127.575)
  8.                 '(944.173 155.364)
  9.                 '(1058.016 319.569)
  10.                 '(622.885 544.405)
  11.                 '(139.688 438.303)
  12.             )        
  13.   )
  14.   (princ (rtos (lst_area lst) 2 6))
  15. )
  16. |;
  17. ;;by:半边书生
  18. (defun lst_area(lst / nn ss x1 y1 x2 y2)
  19.         ;...公式:Area=1/2*(x1*y2-x2*y1+x2*y3-x3*y2+... ...+xn*x1-x1*yn)
  20.         (setq nn 0 ss 0)
  21.         ;将首点坐标插入到尾点以后
  22.         (setq lst (append lst (list (car lst))))
  23.         ;开始循环求值
  24.         (while (< nn (- (length lst) 1))
  25.                  (setq x1 (car (nth nn lst))
  26.                              y1 (cadr (nth nn lst))
  27.                              x2 (car (nth (1+ nn) lst))
  28.                              y2 (cadr (nth (1+ nn) lst))
  29.                  )
  30.                  (setq ss (+ ss (* x1 y2) (* -1 x2 y1)))
  31.                  (setq nn (1+ nn))
  32.         )
  33.         ;除以2得面积
  34.         (setq ss (/ ss 2))
  35. );end
发表于 2018-2-8 10:17 | 显示全部楼层
谢谢! 分享学习!!!!
发表于 2020-8-6 21:43 | 显示全部楼层
这个也很好,也谢谢你
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 11:43 , Processed in 0.394257 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表