# TheSwamp

## Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew.. on March 20, 2019, 03:05:26 PM

Title: help locating a code to draw arc length
Post by: andrew.. 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
Title: Re: help locating a code to draw arc length
Post by: ribarm 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]
`(defun c:arcstptenptlength ( / ArcStartEndLength p1 p2 len )   (defun ArcStartEndLength ( startPoint endPoint arcLength                            / newton chord ang rad mid cen )     ;; use the Newton method to compute the arc half angle according to its length and chord    (defun newton ( arc chord / k x )      (setq k (/ chord arc)            x (sqrt (- 6 (* 6 k)))      )      (repeat 6        (setq x (- x (/ (- (sin x) (* k x)) (- (cos x) k))))      )    )     (setq chord (distance startPoint endPoint))    (if (< chord arcLength)      (progn        (setq ang (newton arcLength chord)              rad (abs (/ chord 2. (sin ang)))              mid (mapcar '(lambda ( p1 p2 ) (/ (+ p1 p2) 2.0))                          startPoint                          endPoint                  )        )        (if (equal (/ pi 2) ang 1e-009)          (setq cen mid               rad (/ chord 2.)          )          (setq            cen (polar mid                     (+ (angle startPoint endPoint) (/ pi 2))                     (* rad (cos ang))                )          )        )        (entmakex          (list            (cons 0 "ARC")            (cons 10 cen)            (cons 40 rad)            (cons 50 (angle cen startPoint))            (cons 51 (angle cen endPoint))          )        )      )    )  )   (setq p1 (getpoint "\nPick or specify start point of arc : "))  (setq p2 (getpoint "\nPick or specify end point of arc : "))  (initget 7)  (setq len (getdist (strcat "\nPick or specify arc length (must be larger than : " (rtos (distance p1 p2) 2 20) ") : ")))  (while (<= len (distance p1 p2))    (prompt "\nArc length must be larger than : ") (princ (rtos (distance p1 p2) 2 20)) (prompt "... Pick or specify length again : ")    (setq len (getdist))  )  (ArcStartEndLength p1 p2 len)  (princ)) `

HTH., M.R.
Title: Re: help locating a code to draw arc length
Post by: gile on March 20, 2019, 03:42:31 PM
Hi,

There was also this reply (http://www.theswamp.org/index.php?topic=28000.msg335867#msg335867).
Title: Re: help locating a code to draw arc length
Post by: Lee Mac on March 20, 2019, 05:48:51 PM
Here's another:
https://www.cadtutor.net/forum/topic/43920-can%C2%B4t-draw-a-correct-arc-lengthplease-help/?do=findComment&comment=359272