Author Topic: (Challenge) calculate arc length  (Read 7228 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
(Challenge) calculate arc length
« on: May 15, 2007, 07:55:04 AM »
I call you to write the program...

Find length of an arc, knowing length a chord and bulge.

d = length a chord
b = bulge


Code: [Select]
(lw_arc_Len b d)

(lw_arc_Len 0.5 100.) = 115.912
(lw_arc_Len -1.5 100.) = 212.939
(lw_arc_Len 30. 100.) = 4617.55
(lw_arc_Len -0.1 100.) = 100.665
« Last Edit: May 15, 2007, 07:56:28 AM by ElpanovEvgeniy »

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: (Challenge) calculate arc length
« Reply #1 on: May 15, 2007, 08:56:10 AM »
Code: [Select]
(defun test(b d)
  (* (/ d b) (+ (* b b) 1) (atan b))
)

(test -30.0 100)->4617.55
« Last Edit: May 15, 2007, 09:06:30 AM by yuanqiu »
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #2 on: May 15, 2007, 09:05:11 AM »
Code: [Select]
(defun test (b d)
  (* 4 (+ (* 0.5 d b) (/ d (/ (* 2 b) (- 1 (* b b))) 2)) (atan b))
)

(test -30.0 100)->4617.55

Hello Chen!
You have written the good program, it correctly works...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #3 on: May 15, 2007, 09:15:07 AM »
Code: [Select]
(defun test(b d)
  (* (/ d b) (+ (* b b) 1) (atan b))
)

(test -30.0 100)->4617.55


Magnificent code!
Who has still variants?
It still probably to improve...  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (Challenge) calculate arc length
« Reply #4 on: May 15, 2007, 11:44:38 AM »
WOW - I can't come close to that code. :-o
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #5 on: May 15, 2007, 12:01:14 PM »
WOW - I can't come close to that code. :-o

Code: [Select]
arc-len = l
arc-radius = r

l = x * 4 * r
r = 0.5 * d / sin (2 * x)

sin(2 * x) = (2 * tg(x))/(1 + (tg(x)*tg(x))

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #6 on: May 15, 2007, 12:11:25 PM »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: (Challenge) calculate arc length
« Reply #7 on: May 15, 2007, 12:23:16 PM »
Did I miss something?  Or do something wrong?  When using the code provided I don't get the right answer.

Code for tangent.
Code: [Select]
(defun tan (ang) (/ (sin ang) (cos ang)))
Then tested it like
Quote
Command: (test (tan (/ (getangle) 4.0)) (getdist))
 Specify second point:  Specify second point: 1.66982

List returned
Quote
                  ARC       Layer: "0"
                            Space: Model space
                   Handle = c4
            center point, X=  33.7210  Y=  15.5358  Z=   0.0000
            radius    1.0000
             start angle      0
               end angle     90
            length    1.5708
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #8 on: May 15, 2007, 12:35:55 PM »
Did I miss something?  Or do something wrong?  When using the code provided I don't get the right answer.

Code for tangent.
Code: [Select]
(defun tan (ang) (/ (sin ang) (cos ang)))
Then tested it like
Quote
Command: (test (tan (/ (getangle) 4.0)) (getdist))
 Specify second point:  Specify second point: 1.66982

List returned
Quote
                  ARC       Layer: "0"
                            Space: Model space
                   Handle = c4
            center point, X=  33.7210  Y=  15.5358  Z=   0.0000
            radius    1.0000
             start angle      0
               end angle     90
            length    1.5708

I have checked up on the computer...  :-o

Code: [Select]
Command: (test (tan (/ (getangle) 4.0)) (getdist))  Specify second point: 
Specify second point: 1.5708

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #9 on: May 15, 2007, 12:48:38 PM »
I did not know, that so the answer will be fast discovered.   :?
As soon as you will tell, I at once shall show the my version.  :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: (Challenge) calculate arc length
« Reply #10 on: May 15, 2007, 12:50:42 PM »
Did I miss something?  Or do something wrong?  When using the code provided I don't get the right answer.

Code for tangent.
Code: [Select]
(defun tan (ang) (/ (sin ang) (cos ang)))
Then tested it like
Quote
Command: (test (tan (/ (getangle) 4.0)) (getdist))
 Specify second point:  Specify second point: 1.66982

List returned
Quote
                  ARC       Layer: "0"
                            Space: Model space
                   Handle = c4
            center point, X=  33.7210  Y=  15.5358  Z=   0.0000
            radius    1.0000
             start angle      0
               end angle     90
            length    1.5708

I have checked up on the computer...  :-o

Code: [Select]
Command: (test (tan (/ (getangle) 4.0)) (getdist))  Specify second point: 
Specify second point: 1.5708
Am I picking wrong then?  For the angle I pick pt1 to pt2, then for the distance I pick pt1 to pt3.  See image for pt's.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #11 on: May 15, 2007, 12:57:56 PM »

Am I picking wrong then?  For the angle I pick pt1 to pt2, then for the distance I pick pt1 to pt3.  See image for pt's.


T.Willey

  • Needs a day job
  • Posts: 5251
Re: (Challenge) calculate arc length
« Reply #12 on: May 15, 2007, 01:11:11 PM »
Still doesn't want to work for me.  Pic added.  Code tested.
Code: [Select]
Command: (test (tan (/ 1.96346541 4)) (getdist))
 Specify second point: 1.66981
getdist = pt1 -> pt3

I don't understand.

Edit: Attached drawing used.
« Last Edit: May 15, 2007, 01:12:23 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: (Challenge) calculate arc length
« Reply #13 on: May 15, 2007, 01:15:22 PM »
no time to compete with you guys... but I guess is that the tangent formula is wrong no?

if my lisp's spirits still are around, I recall that a tan formula can be like:

  (setq *INFINITY* 1.7e308)
  (defun TAN (z / cosz)
    (if (zerop (setq cosz (cos z))) *INFINITY*
      (/ (sin z) cosz)))

if not, please ignore me, I am use to that....

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #14 on: May 15, 2007, 01:18:40 PM »
You arc have total angle (/ Pi 2.)
Code: [Select]
ARC       Layer: "0"
                            Space: Model space
                   Handle = c4
            center point, X=  33.7210  Y=  15.5358  Z=   0.0000
            radius    1.0000
             start angle      0
               end angle     90
            length    1.5708
for your arc, test code:

Code: [Select]
(test (tan (/ (/ Pi 2.) 4)) (getdist))

T.Willey

  • Needs a day job
  • Posts: 5251
Re: (Challenge) calculate arc length
« Reply #15 on: May 15, 2007, 01:27:09 PM »
... but I guess is that the tangent formula is wrong no?
Luis I got the same answer with your equation.

You arc have total angle (/ Pi 2.)
Okay now I'm totally lost.  This worked, but I don't know how you came up with answer from the pic you posted in the first post.  I can see that the angle difference between the start and end is 90 degrees (which = (/ Pi 2.0)), but I don't see how you get it from your pic.

Guess I need to do a little more studying.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #16 on: May 15, 2007, 01:34:31 PM »
his worked, but I don't know how you came up with answer from the pic you posted in the first post.  I can see that the angle difference between the start and end is 90 degrees (which = (/ Pi 2.0)), but I don't see how you get it from your pic.


I have been assured, that you were mistaken specifying points p1 and p2...
In my picture, I wished to show you, you specify what angle!
http: // www.theswamp.org/index.php? topic=16529.msg200764*msg200764

If you will use an angle pt3-pt1-pt2 it should not be divided on 4.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #17 on: May 15, 2007, 01:42:37 PM »
Tim, it is an example of use, for polylines...  :-)

Code: [Select]
(setq e (entsel "\n Specify a polyline, in the necessary arc segment...")
      b (cdr
         (nth
          (fix
           (vlax-curve-getParamAtPoint (car e) (vlax-curve-getClosestPointTo (car e) (cadr e)))
          ) ;_  fix
          (vl-remove-if-not (function (lambda (x) (= (car x) 42))) (entget (car e)))
         ) ;_  nth
        ) ;_  cdr
      d (fix
         (vlax-curve-getParamAtPoint (car e) (vlax-curve-getClosestPointTo (car e) (cadr e)))
        ) ;_  fix
      d (distance (vlax-curve-getPointAtParam (car e) d)
                  (vlax-curve-getPointAtParam (car e) (1+ d))
        ) ;_  distance
) ;_  setq
(test b d)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: (Challenge) calculate arc length
« Reply #18 on: May 15, 2007, 01:59:36 PM »
Thanks for the clarification Evgeniy.  I don't really understand it, but that is because my trig skills are not up to par.  I will have to teach myself somemore stuff when I get a chance to.  :-D
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: (Challenge) calculate arc length
« Reply #19 on: May 15, 2007, 02:41:21 PM »
Haber que les parece esta funcion :)

