Jump to content

Calculate x,y/x,y,z for a 2d/3d curve


Recommended Posts

Posted
9 hours ago, lrm said:

If you are concerned about the speed of execution one thing you could easily change is to remove the write statements and instead store the results in an array and then do one write to a file at the end of the program.  The jumping between lisp execution and file writing is time consuming. It's better to limit how often that is done.

 

It would be interesting to see the average of how many iterations are needed to converge to a solution in the bisection loop for each value of x. 

 

Usually a Newton Raphson numerical algorithm will converge faster than the simple bisection method but I don't see how to use it efficiently in this case. 

Thanks Irm,

Here's my code, where I used the Newton Raphson method, execution time for 10000 points = 0.0 seconds  and for bisection method time = 10 seconds.

I use curves C(x(t), y(t), z(t)), where x(t) is  strictly increasing function.

Also, thanks marko-ribar, where I replaced (setq curveObj (vlax-ename-> vla-object ent))  with (setq curveObj ent).

In conclusion, the code is very fast.

; return time in seconds
(defun timer ( / s )
  (setq s (getvar "DATE"))
  (* 86400.0 (- s (fix s)))
)

(defun c:fx ( / c c0 curve-obj delim dx eps fil name_file nz p param_e param_s pe ps p_deriv t1 u x0 x1 x2 xf xff xi )
;
;  Input
;----------------------------------------------------------------------------------------------------------
  (setq
          eps 0.000001
        delim " "
           nz 6    ; number of decimals
  )
  (if (null *r*)
    (setq *r* 1.0)
  )
  (initget 6)
  (if (setq dx (getreal (strcat "\nIncrement dx < " (rtos *r*) " >: ")))
      (setq *r* (* 1.0 dx))
      (setq dx (* 1.0 *r*))
  )
  (setq
         name_file (getstring "\nFile out : ")
         curve-Obj (car (entsel))
               fil (open (strcat (getvar "DWGPREFIX") name_file) "w")
           param_s (vlax-curve-getStartParam curve-Obj)
           param_e (vlax-curve-getEndParam   curve-Obj)
                ps (vlax-curve-getStartPoint curve-Obj)
                pe (vlax-curve-getEndPoint   curve-Obj)
                x1 (car ps)
                x2 (car pe)
  )
  (setq xi (getstring "\nEnter(for ends of curve) or val. xi = "))
  (if (= xi "")
    (if (< x1 x2)
      (setq xi x1  xf x2)
      (setq xi x2  xf x1)
    )
    (setq xi (atof xi)  xf (atof (getstring "\nxf = ")))
  )
;    End input
;----------------------------------------------------------------------------------------------------------
  (setq t1 (timer))
  (setq x0 xi xff (+ xf eps))
  (setq 
  	     c0 (* 0.5 (+ param_s param_e))
  	      c c0
  	      u 10000.0
  )
  (while (< x0 xff)
;                   Newton Raphson Method
;-----------------------------------------------------
    (while (> (abs u) eps)
      (setq
                  p (vlax-curve-getPointAtParam curve-Obj c)
            p_deriv (vlax-curve-getFirstDeriv curve-obj c)
                  u (/ (- (car p) x0) (car p_deriv))
                  c (- c u)
      )
    )
;-----------------------------------------------------
    (write-line (strcat (rtos x0 2 nz) delim (rtos (cadr p) 2 nz) delim (rtos (caddr p) 2 nz)) fil)
    (setq x0 (+ x0 dx)  c c0  u 10000.0)
  )
  (close fil)
  (princ "\n")
  (princ (- (timer) t1))
  (princ "\nOK")
  (princ)
)

 

  • Like 1
Posted

I am wondering are those methods any good for HELIX curves ??

Posted
22 minutes ago, marko_ribar said:

I am wondering are those methods any good for HELIX curves ??

 

No, because x=x(t) is not  strictly increasing function, for helix curve H(x(t),y(t),z(t)).

Posted
31 minutes ago, marko_ribar said:

I am wondering are those methods any good for HELIX curves ??

 

Come back, only if x=x(t) is strictly increasing function over the studied range.

Posted

Hi roy437 can you post a dwg it would be interesting to see the different methods how long they take even my dumb method one.

Posted
7 hours ago, BIGAL said:

Hi roy437 can you post a dwg it would be interesting to see the different methods how long they take even my dumb method one.

Hi Bigal,

There is a "scr" file. With dx=0.003 result 10613 points, with Newton Raphson time = 0.0 sec. Computer i7-3770, 16GB ram, win 10.

 

spline
1.929575,0.526062,3
2.929575,0.828203,3.686791
3.929575,1.16478,4.316021
4.929575,1.49978,4.834386
5.929575,1.800282,5.196257
6.929575,2.041652,5.371278
7.929575,2.231827,5.382278
8.929575,2.391255,5.270526
9.929575,2.537813,5.07124
10.929575,2.687656,4.815413
11.929575,2.85593,4.53127
12.929575,3.05736,4.245416
13.929575,3.306661,3.983735
14.929575,3.611157,3.76734
15.929575,3.964756,3.609257
16.929575,4.360148,3.522367
17.929575,4.79007,3.520557
18.929575,5.247164,3.619034
19.929575,5.723369,3.833543
20.929575,6.192307,4.13517
21.929575,6.603904,4.432684
22.929575,6.909234,4.631791
23.929575,7.087666,4.685975
24.929575,7.175662,4.651425
25.929575,7.214014,4.59443
26.929575,7.241124,4.574701
27.929575,7.294542,4.607421
28.929575,7.412062,4.680958
29.929575,7.631974,4.782963
30.929575,7.990371,4.900991
31.929575,8.454167,5.027449
32.929575,8.911867,5.160353
33.767556,9.206093,5.275454


 

Posted (edited)
On 12/15/2019 at 10:19 PM, marko_ribar said:

I am wondering are those methods any good for HELIX curves ??

 

maybe 'stretch' rescale x-direction? something like a wave graph? Just $0.02 idea sorry if not practical 😛

 

helix2.thumb.png.4a81a96401bc044f59a2adfb7479f777.png

 

2D illustration purpose only, it does not present actual scale of wave 'frequency' pattern

Edited by hanhphuc
new img & comments
Posted (edited)

Using roy script even though its a bit slow 10000+ steps still workable did not hit minutes. Might shave a few here and there see images.

 

image.png.b9e0cec2756bf54bfd525c30e4d7c7df.png

 

Used entmake line 

 

image.png.bfa47967c931bf1310984b2b0ce53b9b.png

 

Vla-delete entlast

image.png.12064a8d60cbf83a6b62e78be0f73fd5.png

 

Not worth the time of trying to shave any more off.

 

For fun

image.png.b7b3b136f5c4ad5c92d1b0088fde5e94.png

Edited by BIGAL
Posted
15 hours ago, BIGAL said:

Using roy script even though its a bit slow 10000+ steps still workable did not hit minutes. Might shave a few here and there see images.

 

image.png.b9e0cec2756bf54bfd525c30e4d7c7df.png

 

Used entmake line 

 

image.png.bfa47967c931bf1310984b2b0ce53b9b.png

 

Vla-delete entlast

image.png.12064a8d60cbf83a6b62e78be0f73fd5.png

 

Not worth the time of trying to shave any more off.

 

For fun

image.png.b7b3b136f5c4ad5c92d1b0088fde5e94.png

 

 

Time_Newton_Raphson.JPG.06ad427aeb359809c9982af01b52771b.JPG

 

With Newton-Raphson method.

Posted

Yeah a bit of a difference I always knew the trim method would not be fast. Just did it for the fun.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...