roy437 Posted December 15, 2019 Author Posted December 15, 2019 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) ) 1 Quote
marko_ribar Posted December 15, 2019 Posted December 15, 2019 I am wondering are those methods any good for HELIX curves ?? Quote
roy437 Posted December 15, 2019 Author Posted December 15, 2019 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)). Quote
roy437 Posted December 15, 2019 Author Posted December 15, 2019 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. Quote
BIGAL Posted December 15, 2019 Posted December 15, 2019 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. Quote
roy437 Posted December 16, 2019 Author Posted December 16, 2019 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 Quote
hanhphuc Posted December 16, 2019 Posted December 16, 2019 (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 2D illustration purpose only, it does not present actual scale of wave 'frequency' pattern Edited December 16, 2019 by hanhphuc new img & comments Quote
BIGAL Posted December 17, 2019 Posted December 17, 2019 (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. Used entmake line Vla-delete entlast Not worth the time of trying to shave any more off. For fun Edited December 17, 2019 by BIGAL Quote
roy437 Posted December 17, 2019 Author Posted December 17, 2019 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. Used entmake line Vla-delete entlast Not worth the time of trying to shave any more off. For fun With Newton-Raphson method. Quote
BIGAL Posted December 17, 2019 Posted December 17, 2019 Yeah a bit of a difference I always knew the trim method would not be fast. Just did it for the fun. Quote
Recommended Posts
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.