Author Topic: help locating a code to draw arc length  (Read 232 times)

0 Members and 1 Guest are viewing this topic.

andrew..

  • Mosquito
  • Posts: 20
help locating a code to draw arc length
« on: March 20, 2019, 03:05:26 PM »
a few years ago there was code shared that draws arc length based on numeric input.
I can not seem to located it here.
Would anyone happen to have a copy of it they can share?

thanks

ribarm

  • Water Moccasin
  • Posts: 2101
  • Marko Ribar, architect
Re: help locating a code to draw arc length
« Reply #1 on: March 20, 2019, 03:37:51 PM »
I've found something posted by I think @gile at autodesk forums... It's based on Newton's formula :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:arcstptenptlength ( / ArcStartEndLength p1 p2 len )
  2.  
  3.   (defun ArcStartEndLength ( startPoint endPoint arcLength
  4.                             / newton chord ang rad mid cen )
  5.    
  6.     ;; use the Newton method to compute the arc half angle according to its length and chord
  7.     (defun newton ( arc chord / k x )
  8.       (setq k (/ chord arc)
  9.             x (sqrt (- 6 (* 6 k)))
  10.       )
  11.       (repeat 6
  12.         (setq x (- x (/ (- (sin x) (* k x)) (- (cos x) k))))
  13.       )
  14.     )
  15.  
  16.     (setq chord (distance startPoint endPoint))
  17.     (if (< chord arcLength)
  18.       (progn
  19.         (setq ang (newton arcLength chord)
  20.               rad (abs (/ chord 2. (sin ang)))
  21.               mid (mapcar '(lambda ( p1 p2 ) (/ (+ p1 p2) 2.0))
  22.                           startPoint
  23.                           endPoint
  24.                   )
  25.         )
  26.         (if (equal (/ pi 2) ang 1e-009)
  27.           (setq cen mid
  28.                rad (/ chord 2.)
  29.           )
  30.           (setq
  31.             cen (polar mid
  32.                      (+ (angle startPoint endPoint) (/ pi 2))
  33.                      (* rad (cos ang))
  34.                 )
  35.           )
  36.         )
  37.         (entmakex
  38.           (list
  39.             (cons 0 "ARC")
  40.             (cons 10 cen)
  41.             (cons 40 rad)
  42.             (cons 50 (angle cen startPoint))
  43.             (cons 51 (angle cen endPoint))
  44.           )
  45.         )
  46.       )
  47.     )
  48.   )
  49.  
  50.   (setq p1 (getpoint "\nPick or specify start point of arc : "))
  51.   (setq p2 (getpoint "\nPick or specify end point of arc : "))
  52.   (initget 7)
  53.   (setq len (getdist (strcat "\nPick or specify arc length (must be larger than : " (rtos (distance p1 p2) 2 20) ") : ")))
  54.   (while (<= len (distance p1 p2))
  55.     (prompt "\nArc length must be larger than : ") (princ (rtos (distance p1 p2) 2 20)) (prompt "... Pick or specify length again : ")
  56.     (setq len (getdist))
  57.   )
  58.   (ArcStartEndLength p1 p2 len)
  59.   (princ)
  60. )
  61.  

HTH., M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

gile

  • Water Moccasin
  • Posts: 2222
  • Marseille, France
Re: help locating a code to draw arc length
« Reply #2 on: March 20, 2019, 03:42:31 PM »
Hi,

There was also this reply.
Speaking English as a French Frog