明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2600|回复: 7

求写一函数判断两点是否在曲线同一侧

[复制链接]
发表于 2012-2-26 17:38:51 | 显示全部楼层 |阅读模式
(defun curve-pt-side (entcurve pt1 pt2)

)

如果是同一侧返回T

求解啊!!!
发表于 2012-2-26 21:42:37 | 显示全部楼层
  1. (defun curvesidep (curve p1 p2 / a b)
  2.   (setq a (vlax-curve-getclosestpointto curve p1)
  3.         b (vlax-curve-getclosestpointto curve p2)
  4.         )
  5.   (not (inters a b p1 p2 ) )
  6.   )
  7. ;;;测试
  8. (defun c:tt(/ curve p1 p2)
  9.   (while (not (setq curve (car (entsel "\n**选择曲线:")))))
  10.   (while (not (setq p1 (getpoint "\n 第一点:"))))
  11.   (while (not (setq p2 (getpoint "\n 第二点:"))))
  12.   (if (curvesidep curve p1 p2)
  13.     (princ "\n两点在曲线同侧.")
  14.     (princ "\n两点在曲线两侧.")
  15.     )
  16.   (princ)
  17.   )
发表于 2012-2-26 22:57:25 | 显示全部楼层
Gu_xl 发表于 2012-2-26 21:42


顾版程序不完全正确,拿此图形一试便知。曲线选spline,两点选直线的端点。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2012-2-27 00:50:32 | 显示全部楼层
本帖最后由 caoyin 于 2012-2-27 01:40 编辑

参考:
http://space.mjtd.com/blog-213172-306.html

(lt:curve-getDistancePtTo ENTCURVE PT1)
(lt:curve-getDistancePtTo ENTCURVE PT2)
以上2者返回,如果同为正值或同为负值则表明2点在曲线的同一侧,反之则在不同侧
 楼主| 发表于 2012-2-27 13:12:33 | 显示全部楼层
多谢各位高手的热心回答!
发表于 2012-2-27 16:39:10 | 显示全部楼层
本帖最后由 Gu_xl 于 2012-2-27 19:06 编辑
cabinsummer 发表于 2012-2-26 22:57
顾版程序不完全正确,拿此图形一试便知。曲线选spline,两点选直线的端点。

修改了下,再测试下这个!
  1. ;;;判断两点是否曲线同侧
  2. (defun curvesidep  (curve p1 p2 / a a1 b b1 a2 b2)
  3. (cond ((equal p1
  4.   (setq a (vlax-curve-getclosestpointto curve p1))
  5.   1e-6
  6.   ) ;_ p1在曲线上的最近点
  7.   nil
  8. )
  9. ((equal p2
  10.   (setq b (vlax-curve-getclosestpointto curve p2))
  11.   1e-6
  12.   ) ;_ p2在曲线上的最近点
  13.   nil
  14. )
  15. (t
  16.   (setq a1   (mapcar '+
  17.        a
  18.        (vlax-curve-getFirstDeriv
  19.          curve
  20.          (vlax-curve-getParamAtPoint curve a)
  21.        )
  22.       ) ;_ p1在曲线上最近点的切线方向点
  23.         ang1 (+ (* 0.5 pi) (angle a a1)) ;_ p1在曲线上最近点的法线方向
  24.         a2   (inters a a1 p1 (polar p1 ang1 1) nil) ;_ p1在曲线上的垂足点
  25.         b1   (mapcar '+
  26.        b
  27.        (vlax-curve-getFirstDeriv
  28.          curve
  29.          (vlax-curve-getParamAtPoint curve b)
  30.        )
  31.       ) ;_ p2在曲线上最近点的切线方向点
  32.         ang2 (+ (* 0.5 pi) (angle b b1)) ;_ p2在曲线上最近点的法线方向
  33.         b2   (inters b b1 p2 (polar p2 ang2 1) nil) ;_ p2在曲线上的最近点
  34.   )
  35.   (if (> ang1 (* pi 2))
  36.     (setq ang1 (- ang1 pi pi))
  37.   )
  38.   (if (> ang2 (* pi 2))
  39.     (setq ang2 (- ang2 pi pi))
  40.   )
  41.   (equal (equal ang1 (angle a2 p1) 1e-6)
  42.   (equal ang2 (angle b2 p2) 1e-6)
  43.   )
  44. )
  45.   )
  46.   )


发表于 2013-3-8 12:33:31 | 显示全部楼层
Gu_xl 发表于 2012-2-27 16:39
修改了下,再测试下这个!

谢谢版主,借用了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-29 15:26 , Processed in 0.178688 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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