skill.geometry.Path_getLength

Last-modified: 2013-03-04 (月) 23:50:40
; -----------------------------------------------------------------------------
; (Path_getLength this)
; -----------------------------------------------------------------------------
; パスの頂点列 this を受け取り、隣り合う頂点間の距離の合計を求めて返す、汎用の関数。
;
; ※ レイアウトのパスオブジェクト path の頂点列は path~>points で得られます。、
;    path の両端が truncate の場合には (Path_getLength path~>points) で長さが得ら
;    れますが、path の片方または両方の端が extended、round、variable の場合は、
;    この関数だけでは正確な長さは求まりませんので、ご注意ください。
; -----------------------------------------------------------------------------
(define (Path_getLength this)
  (letrec
    (
    (p  (car this))
    (ps (cdr this))
    (len 0.0)
    )
    (while ps
      (setq len (plus len (Point_getDistanceTo p (car ps))))
      (setq p  (car ps))
      (setq ps (cdr ps))
    )
    len
  )
)
; -----------------------------------------------------------------------------
; (Point_getDistanceTo this another)
; -----------------------------------------------------------------------------
; 二点 this と another の間の距離を求めて返す、汎用の関数。
; -----------------------------------------------------------------------------
(define (Point_getDistanceTo this another)
  (let
    (
    (dx (difference (car  this) (car  another)))
    (dy (difference (cadr this) (cadr another)))
    )
    (sqrt (plus (times dx dx) (times dy dy)))
  )
)