XDGE几何库应用 ---获取曲线重叠段
本帖最后由 Lispboy 于 2017-2-13 13:06 编辑ARX功能强大,尤其是其中的AcGe几何库,最近研究了下,有些心得
下面探讨如何获得两条曲线重叠的部分
几何库里面有个类 AcGeCurveCurveInt3d,这个类就是处理两条相交曲线的各种位置关系的,其中
1、overlapCount 方法获取重叠段的数量
2、getOverLapRanges 获得指定索引(数量,基于0)的两条曲线上的重叠的范围的参数(AcGeInterval)
得到重叠的参数范围,就可以扣除局部的曲线了(使用通用函数库的xd::curve:getsub函数)
XDRX API 封装了ARX的几何库方法供LISP调用
下面是代码:
(defun c:tt ()
(if (and (setq e1 (car (xdrx_entsel
"\n选取第一个多段线<退出>:"
'((0 . "LWPOLYLINE"))
)
)
)
(setq e2 (car (xdrx_entsel
"\n选取第二个多段线<退出>:"
'((0 . "LWPOLYLINE"))
)
)
)
)
(progn
(setq g1 (xdge::constructor e1) ;;构建第一条多段线的几何实体
g2 (xdge::constructor e2) ;;构建第二条多段线的几何实体
)
(if (setq gint (xdge::constructor "kCurveCurveInt3d" g1 g2)) ;;从两个几何实体构造AcGeCurveCurveInt3d对象
(progn
(setq num (xdge::getpropertyvalue gint "overlapcount")) ;;获取重叠段的数量
(setq i-1
ss (ssadd)
)
(repeat num
(setq i (1+ i)
g (xdge::getpropertyvalue gint "getOverLapRanges" i) ;;获得第i段重叠的曲线范围参数
intv1 (car g) ;;获得第一条曲线的重叠部分的范围AcGeInterval对象
param (xdge::getpropertyvalue intv1 "getbounds") ;;从AcGeInterval得到曲线参数上下范围
)
(setq e (xd::curve:getsub e1 (car param) (cadr param) 0));;调用通用LISP函数库函数扣取曲线部分实体(几何实体)
(xdge::entity:make e) ;;生成数据库AcDbPolyline对象
(xdrx_setpropertyvalue;;设置颜色6,常量宽度60
(entlast)
"color"
6
"constantwidth"
60.0
)
(ssadd (entlast) ss)
)
(xdrx_prompt "\n发现了" num "个重叠段,品红色标记出.")
(sssetfirst nil ss)
)
) (xdge::free)
)
)
(princ)
)
AcGeCurveCurveInt3d类,XDRXAPI 封装的方法
<kCurveCurveInt3d>:
Edit Functions:
├───set
Intersection Query Functions:
├───intPoint
├───intPoints
├───intPointTol
├───isTangential
├───isTransversal
├───numIntPoints
├───overlapCount
├───overlapDirection
Ordering Functions:
├───changeCurveOrder
├───orderWrt1
├───orderWrt12
Query Functions:
├───curve1
├───curve2
├───getIntParams
├───getIntRanges
├───getOverlapRanges
├───getPointOnCurve1
├───getPointOnCurve2
├───tolerance
<kEntity3d>:
Equality Checking Functions:
├───isEqualTo
Point Containment Functions:
├───isOn
Type Identification Functions:
├───isKindOf
├───type
谢谢老师分享{:1_23:} 老师:我使用这个插件发现一个问题,对于二个封闭的图形生成的是选择的第一条曲线的非重叠段;
另一个问题:能不能框选生成多条曲线生成重叠段。 我测试的结果也是有上述问题,应该是函数出问题了。估计是后面的函数有修改造成的。 开心68602 发表于 2021-11-1 10:57
老师:我使用这个插件发现一个问题,对于二个封闭的图形生成的是选择的第一条曲线的非重叠段;
另一个问题 ...
修改了下代码,试试下面的
(defun c:tt ()
(if (and (setq e1 (car (xdrx_entsel
"\nSelect the first polyline<Exit>:"
'((0 . "LWPOLYLINE"))
)
)
)
(setq e2 (car (xdrx_entsel
"\nSelect second polyline <Exit>:"
'((0 . "LWPOLYLINE"))
)
)
)
)
(progn
(setq g1 (xdge::constructor e1)
;;Construct the geometric entity of the first polyline
g2 (xdge::constructor e2)
;;Construct the geometric entity of the second polyline
)
(if (setq gint (xdge::constructor "kCurveCurveInt3d" g1 g2))
;;Construct AcGeCurveCurveInt3d object from two geometric entities
(progn
(setq num (xdge::getpropertyvalue gint "overlapcount"))
;;Get the number of overlapping segments
(setq i-1
ss (ssadd)
)
(repeat num
(setq i (1+ i)
g (xdge::getpropertyvalue gint "getOverLapRanges" i)
;;Get the overlapping curve range parameters of the i-th segment
intv1 (car g)
;;Get the range AcGeInterval object of the overlapping part of the first curve
param (xdge::getpropertyvalue intv1 "getbounds")
;;Get the upper and lower range of curve parameters from AcGeInterval
)
;(setq e (xd::curve:getsub e1 (car param) (cadr param) 0))
(setq e (xdge::setpropertyvalue g1 "setinterval" (car param) (cadr param) ))
;;Call the general LISP function library function to deduct part of the curve entity (geometric entity)
(xdge::entity:make e)
;;Generate database AcDbPolyline object
(xdrx_setpropertyvalue
;;Set color 6, constant width 60
(entlast)
"color"
6
"constantwidth"
60.0
)
(ssadd (entlast) ss)
)
(xdrx_prompt
"\n"
num
"overlapping segments found, marked in magenta."
)
(sssetfirst nil ss)
)
)
(xdge::free)
)
)
(princ)
)
LoveArx 发表于 2023-11-15 06:15
修改了下代码,试试下面的
今天刚看到,试了一下,能用了,非常感谢老师。{:1_23:} 封闭的多边形就不行呢大佬出个封闭的也可以用的
页:
[1]