How to draw arc if only two points and arc length is given?

How to draw arc if only two points and arc length is given?

Anonymous
Not applicable
4,790 Views
17 Replies
Message 1 of 18

How to draw arc if only two points and arc length is given?

Anonymous
Not applicable

How to draw an arc if only two points and Arc length is given?

Any Lisp or Idea?

 

Thanks

0 Likes
Accepted solutions (1)
4,791 Views
17 Replies
Replies (17)
Message 2 of 18

ВeekeeCZ
Consultant
Consultant
Accepted solution

If you mean 'two end points and length' given, then HERE is the comprehensive thread up on this subject.

Message 3 of 18

_gile
Consultant
Consultant

Hi,

 

(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))
	)
      )
    )
  )
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 18

john.uhden
Mentor
Mentor

Is that function by Sir Isaac Newton, you know, the guy who invented gravity?

John F. Uhden

0 Likes
Message 5 of 18

_gile
Consultant
Consultant

Sir Isaac Newton himself didn't wrote this LISP function Smiley Wink

He defined a method to find by successive approximations the zero of a mathematical function.

 

In this case where looking to solve the equation:

 

chord / arc = sin (angle / 2) / (angle / 2)

 

In other words were're searching the zero of the function:

 

f(x) = sin(x) - (chord / arc) * x (where x = angle / 2).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 18

john.uhden
Mentor
Mentor

am a Civil type.  In my first job as a laborer back in the early 70s, I was assigned to compute all the highway geometry (jughandles and such) using a pencil, paper, crank calculator, and a book of trigonometric values for sine, cosine, etc.

 

Rearranging the formula C=2Rsin(Delta/2)

 

Delta = 2arcsin(C/2R)

 

Isn't that easier?

John F. Uhden

0 Likes
Message 7 of 18

_gile
Consultant
Consultant

@john.uhden

 

Delta = 2arcsin(C/2R) works fine indeed, but it requires to know the chord (C) and the radius (R), in the OP we only know the chord and the arc length.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 8 of 18

john.uhden
Mentor
Mentor

Agreed.  That was a major shortcoming of mine.  Sorry.

I'd like to figure another way out of it, but my guess is that you can't circumvent Newton.

 

Okay, knowing that L=R*Delta,

then R=L/Delta

so sin(Delta/2)/Delta = C/2L

 

but how do you solve for Delta from that??

John F. Uhden

0 Likes
Message 9 of 18

Ranjit_Singh
Advisor
Advisor

@john.uhden You will have to do it iteratively. See one way using excel

