马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 Lispboy 于 2016-10-10 21:02 编辑
应朋友要求,研究了下曲线分割图形,下面是一个演示的代码,完善完善就可以用到“分地”的应用上。代码用了API ARX的 几何库,算这些图形分析很强。
(defun c:tt () (defun _callback (dynpt)
(redraw)
(xdge::setpropertyvalue xline "set" dynpt (mapcar
'+
dynpt
ydir
)
)
(xdge::setpropertyvalue crvInt "set" gsrc xline)
(if (>= (length (setq ints (xdge::getpropertyvalue crvInt "intPoints")))
2
)
(progn
(xdge::setpropertyvalue tmpLine "set" (car ints) (last ints))
(xdge::setpropertyvalue tmpRay "set" (setq midpnt
(xdge::getpropertyvalue tmpLine "midpoint")
)
(mapcar
'-
midpnt
xdir
)
)
(xdge::setpropertyvalue crvInt "set" gsrc tmpRay)
(setq tmpPnt (xdge::getpropertyvalue crvInt "intPoints"))
(if (= 'LIST (type (car tmppnt)))
(setq tmpPnt (last tmppnt))
)
(setq gsub (xd::curve:getsub e (trans (car ints) 0 1)
(trans (cadr ints) 0 1) (trans tmppnt 0
1
)
)
#tarea1 (abs (xdge::getpropertyvalue gsub "area"))
)
(xdrx_setpropertyvalue eTxtL "textstring" (rtos #tarea1 2 1))
(xdrx_setpropertyvalue eTxtR "textstring" (rtos (- #tarea #tarea1) 2
1
)
)
(xdrx_setpropertyvalue eTxtM "textstring" (strcat "总面积:"
(rtos #tarea 2 1)
)
)
(xdge::free gsub)
(xdrx_grdraw 1 0 tmpLine)
)
(progn
(xdrx_setpropertyvalue eTxtL "textstring" "0.0")
(xdrx_setpropertyvalue eTxtR "textstring" "0.0")
(xdrx_setpropertyvalue eTxtM "textstring" (strcat "总面积:"
(rtos #tarea 2 1)
)
)
)
)
)
(defun _writeText ()
(xdrx_setpropertyvalue (entlast) "color" 253)
(setq h (/ (distance (car box) (last box)) 13.0)
an (angle (car box) (cadr box))
)
(xdrx_text_make (last box) "0.0" h an)
(setq etxtL (entlast))
(xdrx_setpropertyvalue etxtL "color" 1)
(xdrx_text_make (caddr box) "0.0" h an)
(setq etxtR (entlast))
(xdrx_setpropertyvalue etxtR "color" 1 "horizontalMode" 2
"alignmentPoint" (caddr box)
)
(setq midp (xdrx_midp (last box) (caddr box))
midp (mapcar
'+
midp
(xdrx_vector_product ydir (* 2 h))
)
)
(xdrx_text_make midp "0.0" h an)
(setq etxtM (entlast))
(xdrx_setpropertyvalue etxtM "color" 2 "horizontalMode" 4 "verticalmode"
0 "AlignmentPoint" midp
)
)
(if (and
(setq e (car (xdrx_entsel "\n拾取封闭的曲线<退出>" '((0 . "*POLYLINE,SPLINE,ELLIPSE,CIRCLE")))))
(xdrx_getpropertyvalue e "isclosed")
)
(progn
(xdrx_begin)
(xdrx_sysvar_push '("cursorsize" 3) '("osmode" 32) '("dimzin" 0))
(setq xdir (getvar "ucsxdir")
ydir (getvar "ucsydir")
box (xdrx_entity_box e)
gsrc (xdge::constructor e)
crvInt (xdge::constructor "kCurveCurveInt3d")
tmpLine (xdge::constructor "kLineSeg3d")
tmpRay (xdge::constructor "kRay3d" '(0 0 0)
(xdrx_vector_negate xdir)
)
#tarea (abs (xdrx_getpropertyvalue e "area"))
)
(xdrx_polyline_make box t)
(_writeText)
(setq xline (xdge::constructor "kLine3d" '(0 0 0) ydir))
(xdrx_pointmonitor "_callback")
(if (getpoint "\n移动十字光标<退出>")
(xdge::entity:make tmpline)
(redraw)
)
(xdrx_pointmonitor)
(xdrx_sysvar_pop)
(xdrx_end)
)
)
(princ)
)
|