注册 登录
明经CAD社区 返回首页

Gu_xl的个人空间 http://bbs.mjtd.com/?161460 [收藏] [复制] [分享] [RSS]

日志

点在封闭曲线内外判断

热度 14已有 3849 次阅读2012-12-11 09:08 |个人分类:Lisp公用函数|系统分类:开发| 曲线, 点在曲线内外判断, Lisp

 

点在曲线内外判断.LSP

本源代码由 Gu_xl 编写发布! 联系方式: Email: Gu_xl@sohu.com
;;功能:判断点在封闭曲线内外,自交曲线不适用 By Gu_xl 2012.07.31
;;返回: 点在封闭曲线上或曲线内,返回T,否则返回nil
;;测试: (gxl-PtInCurveP  (car(entsel "\n选择曲线:")) (getpoint))
(defun gxl-PtInCurveP  (POLY PT	   /	   CP	   LW
				   MINP	   MAXP	   MINX	   MINY
				   MAXX	   MAXY	   X	   Y
				   LST	   CLOCKWISEP	   ENDPARAM
				   CURVELENGTH	   PARAM   DIST
				   D1	   D2	   DEV	   )
  (cond
    ((equal pt
	    (setq cp (vlax-curve-getclosestpointto poly pt))
	    1e-8)) ;_ 点在曲线上 T
    ((progn
       (vla-GetBoundingBox
	 (setq lw (vlax-ename->vla-object POLY))
	 'MinP
	 'MaxP)
       (setq MinP (vlax-safearray->list MinP))
       (setq MaxP (vlax-safearray->list MaxP))
       (setq minx (car MinP)
	     miny (cadr MinP)
	     maxx (car MaxP)
	     maxy (cadr MaxP)
	     x	  (car pt)
	     y	  (cadr pt)
	     )
       (or (< x minx)
	   (> x maxx)
	   (< y miny)
	   (> y maxy)
	   )
       ) 
     NIL ;_ 点在曲线最小包围盒外 nil
     )
    (t
     (setq
       lst (mapcar
	     (function
	       (lambda (x)
		 (vlax-curve-getParamAtPoint
		   lw
		   (vlax-curve-getClosestPointTo lw x)
		   )
		 )
	       )
	     (list minp
		   (list minx maxy)
		   MaxP
		   (list maxx miny)
		   )
	     )
       ) ;_ 最小包围盒点在曲线上的投影点的参数表
     (setq ClockwiseP
	    (if	(or
		  (<= (car lst) (cadr lst) (caddr lst) (cadddr lst))
		  (<= (cadr lst) (caddr lst) (cadddr lst) (car lst))
		  (<= (caddr lst) (cadddr lst) (car lst) (cadr lst))
		  (<= (cadddr lst) (car lst) (cadr lst) (caddr lst))
		  ) ;_  or
	      t
	      ) ;_  if
	   ) ;_ 判断曲线是否为顺时针,顺时针 = T
     (setq endparam    (vlax-curve-getendparam poly)
	   curvelength (vlax-curve-getDistAtParam poly endparam) ;_ 曲线长度
	   )
     (setq param (vlax-curve-getparamatpoint poly cp)
	   dist	 (vlax-curve-getDistAtParam poly param)
	   )
     (if (equal param (fix param) 1e-8)
       (progn
	 (setq d1 (- dist 1e-8))
	 (if (minusp d1)
	   (setq d1 (+ curvelength d1))
	   )
	 (setq d2 (+ dist 1e-8))
	 (if (> d2 curvelength)
	   (setq d2 (- d2 curvelength)))
	 (if (<	(distance pt (vlax-curve-getpointatdist poly d1))
		(distance pt (vlax-curve-getpointatdist poly d2))
		)
	   (setq param (vlax-curve-getparamatdist poly d1))
	   (setq param (vlax-curve-getparamatdist poly d2))
	   )
	 )
       )
     (setq dev (vlax-curve-getFirstDeriv poly param)
	   cp  (vlax-curve-getpointatparam poly param)
	   )
     (=	ClockwiseP
	(
	 (lambda (p1 p2 p3)
	   (<
	     (* (- (car p2) (car p1)) (- (cadr p3) (cadr p1)))
	     (* (- (cadr p2) (cadr p1)) (- (car p3) (car p1)))
	     )
	   )
	  pt
	  cp
	  (mapcar '+ cp dev)
	  )
	)
       )
    )
  )
原理见下图所示:


路过

雷人
10

握手
3

鲜花

鸡蛋

刚表态过的朋友 (13 人)

发表评论 评论 (1 个评论)

回复 tigcat 2020-11-22 22:21
高山仰止,得好好消化了

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

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

GMT+8, 2024-11-22 00:10 , Processed in 0.094436 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部