Jump to content

Recommended Posts

Posted (edited)

Command: func (enter)

Function expression y(x):

What is the expression?

It says function expression must be entered with little letter x - not with X.

I enter x.

What about x^2?

What should I type?

x*x, x.x, or x^2?

Function expression z(x):

Why z(x)?

Why two functions, y(x) and z(x)?

The function I need is only one, it is y = f(x) = x^3 + x^2 + x + 1.

It automatically changing view from 2D to the 3D view such as isometric view.

http://s13.postimg.org/6aekr41if/2nd_marco_s_codes.png

 

I've explained you all this, only if someone wants to read carefully...

My function is designed to be 3D, not only 2D, this is why it firstly asks for y(x), and later for z(x)...

If you want only 2D, I've explained... You should enter exactly this :

y(x)=x^3+x^2+x+1 - note that x is small letter not X,

z(x)=0

 

If you want though to use full capability of this code, I suggest that you combine both y(x) and z(x)...

For example :

y(x)=sin(x) - sine curve

z(x)=x - line that is passing through 1st and 3rd quadrant (xOy - plane)... Here as it is defined z(x) it is actually (xOz - plane)

 

So for x=1.0 => y=sin(1.0), z=1.0 ==> point has coordinates (1.0 sin(1.0) 1.0)

for x=-1.0 => y=sin(-1.0), z=-1.0 ==> (-1.0 sin(-1.0) -1.0)

 

As sin function is defined from -1.0 to 1.0 (x=3pi/2; x=pi/2), your graph will be spanned in y direction from -1.0 value to 1.0 value,

and as x function is defined from -~ to +~ (~ - infinity), your graph will be spanned in z direction from -~ to +~, but as you have to define observing segment by picking points on X axis (it is gripped so you know it when viewed from 3D SWISO view) - firstly start point (usually on left portion of X axis) and then end point (right portion of X axis), your 3D graph will be spanned from X coordinate of first point to X coordinate of second in both (xOy) and (xOz) plane z coordinates should be equal to x coordinates ( z(x)=x ), and in y direction it will span as sin function from (-1.0, 1.0)...

 

So after you define functions y(x) and z(x), you only have to pick observing segment of function by picking 2 points on X axis witch is by the way gripped, so you can see where to pick these points...

 