;;;created by Ranjit Singh 3/14/17
(defun somefunc  (pt1 pt2 arcl / xclobj wksht chordd cang)
 (setq chordd (distance (cons (car pt1) (list (cadr pt1))) pt2))
 (cond ((> arcl chordd)
        (setq wksht (vlax-get (vlax-invoke (vlax-get (setq xclobj (vlax-get-or-create-object "excel.application")) 'workbooks)
                                           'add)
                              'activesheet))
        (mapcar '(lambda (x y) (vlax-put-property xclobj x y))
                '(iteration maxiterations maxchange)
                '(1 32767 1e-15))
        (mapcar '(lambda (x y) (vlax-put (vlax-get-property wksht 'range x) 'value y))
                '("a1" "a2" "a3" "b1" "b2" "b3")
                (list "45" arcl chordd "=A1/SIN(RADIANS(A1/2))" "=360*A2/PI()/A3" "=b2-b1"))
        (vlax-invoke (vlax-get-property wksht 'range "b3")
                     'goalseek
                     "0"
                     (vlax-get-property wksht 'range "a1"))
        (setq cang (rtos (variant-value (vlax-get-property (vlax-get-property wksht 'range "A1") 'value2)) 2 15))
        (mapcar 'vlax-release-object (list wksht xclobj))
        (command "._arc" pt1 "_e" pt2 "_angle" cang)
        (command "._mirror" (entlast) "" pt1 pt2 "_n"))
       ("Arc should be longer than Chord!")))
0 Likes
Message 10 of 18

_gile
Consultant
Consultant

john.uhden a écrit :Okay, knowing that L=R*Delta,

then R=L/Delta

so sin(Delta/2)/Delta = C/2L

 

but how do you solve for Delta from that??


It is here that Sir Isaac Newton enters the scene.

 

sin(Delta/2)/Delta = C/2L <=> sin(Delta/2)/(Delta/2) = C/L <=> sin(Delta/2) - (C/L)*(Delta/2) = 0

 

This last expression can be seen as the 0 of  the function:

f(x) = sin(x) - k*x

where x=Delta/2 and k=C/L

 

Applying the Newton's method to this function and its derivative: f'(x) = cos(x) - k gives an accurate result after 6 iterations.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 18

john.uhden
Mentor
Mentor

Ya know, I was thinking of Excel earlier today.  That iteration option is the key.  I once developed a spreadsheet to calculate how long Grandma's money would last but created a circular reference.  Then I found out about the iteration capability and voila!  Excel should have been around back in the day when I wrote my own drainage programs.  I spent more time testing convergence mechanisms than any of the input or hydraulic calculations.  Nobody knows but me, but I submitted and got approved the first computations using a Type III unit hydrograph submitted to the NJDEP.  Whatever... I still can't land a regular job.

 

It's funny that I just found out yesterday that my compiled basic programs from DOS days won't run in Windows 7 in any compatibility mode, but they run on my buddy's Vista machine.

John F. Uhden

0 Likes
Message 12 of 18

_gile
Consultant
Consultant

Attached a little Excel file which illustrates the Newton's method to find arc dimensions from arc length and chord (arc & corde) or arc length and sagitta (arc & flèche).

Just fill the 2 blue cells in a row, the results of the successive approximations are shown in grey.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 13 of 18

john.uhden
Mentor
Mentor

Tres bien, actuelment magnifique!  (Je ne really parlez francaise, but I make excellent chicken francaise. :]  )

John F. Uhden

0 Likes
Message 14 of 18

Anonymous
Not applicable

Post no 45 Solved the issue. This is what I wanted exactly.

Thanks

 

Other Lisps given by experts are not working. 

it loads, but command does not work.

0 Likes
Message 15 of 18

_gile
Consultant
Consultant

syedshanhaider a écrit :

Other Lisps given by experts are not working. 

it loads, but command does not work.


The LISP routine I gave upper is working (I use this algorithm since about 15 years).

The routine written by CAB (Charles Alan Butler) also uses the Newton's method. Compare CAB's factor sub routine and the upper newton sub-routine.

 

To test the upper ArcStartEndLength routine:

 

(defun c:test (/ sPt ePt l)
  (and
    (setq sPt (getpoint "\nStart point: "))
    (setq ePt (getpoint sPt "\nEnd point: "))
    (setq l (getdist "\nArc length: "))
    (ArcStartEndLength (trans sPt 1 0) (trans ePt 1 0) l)
  )
  (princ)
)

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 16 of 18

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

Post no 45 Solved the issue. This is what I wanted exactly.

Thanks

 

Other Lisps given by experts are not working. ..........

it loads, but command does not work.


You did not mention the exact error you get. It might be the way the function is called. The code I presented in post 9 needs to be called with arguments (same with post 3). If you simply type somefunc it will not work. Example call (somefunc (getpoint) (getpoint) 22), for a arc of length 22.
0 Likes
Message 17 of 18

marko_ribar
Advisor
Advisor

@_gile 

I know that there is statring guess of x, but from what equation did you derived x in this (setq ... ) expression?

 

    (setq k (/ chord arc)
	  x (sqrt (- 6 (* 6 k)))
    )

 

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 18 of 18

marko_ribar
Advisor
Advisor

Just checked... It seems that this is also good :

 

  ;; 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 pi
    )
    (repeat 10
      (setq x (- x (/ (- (sin x) (* k x)) (- (cos x) k))))
    )
  )

I've decided to put initial x=pi, since (- (cos x) k) would give maximal abs value : (- (-1) k)

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes