_$ (infix->prefix '(5 ^ 6 / 3 + max ((A / 5) 2) * (8 + 7 * min (4 (9 + 5)) - 5)))
(+ (/ (^ 5 6) 3) (* (MAX (/ A 5) 2) (+ 8 (- (* 7 (MIN 4 (+ 9 5))) 5))))
; error: Automation Error. Problem in loading application
What version of SC are you using?Even after I've installed this: http://www.microsoft.com/en-us/download/confirmation.aspx?id=1949
I'm getting an error:Code: [Select]; error: Automation Error. Problem in loading application
What version of SC are you using?
Anyhow, what's the difference between doing it that way and using the geomcal.arx and its cal function? Actually, it means you can't have variable references inside the formula as you can with the cal function. And it's a bit slow in comparison to eval.
Probably no difference, but I just wanted to offer an alternative way to evaluate user-readable mathematical expressions, without the hard work of performing the conversion to LISP.Thanks! It is nice to see other ways, it's just that I actually wanted to perform this as fast as possible.
_$ (infix->prefix '(sin (5) ^ cos (6) / 3 + max ((A / 5) 2) * (abs 8 + 7 * min (4 (9 + 5)) - atan (5))))
(SIN 5 + (/ (^ COS 6) 3) (* (MAX (/ A 5) 2) (ABS 8 + 7 * MIN (4 (+ 9 5)) - ATAN 5)))
That's just plain WRONG! Will have to do some debugging :-[
_$ (infix->prefix '(sin (5) ^ cos (6) / 3 + max ((A / 5) 2) * (abs 8 + 7 * min (4 (9 + 5)) - atan (5))))
(^ (SIN 5) (/ (COS 6) (+ 3 (* (MAX (/ A 5) 2) (+ (ABS 8) (- (* 7 (MIN 4 (+ 9 5))) (ATAN 5)))))))
Slightly closer, though that exponent betwee sin(5) ^ cos(6) seems to go haywire! Something screws up the operator precedence.
Command: (infix->prefix '(1+2-3))Srr, i didn't put spaces. Srr ^^
1+2-3
_$ (infix->prefix '(sin (5) ^ cos (1.23423478754359045098) / -3 + max ((A / 5) 2) * (abs 8 + 7 * min (4 (9 + 5)) - atan (5))))
(+ (/ (^ (SIN 5) (COS 1.23423)) -3) (* (MAX (/ A 5) 2) (+ (ABS 8) (- (* 7 (MIN 4 (+ 9 5))) (ATAN 5)))))
_$ (infix->prefix "sin(5)^cos(1.23423478754359045098)/-3+max((A/5)2)*(abs 8+7*min(4(9+5))-atan(5))")
(+ (/ (^ (SIN 5) (COS 1.23423)) -3) (* (MAX (/ A 5) 2) (+ (ABS 8) (- (* 7 (MIN 4 (+ 9 5))) (ATAN 5)))))
(vl-load-com)
;;; Draw a spline along the points defined by evaluating the formula,
;;; incrementing X by a factor from startpoint to endpoint.
;;; forumla = Prefix (lisp-like) list to be evaluated. Only allowed
;;; X as a variable
;;; start = Starting value for X
;;; stop = End value for X
;;; increment = A number to increment X by at each step
(defun GraphFX2D (formula start stop increment / x lst pt1 pt2 array spline t1 t2 n)
(setq x stop
pt2 (list x (eval formula) 0.)
x start
pt1 (list x (eval formula) 0.)
x (- start increment)
t1 (mapcar '- pt1 (list x (eval formula) 0.))
x (+ stop increment)
t2 (mapcar '- (list x (eval formula) 0.) pt2)
x start
n 0)
(while (< (setq x (+ x increment)) stop) (setq lst (append lst (list x (eval formula) 0.))))
(setq array (vlax-make-safearray vlax-vbdouble (cons 0 (+ 5 (length lst)))))
(vlax-safearray-fill array (append pt1 lst pt2))
(setq spline (vla-AddSpline (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-make-variant array) (vlax-3d-point t1) (vlax-3d-point t2)))
(vla-put-FitTolerance spline 0.)
(vla-put-Degree2 spline 3)
(vla-put-SplineFrame spline 1)
(vla-put-SplineMethod spline 0)
(while (< (setq x (+ x increment)) stop) (vla-SetFitpoint spline (setq n (1+ n)) (vlax-3d-point x (eval formula) 0.)))
spline)
;;; Draw a 3d Mesh along the points defined by evaluating the formula,
;;; incrementing X & Y by a factor from startpoint to endpoint.
;;; forumla = Prefix (lisp-like) list to be evaluated. Only allowed
;;; X and Y as variables
;;; Xstart = Starting value for X
;;; Xstop = End value for X
;;; Xincr = A number to increment X by at each step
;;; Ystart = Starting value for Y
;;; Ystop = End value for Y
;;; Yincr = A number to increment Y by at each step
(defun GraphFX3D (formula Xstart Xstop Xincr Ystart Ystop Yincr / x y m n lst array)
(setq m 0 y (- Ystart Yincr) Xstop (+ Xstop Xincr) Ystop (+ Ystop Yincr))
(while (< (setq y (+ y Yincr)) Ystop)
(setq m (1+ m) x (- Xstart Xincr))
(while (< (setq x (+ x Xincr)) Xstop)
(setq lst (cons (eval formula) (cons y (cons x lst)))))
(if (not n) (setq n (length lst))))
(setq array (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length lst)))))
(vlax-safearray-fill array (reverse lst))
(vla-Add3dMesh (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))) m n (vlax-make-variant array)))
Command: (infix->prefix "sin(pi/2)")
; error: bad argument type: listp $PLACEHOLDER0
Command: (infix->prefix "sin(pi/2)+0")
(+ (SIN PI / 2) 0)
Command: (infix->prefix "sin((pi/2))")
; error: bad argument type: listp $PLACEHOLDER0
Command: (infix->prefix "sin((pi/2))+0")
(+ (SIN (/ PI 2)) 0)
Command: (infix->prefix "sqrt(2)")
; error: bad argument type: listp $PLACEHOLDER0
_$ (infix->prefix "sin((pi/2))")
(SIN (/ PI 2))
_$ (infix->prefix "sqrt(2)")
(SQRT 2)
_$ (infix->prefix "sin(pi/2)+0")
(+ (SIN (/ PI 2)) 0)
_$ (infix->prefix "sin(2^3/6)")
(SIN (/ (^ 2 3) 6))
_$ (infix->prefix "-A*S")
(* -A S)
The problem is that -A might be a symbol instead of meaning (- A)._$ (infix->prefix "0-A*S")
(- 0 (* A S))
Or forcing it:_$ (infix->prefix "(- A)*S")
(* (- A) S)
(setq infix "2*x^2+5*x+4")
(setq prefix (infix->prefix infix)) ;(+ (* 2 (^ X 2)) (+ (* 5 X) 4))
(setq x 5)
(eval prefix) ;79
(eval (infix->prefix infix)) ;79
(cal infix) ;79.0
(quickbench '((cal infix) (eval (infix->prefix infix)) (eval prefix)))
Benchmarking ... done for 16384 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(EVAL PREFIX) 16384 1388 1388 5.40
(cal INFIX) 4096 1498 5992 1.25
(EVAL (INFIX->PREFIX INFIX)) 4096 1873 7492 1.00
--------------------------------------------------------------------------------
So it's only slightly slower than sending the infix string to the GeoCal.ARX cal function, but once you've converted the infix string to a prefix list you need only apply the eval function on that - and this is a lot faster than cal.