[important note ab cal with sin function : As geomcal takes angles in degrees when calculating sin or cos function, for better look on sin(x), you should type y(x) : sin(r2d(x))

Edited by marko_ribar
Important note ab cal with sin function
  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

  • automaticad

    17

  • marko_ribar

    6

  • irneb

    6

  • LibertyOne

    4

Top Posters In This Topic

Posted Images

Posted
Well, perhaps if you read Lee's explaination correctly. He explicitly stated to change out the variable for f.

You obviously didn't do that. Try that first then come back and give us your results.

 

Which line of Lee's code, where I can change the variable value of f?

Posted

Here - highlighted line :

 

;; Dynamic Function Plotter  -  Lee Mac
(defun c:dynfun ( / f i o p q x )
   (setq f [highlight](lambda ( x ) (+ (* x x x) (* x x) x 1))[/highlight] ;; Function to evaluate
         i 0.1 ;; Increment (i > 0)
   )
   (or (setq o (getpoint "\nSpecify Origin for Function <0,0>: "))
       (setq o '(0.0 0.0 0.0))
   )
   (princ "\nMove cursor to alter x-range...")
   (while (= 5 (car (setq p (grread t 13 0))))
       (redraw)
       (setq x (abs (- (caadr p) (car o)))
             x (- x (rem x i))
             q (mapcar '+ o (list x (f x)))
       )
       (repeat (fix (/ x i 0.5))
           (grdraw q (setq q (mapcar '+ o (list (setq x (- x i)) (f x)))) 3)
       )
   )
   (princ)
)

 

But as I stated in post #13, if you want to obtain graph of function as real ACAD entity, you should use my or Stefan's code...

Lee's code is as it states : Dynamic Function Plotter - when you finish with previewing and type command "regen", plotted vectors of function will disappear...

Posted

I will not use the codes which the graphic is dissappear when zoom in or zoom out or regen.

 

They are the Lee's codes and the Marko's first codes.

 

I will use they codes if they can fix the code so that it will not dissappear when regen, zoom in, and zoom out.

 

I would like to extrude the function.

Posted
I will not use the codes which the graphic is dissappear when zoom in or zoom out or regen.
You did not state that anywhere. Thos code use the temporary display function grdraw. If you want it permanent then it should generate something like a spline object instead.

 

Anyhow, I've done something like this a while back: http://www.theswamp.org/index.php?topic=41681.10

 

It converts any algebraic function into a lisp function (at least it tries to) by converting the math in-fix notation to the Lisp's polish (pre-fix) notation. The latest version is in post #13. For the visualization functions see post #10 in that thread - provides both 2d and 3d versions. If you want to use them, you'll have to add both into one file or load both files.

 

And to pre-empt your requests, those functions are non-command functions. And you send them the inputs as arguments. If you "need" a command, here's a wrapper command which asks for the values and then sends it to the normal lisp function:

(defun c:GraphFX2D (/ formula start stop incr)
 (if (and (setq formula (getstring t "\nEnter the formula: "))
          (setq start (car (getpoint "\nPick start X: ")))
          (setq stop (car (getpoint (list start 0.0 0.0) "\nPick stop X: ")))
          (setq incr (car (getpoint (list start 0.0 0.0) "\nPick increments for X: "))))
   (GraphFX2D formula start stop incr))
 (princ))

Posted
You did not state that anywhere. Thos code use the temporary display function grdraw. If you want it permanent then it should generate something like a spline object instead.

 

Anyhow, I've done something like this a while back: http://www.theswamp.org/index.php?topic=41681.10

 

It converts any algebraic function into a lisp function (at least it tries to) by converting the math in-fix notation to the Lisp's polish (pre-fix) notation. The latest version is in post #13. For the visualization functions see post #10 in that thread - provides both 2d and 3d versions. If you want to use them, you'll have to add both into one file or load both files.

 

And to pre-empt your requests, those functions are non-command functions. And you send them the inputs as arguments. If you "need" a command, here's a wrapper command which asks for the values and then sends it to the normal lisp function:

(defun c:GraphFX2D (/ formula start stop incr)
 (if (and (setq formula (getstring t "\nEnter the formula: "))
          (setq start (car (getpoint "\nPick start X: ")))
          (setq stop (car (getpoint (list start 0.0 0.0) "\nPick stop X: ")))
          (setq incr (car (getpoint (list start 0.0 0.0) "\nPick increments for X: "))))
   (GraphFX2D formula start stop incr))
 (princ))

 

You mean I should combine your code into the other code?

 

I can not do it.

 

Could you do it for me?

Posted
You mean I should combine your code into the other code?

 

I can not do it.

 

Could you do it for me?

Attached, combined all 3 portions into one file. Sample command-line:
Command: GRAPHFX2D

Enter the formula: x^3 + x^2 + x + 1

Pick start X: -2

Pick stop X: 2

Pick increments for X: .01

It creates a spline curve by evaluating the formula you've entered by incrementing the X value by the specified increment to get the Y value at each increment.

 

Note my command-line wrapper was a bit incorrect. I simplified it to just ask for the real values instead of points. Also forgot to add the infix->prefix conversion :ouch:

Graphing.LSP

Posted
Attached, combined all 3 portions into one file. Sample command-line:
Command: GRAPHFX2D

Enter the formula: x^3 + x^2 + x + 1

Pick start X: -2

Pick stop X: 2

Pick increments for X: .01

It creates a spline curve by evaluating the formula you've entered by incrementing the X value by the specified increment to get the Y value at each increment.

 

Note my command-line wrapper was a bit incorrect. I simplified it to just ask for the real values instead of points. Also forgot to add the infix->prefix conversion :ouch:

 

Which portions?

Posted
Which portions?
The infix-to-prefix conversion, the graphical drawing routines from prefix formulas, and the command wrapper to use them all from the command line.
Posted
The infix-to-prefix conversion, the graphical drawing routines from prefix formulas, and the command wrapper to use them all from the command line.

 

Which one is infix, which one is prefix, and which one is the command wrapper?

 

I don't get it.

 

Could you please do it for me?

Posted
Or maybe anyone mind to send me a lisp of

y = 2r (a straight horizontal line, where the r is a variable and its value is a constant)

between the x1 and the x2.

 

The options are:

specify first point (which is the value of the x1),

specify end point (which is the value of the x2).

 

As an example:

 

y = 2*3 (r = 3)

 

or

 

y = 6

 

x1 = 1 and x2 = 17.

 

It's as a straight horizontal line with length of 16 units.

 

Need it as soon as possible.

In this case, using my routine the command-line entry should be:
Command: GRAPHFX2D

Enter the formula: 6

Pick start X: 1

Pick stop X: 17

Pick increments for X: 1

Or if you want to use a variable-constant:

Command: (setq r 3)
3
Command: GRAPHFX2D

Enter the formula: 2*r

Pick start X: 1

Pick stop X: 17

Pick increments for X: 1

Posted
Which one is infix, which one is prefix, and which one is the command wrapper?

 

I don't get it.

 

Could you please do it for me?

Do what? It's already done. I've already added all the functions into that LSP file, just appload it and start the command.

 

Portion 1 (already in the LSP file):

infix = normal algebraic function, e.g. x^3 + x^2 + x + 1 is an infix notated algebraic function

prefix of the same would be (+ (^ x 3) (+ (^ x 2) (+ x 1))) ... which is what my infix->prefix function does.

 

Portion 2 (also already in the LSP file):

Then the graphfx2d evaluates that by setting X's value for each increment: start ... start + incr ... start + 2 * incr ... until start + n * incr > stop. It then get's the y value at each point along x, places that as the vector point of a spline.

 

Portion 3 (again, also in the LSP file):

The c:graphfx2d function simply makes a command which asks you to enter the formula, the start, stop & increment. Then converts the formula to prefix and sends that (together with start, stop & incr) to the graphfx2d function to draw the curve.

Posted
Could you please do it for me?
If you want to do this yourself on other lisps: All LSP files are simply text files. Open them in any text editor, even just NotePad is good enough. Then simply copy (Select & Ctrl+C) from wherever you got the code, paste it (place cursor in file & Ctrl+V) at the end of the file. Save the file, then appload it into AutoCAD. Then call the command(s) or whatever else in that file.
Posted

What about:

 

y = a sin t

x = a cos t

 

Could you please write a lisp for me?

Posted
y = a sin t

x = a cos t

 

Could you please write a lisp for me?

 

No need for LISP.

Use the CIRCLE command to create a circle of radius 'a' centered at the origin.

Posted
No need for LISP.

Use the CIRCLE command to create a circle of radius 'a' centered at the origin.

 

No.

 

I need it and I want to learn lisp.

 

Please recommend me an autolisp of autocad book where I can learn geometric programming.

Posted

 

Start from where?

 

There are so many menus and options.

 

Do you mind to guide me to the point?

 

I need book though.

 

Please recommend me a book of autolisp where I can learn geometric programming for autocad.

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...