Equation based surface using 3DPLOT

Equation based surface using 3DPLOT

Anonymous
Not applicable
2,210 Views
17 Replies
Message 1 of 18

Equation based surface using 3DPLOT

Anonymous
Not applicable

Hello all, I am trying to create a custom surface LISP for the 3DPLOT utility, specifically a Klein Bottle. Here is a link to there website. The equation is  Klein bottle.PNG

 

and the surface should look like this (more or less).Klein Bottle.PNG.

 

Even if some one could help me to at least write the equations in LISP form, I wold greatly appreciate that! 

 

If it helps I'm currently using AutoCAD 2013 and 2015.

 

Thank you in advance.

     -Ryan

 

0 Likes
2,211 Views
17 Replies
Replies (17)
Message 2 of 18

hgasty1001
Advisor
Advisor

Hi,

 

Not sure, but try this:

 

(defun KleinX(u v)
(* (cos u)(+ (* cos (/ u 2) (+ (sqrt 2) (cos v))) (* (sin (/ u 2)) (sin u) (sin v)))
)

(defun KleinY(u v)
(* (cos u)(+ (* sin (/ u 2) (+ (sqrt 2) (cos v))) (* (sin (/ u 2)) (sin u) (sin v))))
)

(defun KleinZ(u v)
(- (* (cos (/ u 2)) (sin v) (cos v)) (* sin (/ u 2) (+ (sqrt 2) (cos v))))
)

(defun KelinBottle(u v)
(list (KleinX u v) (KleinY u v) (KleinZ u v))
)
;;(3DPlot functionName startU endU stepU startV endV stepV)
(3DPlot KleinBottle 0 (* 2 pi) (/ (* 2 pi) 360) 0 (* 2 pi) (/ (* 2 pi) 360))

 

Gaston Nunez

0 Likes
Message 3 of 18

Anonymous
Not applicable

Thank you!! I'll give it a shot and let you know if it works.

0 Likes
Message 4 of 18

Anonymous
Not applicable
Nope didn't work... Here is a snip of the command dialog box when i insert the lisp.
0 Likes
Message 5 of 18

Anonymous
Not applicable

klein error.PNG

0 Likes
Message 6 of 18

hgasty1001
Advisor
Advisor

Hi,

 

You only need the "C:xxx" with lisp implemented commands (that's why the "C:", C as Command), if you need to call commands as  functions, you need to call it this way: (C:xxx) without parameters, as lisp implemented commands doesn't support parameters (arguments). So just copy the text from my post to the command line and see if it works calling the function exactly as it was posted:

 

(3DPlot KleinBottle 0 (* 2 pi) (/ (* 2 pi) 360) 0 (* 2 pi) (/ (* 2 pi) 360)))

 

If does, then you can implement a command like this:

 

(defun C:KB()(3DPlot KleinBottle 0 (* 2 pi) (/ (* 2 pi) 360) 0 (* 2 pi) (/ (* 2 pi) 360)))

 

And just type KB at the command prompt.

 

Gaston Nunez

0 Likes
Message 7 of 18

Anonymous
Not applicable

I had tried that originally but it didnt work. It seems to want more in formation. in order to end it i have to imput a para ")". here are some more sinps. 

 

Thank you very much for the help!klein error.PNGklein error2.PNGklein error3.PNG

0 Likes
Message 8 of 18

hgasty1001
Advisor
Advisor

Hi,

 

Sorry the code was bad formated and had a lot of errors, this should work:

 

(defun KleinX(u v)
(* (cos u)(+ (* (cos (/ u 2)) (+ (sqrt 2) (cos v))) (* (sin (/ u 2)) (sin u) (sin v))))
)

(defun KleinY(u v)
(* (cos u) (+ (* (sin (/ u 2)) (+ (sqrt 2) (cos v))) (* (sin (/ u 2)) (sin u) (sin v))))
)

(defun KleinZ(u v)
(- (* (cos (/ u 2)) (sin v) (cos v)) (* (sin (/ u 2)) (+ (sqrt 2) (cos v))))
)

(defun KleinBottle(u v)
(list (KleinX u v) (KleinY u v) (KleinZ u v))
)

(defun C:KB()
(3DPlot KleinBottle 0 (* 2 pi) 0.1 0 (* 2 pi) 0.1)
)

 

Gaston Nunez

Message 9 of 18

Anonymous
Not applicable

I was wondering about the step part of that. Didn't get a Klein Bottle but there was a shape! now I just need to do some fine tuning I guess.

 

Could you explain to me how you chose the interval and steps for the last part of the lisp?Klein  Bottle.PNG

0 Likes
Message 10 of 18

hgasty1001
Advisor
Advisor

Hi,

 

I got the same shape,I double checked the equations in the lisp format and are right (I think), so the problem it seems to come from 3DPLOT or the equations, may be someone can jump to this thread an bring some ideas.

 

As for the parameters and step, they come from the mathematical parametrization itself, 0 < u < 2pi; 0 < v < 2pi, the step i first choose, one degree,  was to much for my low spec notebook, so i changed to some more reasonable value.

 

This is a simpler function to play with:

 

(defun KleinB(u v / cu cv cu2 su2 su sv sq)
(setq cu (cos u))
(setq cv (cos v))
(setq cu2 (cos (/ u 2)))
(setq su2 (sin (/ u 2)))
(setq su (sin u))
(setq sv (sin v))
(setq sq (+ (sqrt 2) cv))
(setq KBX (* cu (+ (* cu2 sq) (* su2 sv cv))))
(setq KBY (* su (+ (* cu2 sq) (* su2 sv cv))))
(setq KBZ (+ (* (* -1 su2) sq) (* cu2 sv cv)))
(list KBX KBY KBZ)
)

(defun C:KB2(/ umax vmax stepu stepv)
(setq umax (getreal "\nU Parameter Max Value:"))
(setq vmax (getreal "\nV Parameter Max Value:"))
(setq stepU (getreal "\nU Parameter Step:"))
(setq stepV (getreal "\nV Parameter Step:"))
(3DPlot KleinB 0 umax stepU 0 vmax stepV)
)

 

Some info here: http://mathworld.wolfram.com/KleinBottle.html

 

Gaston Nunez

 

 

Message 11 of 18

hgasty1001
Advisor
Advisor

Hi,

 

It seems that the equations are not the needed ones, this article from Wikipedia bring some light: https://en.wikipedia.org/wiki/Klein_bottle.

 

Gaston Nunez

0 Likes
Message 12 of 18

hgasty1001
Advisor
Advisor

Hi,

 

The attached file have a new version that works. It's not best KB I've seen, but it's one.KB.PNG

 

Gaston Nunez

 

 

0 Likes
Message 13 of 18

Anonymous
Not applicable

Ill look into that link. there could be something wrong with the equation. just seeing how to write it in lisp form is very helpful though.

Capture.PNG

0 Likes
Message 14 of 18

Anonymous
Not applicable

Thats actually where i got the equations from. Smiley Very Happy

0 Likes
Message 15 of 18

hgasty1001
Advisor
Advisor

Hi,

 

I'm no multiplying by 0, the Lisp syntax use the prefix notation, while most other languages use infix (an there exist the postfix notation like the reverse polish notation in the HP calculators) , that means that you put first the operation intended and then the operands or arguments for the mathematical expression:

 

This in the usual way: X + Y translate to (+ X Y) in Lisp notation and syntax, the same for all the others math operations.

 

X - Y -> (- X Y)

X:Y -> (/ X Y)

X*Y -> (* X Y)

 

Each math operator takes 2 or more arguments separated by space, like this:

 

X + Y + Z -> (+ X Y Z)

 

The usual preceding order of evaluation is given by the parenthesis nesting of the operations, like this:

 

X*(Y + Z) -> (* X (+ Y Z)):=(+ (* X Y) (* X Z))

 

Each Lisp function (operators in this case) , not only math operators, must be preceded by a parenthesis that you must close at proper position in order to give the correct math meaning to the expression just like the usual way.

 

There is a lot more on Lisp syntax, but with that you have a start point translating usual (infix) notation to Lisp

 

Gaston Nunez

 

 

Message 16 of 18

Anonymous
Not applicable

okay got it thank you. Ive known about how to write basic math function in lisp form but i kept messing up writing last part of this lisp.

0 Likes
Message 17 of 18

vladimir_michl
Advisor
Advisor

Are you sure the equations are right? Transcripting them to LISP gives the following shape:

 

(defun KleinX(u v)
(* (cos u)(+ (* (cos (/ u 2.0)) (+ (sqrt 2.0) (cos v))) (* (sin (/ u 2.0)) (sin v) (cos v))))
)
(defun KleinY(u v)
(* (sin u) (+ (* (cos (/ u 2.0)) (+ (sqrt 2.0) (cos v))) (* (sin (/ u 2.0)) (sin v) (cos v))))
)
(defun KleinZ(u v)
(- (* (cos (/ u 2.0)) (sin v) (cos v)) (* (sin (/ u 2.0)) (+ (sqrt 2.0) (cos v))))
)
(defun KleinBottle(u v)
(list (KleinX u v) (KleinY u v) (KleinZ u v))
)
(defun C:KB()
(3DPlot KleinBottle 0 (* 2.0 pi) 0.1 0 (* 2.0 pi) 0.1)
)

 

klein.png

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 18 of 18

vladimir_michl
Advisor
Advisor

I have found better equations which work also in 3DPlot. Here is the LISP code and the resulting model:

 

(defun KleinX(u v)
 (if (< v pi)         (* (- 2.5 (* 1.5 (cos v))) (cos u))
  (if (< v (* 2.0 pi)) (* (- 2.5 (* 1.5 (cos v))) (cos u))
   (if (< v (* 3.0 pi)) (- (* (+ 2.0 (cos u)) (cos v)) 2.0)
					      (- (* 2.0 (cos v)) 2.0 (cos u))
 )))
)
(defun KleinY(u v)
 (if (< v pi)         (* (- 2.5 (* 1.5 (cos v))) (sin u))
  (if (< v (* 2.0 pi)) (* (- 2.5 (* 1.5 (cos v))) (sin u))
   (if (< v (* 3.0 pi)) (sin u)
					      (sin u)
 )))
)
(defun KleinZ(u v)
 (if (< v pi)         (* -2.5 (sin v))
  (if (< v (* 2.0 pi)) (- (* 3.0 v)(* 3.0 pi))
   (if (< v (* 3.0 pi)) (+ (* (+ 2.0 (cos u))(sin v)) (* 3.0 pi))
					      (- (* 12.0 pi) (* 3.0 v))
 )))
)
(defun KleinBottle(u v)
(list (KleinX u v) (KleinY u v) (KleinZ u v))
)
(defun C:KB()
(3DPlot KleinBottle 0.0 (* 2.0 pi)(/ pi 36.0) 0.0 (* 4.0 pi) (/ pi 36.0))
)

3D DWG: http://www.cadforum.cz/catalog_en/block.asp?blk=15126

 

kleinbottle.png

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

 

0 Likes