我想取一条AutoCAD曲线(多段线)&计算其近似的总平均斜率。附件是到目前为止我的代码
- (defun weightedAverageSlopeOfCurve (<obj>)
-
- ;Some function variables
- (setq chainage 0.0 interval 0.1 tempList nil orig (list 0 0 0 ) maxIterations (fix 1e5) average 0.0)
- (setq startChainage (vlax-curve-getDistAtParam <obj> (vlax-curve-getStartParam <obj>))
- endChainage (vlax-curve-getDistAtParam <obj> (vlax-curve-getEndParam <obj>))
- )
- ;Define the length of the curve
-
- (setq curveLength (- endChainage startChainage )
- chainage startChainage)
- ;Caclulate the number of iterations
-
- (setq iterations (fix (/ curveLength interval)))
- ;;Take some loading off the CPU if too many iterations required. Revert to maxIterations
- (if
- (> iterations maxIterations)
- (setq interval (/ curveLength maxIterations) iterations maxIterations)
- )
- (repeat iterations
- (setq dy/dx (vlax-curve-getFirstDeriv <obj> (vlax-curve-getParamAtDist <obj> chainage))
- slope (angle orig dy/dx))
- (setq average (+ average (/ slope iterations)))
- (setq chainage (+ chainage interval))
-
- )
- average
- )
有人对另一种方法的方法或建议有什么想法吗? |