Code: [Select]
(defun arcLength  (bulge chord)
  (setq h (* chord (/ bulge 2.0))
r (/ (+ (expt (/ chord 2.0) 2) (expt h 2.0)) (* 2 h)))
  (* r 4.0 (atan bulge)))

test:
Quote
(ARCLENGTH 0.5 100.)
(ARCLENGTH -1.5 100.)
(ARCLENGTH 30. 100.)
(ARCLENGTH -0.1 100.)


115.912
212.939
4617.55
100.665

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: (Challenge) calculate arc length
« Reply #20 on: May 15, 2007, 03:06:15 PM »
Hi,

Here's a trig way

Code: [Select]
(defun test (b d)
  ((lambda (a)
     (* (/ d (sin a)) a)
   )
    (* 2 (atan b))
  )
)

It seems to run faster with a setq

Code: [Select]
(defun test (b d / a)
  (setq a (* 2 (atan b)))
  (* (/ d (sin a)) a)
)
« Last Edit: May 15, 2007, 03:49:36 PM by gile »
Speaking English as a French Frog

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) calculate arc length
« Reply #21 on: May 15, 2007, 03:58:31 PM »
Hi,

Here's a trig way


Hi gile
Very good way!  :-)


Here's my way...
Code: [Select]
(defun lw_arc_Len (b d)
                 ;|
by ElpanovEvgeniy
Find length of an arc
Before start, it is obligatory to check up not a zero tangent!
   b = a tangent of a quarter of a central angle of an arc
   d = it is long chords of a segment
   |;
 (* (atan b) d (+ b (/1. b)))
); _ defun