( defun mpt(pt1 pt2)
  (polar pt1
    (angle pt1 pt2)
    (/(distance pt1 pt2) 2)
  )
)
( defun getdms (pt1 pt2)
   
   (setq space " ")

   (setq d3 (angle pt1 pt2))
   (setq d1 (rtd d3))
   ;(setq d1 (* (/ d3 pi) 180.0))
   (setq d1 (- 450.0 d1))

   (if (>= d1 360.0)  (setq d1 (- d1 360.0)))

   (setq d (fix d1))
   (setq m1  (* (- d1 d) 60.0))
   (setq m (fix m1))
   (setq s1  (* (- m1 m) 60.0))
   (setq s (fix s1))
   (setq s (+ s 5))
   (setq s (* (/ s 10) 10))
   (cond (
           ( >= s 60)
           (setq s (- s 60))
           (setq m (+ m 1))
          )
    )
    (cond (
           ( >= m 60)
           (setq m (- m 60))
           (setq d (+ d 1))
          )
    )
    (cond (
           ( >= d 360)
           (setq d (- d 360))
          )
    )

    (setq ds (itoa d))
    (setq ms (itoa m))
    (setq l1 (strlen ms))
    (if (= (strlen ms) 1) (setq ms (strcat "0" ms)))

    (setq ss (itoa s))
    (setq l2 (strlen ss))
    (if (= (strlen ss) 1) (setq ss (strcat "0" ss)))

    (setq dms (strcat ds "%%d" ms (chr 39) ss (chr 34)))
    ;(strcat ds chr(248)  ms chr(39) ss chr(34))

 )
( defun getdist (pt1 pt2)

   (setq dist (distance pt1 pt2))
   (rtos dist)
   ;(rtos 5.123)
)


(defun c:dpar()
  (setq dist (getreal "\n Enter offset diatance. "))
  (setq pt1 (getpoint "\n Define the first point. "))
  (setq pt2 (getpoint "\n Define the next point. "))
  (while (not (equal pt2 nil))
    (setq ang (angle pt1 pt2))
    (setq ang (- ang (* pi 0.5)))
    (setq pt1a (polar pt1 ang dist))
    (setq pt2a (polar pt2 ang dist))
    (command "line" pt1a pt2a "")
    (setq pt1 pt2)
    (setq pt2 (getpoint "\n Define the next point. "))
   )
)

(defun rtd (a) (* 180.0 (/ a pi)))
(defun dtr (a) (* pi (/ a 180.0)))
(defun brgd (pt1 pt2)
   (setq d3 (angle pt1 pt2))
   (setq d1 (rtd d3))
   (setq d1 (- 450.0 d1))

   (if (>= d1 360.0)  (setq d1 (- d1 360.0)))
   (+ d1 0)
)

(defun updn (pt1 pt2 d1 offset ht leng n)
    (setq ra (dtr d1))
    (setq oldra ra)
    (setq brg1 (- ra ( * pi 0.5))) ;brg-90

    (if ( >= ra pi) (setq ra (- ra pi)))

    (setq npt (mpt pt1 pt2))

    ; Annotate brg above line

    (setq dx (* offset (sin brg1)))
    (setq dy (* offset (cos brg1)))
    (setq xht (* 1.05 ( * ht (sin brg1))))
    (setq yht (* 1.05 ( * ht (cos brg1))))

    ;(setq x ( + (car npt) dx))
    ;(setq y ( + (cadr npt) dy))

    (if (= n 1) (setq x ( + (car npt) dx)) (setq x ( - (car npt) dx)))
    (if (= n 1) (setq y ( + (cadr npt) dy)) (setq y ( - (cadr npt) dy)))

    (cond
      ( ( = n 1)
      (if ( >= oldra pi) (setq x ( + x xht)))
      (if ( >= oldra pi) (setq y ( + y yht)))
      )
    )
    (cond
      ( ( = n 2)
      (if ( < oldra pi) (setq x ( - x  xht )))
      (if ( < oldra pi) (setq y ( - y  yht )))

      ;(if ( >= oldra pi) (setq x ( + x xht)))
      ;(if ( >= oldra pi) (setq y ( + y yht)))
      )
    )

    ;(if (< ra pi) (setq ra (+ ra pi)))
    (setq dx (* leng (sin ra)))
    (setq dy (* leng (cos ra)))

    (setq x (- x dx))
    (setq y (- y dy))


    (list x y)
)


(defun c:wbd()
  ;(textscr)
  (setq offset 0.6)
  (setq wf 0.857143)

  (cond
    ( (or (= sc 0) (= sc nil))
       (setq sc (getreal "\Enter scale: <1000>"))
       (if (= sc nil) (setq sc 1000.0))

       (setq ht (getreal "\Enter text ht for brg and dist: <1.6>"))
       (if (= ht nil) (setq ht 1.6))
       (setq sf (/ sc 1000.0))
       (setq ht (* ht sf))
       (setq offset (* offset sf))
    )
  )

  (setq choice 0)
  (if (or (<= choice 0) (> choice 4))
    ;(princ  "\n 1=Brg only  2=Dist only  3=Brg above, dist below")
    (setq choice
    (getint "\n 1=brg only  2=dist only  3=brg above, dist below  4=brg & dist same line ")

    )
  )
 ;(graphscr)

  (setq pt1 (getpoint "\n define first point "))
  (setq pt2 (getpoint "\n define next point "))

 (while (not (equal pt2 nil))
     (setq dms (getdms pt1 pt2))
     (setq noc1 (- (strlen dms) 4.1)) 
     ; %%d ' and " (5 characters) taken as 0.9 character 
     (setq leng1 ( * noc1 ht ))
     (setq leng1 ( * (* leng1 wf) 0.5))
     (setq d1 (brgd pt1 pt2))

     (setq diss (getdist pt1 pt2))
     (setq noc2 (- (strlen diss) 0.8)) 
     ; . taken as 0.2 character
     (setq leng2 (* noc2 ht ))
     (setq leng2 (* (* leng2 wf) 0.5))

     (cond
       ( (or (= choice 1) (= choice 3))
         (setq n 1)
         (setq pt (updn pt1 pt2 d1 offset ht leng1 n))
         (setq d2 d1)
         (if (>= d1 180.0) (setq d1 (- d1 180.0)))
         (command "text" pt ht d1 dms)
         (setq d1 d2)
        )
      )

    (cond
       ( (or (= choice 2) (= choice 3))
         (setq n 2)
         (setq pt (updn pt1 pt2 d1 offset ht leng2 n))
         (if (>= d1 180.0) (setq d1 (- d1 180.0)))
         (command "text" pt ht d1 diss)
       )
     )

   (cond
      ( (= choice 4)
        (setq bandd (strcat dms "  " diss))
        (setq leng3 (+ leng1 leng2))
        (setq n 1)
        (setq pt (updn pt1 pt2 d1 offset ht leng3 n))
        (if (>= d1 180.0) (setq d1 (- d1 180.0)))
        (command "text" pt ht d1 bandd)
      )
   )
   ;(command "text" pt ht d1 diss)
   (setq pt1 pt2)
   (setq pt2 (getpoint "\n define next point "))

 )
)

