Jump to content

Get your Helix here!


CADTutor

Recommended Posts

I copy here a message from fuccaro that I rescued from the old message board. This is so useful that I thought it would be great to kick-off this new AutoLISP board.

 

I send you a short Lisp program to draw a helix. Deleting the line I marked you will get just a helix, but in my opinion, the final line help to put the shape to extrude in right position. For more help, you find me at mfuccaro@hotmail.com

 

Best luck!

 

And here is the program

(defun C:Helix1()
(setq nr 30);segments
(setq fi (/ (* 2 PI) nr) i 0)
(setq r (getreal "Radius of helix "))
(setq p (getreal "elevation "))
(setq old (getvar "osmode"))
(command "3dpoly")
(repeat (+ nr 1) (setq x (* r (sin (* i fi)))
              y (* r (cos (* i fi)))
              z (* i (/ p nr))
      )
      (command (list x y z))
      (setq i (1+ i))
)
(command (list x y (+ z 10)));delete?
(command "")
(setvar "osmode" old)
)

David

Link to comment
Share on other sites

  • 1 month later...
  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

  • fuccaro

    13

  • CADTutor

    8

  • Mr T

    6

  • tlyall

    3

Top Posters In This Topic

Posted Images

I vas announced by e-mail, that the lisp program above works fine only if OSNAP is OFF. Is true, please excuse me, but I simplified too much the program, trying to make it short. After the line

(setq old (getvar 'snapmode'))

please insert this one:

(setvar 'snapmode' 0)

Thanks to Koczka for observations.

Link to comment
Share on other sites

Thank you, Mr T for the link. It's an other approach, to generate surfaces when solids become hard to manipulate. Those are general propose programs, I rewrote the routines in a simple way, for our needs. First, here is a program for draw a helix, or a spiral if elevation (pitch) is set to zero. The number of turns may be real(!) You may set the start and the end radius independently, so conical springs are easy to draw. Negative value is accepted for radius (try this: Rb=10; Rt=-10; elev.=0, turns=2).

I will return with an other program to extrude a shape on a helix path, generating a surface. So stay close!

 

(defun C:Helcon()
 (setq segs 20); segments/turn
 (setq spin -1); -1=CW, 1=CCW
 (setq ri (getreal "base radius ") rf (getreal "top radius "))
 (initget (+ 1 4))
 (setq h (getreal "elevation "))
 (initget (+ 1 2 4))
 (setq tu (getreal "turns "))
 (setq old (getvar "osmode"))
 (setvar "cmdecho" 0)  
 (setq fi1 (/ (* 2 PI) segs) i 0)
 (setq points (fix (* tu segs))
   h1 (/ h points) r1 (/ (- rf ri) points)
   s (getpoint "center of base ")
   end (list (car s) (cadr s) (+ h (caddr s))))
 (setvar "osmode" 0 )
 (command "line" s end "")
 (command "chprop" "l" "" "c" 1 "")
 (command "3dpoly")
 (setq i 0)
 (repeat (1+ points)
   (setq fi (* i fi1) h (* i h1) r (+ ri (* i r1)))
   (setq x (* r (cos fi)) y (* spin r (sin fi)))
   (command (list (+ (car s) x) (+ (cadr s) y) (+ (caddr s) h)))
   (setq i (1+ i)))
 (command "")
 (setvar "osmode" old))

Link to comment
Share on other sites

Fuccaro

 

Thanks for the revised lisp file. I just tried it out and it works a treat. I used it to create the path for this extrusion:

 

image5.gif.3485e08712bd06bfea5ffe8899c01432.gif

 

The solid extrusion is faceted because of the increment between points on the 3D Polyline. Do you think it would be possible to allow the user to set the increment?

 

Also, it is possible to spline the resulting helix but AutoCAD won't allow an extrusion along a splined 3D Polyline. Has anyone found a way round this?

Link to comment
Share on other sites

That's easy to change. In the second program line (marked with a comment) setting the number (20) to a higher value the spring will look better. Yes, it's possible to ask the user about a lot of things, like the color, the layer, ... I decided to make programs simple to use. But if you wish, just replace the second line

(setq segs 20); segments/turn

with this one:

(setq segs (getint 'segments?'))

I feel frustrated, I don't have possibility to insert images. The new in this program is the possibility to draw a conical helix, and with the number of turns as real. But in your image is just a simple, ordinary cylindrical helix, with exactly 5 turns.

As I promised, I will be back with an other program, to extrude on a helix path other shapes, not just circles. I must just test it, than the world may have it.

Link to comment
Share on other sites

Draw a horizontal line from (0,0,0) -this will be the axis of the helix. Draw a shape, most convenient as a polyline. The distance of the shape from the axis will give the radius of the helix. Start the program. When you are prompted about the number of points of the profile, enter the number of vertexes of the shape, if the shape is open. If it's a close one, you must enter number of points+1. Show the points in order, like when you draw the polyline. To close the shape, the last point must be identical with the first one. Here is a limit of the 3Dmesh size, if your surface will be incomplete and program ends with the message "Warning! surface is trimmed", try again decreasing the quality or the number of turns.

 

(defun C:helsurf ()
(setq fin (getint "  surface quality? (20...1   1=best)")) 
(setq nr (getint "nr. of points defining the profil?"))
(setq nr (1- nr) tri 0)
(setq oldc (getvar "cmdecho"))
(setvar "cmdecho" 0) 
(setq lpa (list (getpoint "\n1 point?")))
(repeat nr
      (setq lpa (cons (getpoint "next point?") lpa)))
 (setq tu (getreal "\nturns?"))
 (setq xx (* 360 tu))
 (setq xx (1+ (fix (/ xx fin))))
 (if (> xx 255) (setq tri 1))
 (setq xx (if (> xx 255) 255 xx))
 (command "3dmesh" xx (length lpa))
 (setq h (getdist "\n pitch (elevation/turn)"))
 (setq old (getvar "osmode"))
 (setvar "osmode" 0)
 (setq fi 0.0 h (/ h (* 2 pi)))
 (repeat  xx
   (foreach pt lpa
     (setq ya (car pt))
     (setq za (cadr pt))
     (setq z (* za (sin fi)))
     (setq x (+ (* h fi) ya))
      (setq y (* za (cos fi)))
     (command (list x y z)))
 (setq fi (+ fi (/ (* pi fin) 180))))
 (setvar "osmode" old)
 (if (> tri 0) (prompt "\nWarning! surface is trimmed   "))
 (setvar "cmdecho" oldc))

Link to comment
Share on other sites

Yep, that works too...

 

image7.gif.2a60416bb3f01b164b7cdefa6b819140.gif

 

I have just one criticism of this routine. Why not ask the user to select the profile and have the routine work out the number of points and their coordinates? Obviously, you'd have to stipulate that the profile was formed using a polyline but this would avoid potential errors caused by the user entering the wrong number of points etc.

 

Otherwise it works as advertised. Thanks Fuccaro.

Link to comment
Share on other sites

Well, I feel that is enough about helix, -unless if someone will post here interesting special requests and I can help. My intention was (and is) to wrote simple programs, easy to understand and -why not- to use as "skeleton" or part in bigger applications. Thanks to David to quick and useful observations. So, see you in other topics!

P.S.

I have 3 reasons to post a picture here:

1 -To practice posting images (I hope it works).

2 -To show the results of a combination of the last two routines.

3 -To show to David, I didn't missing from school, when lesson about real numbers was (the number of turns is not an integer)

 

Sorry, it don't works. The image is on my computer. If you wish, make me a visit :evil:

 

screw.jpg.38773430194494e48ff95148b0bc548d.jpg

 

(if the image is not here, try this link:

http://fuccaro.netfirms.com/screw.jpg

And the picture is here, thank you David! :D

Link to comment
Share on other sites

  • 2 weeks later...

Hello, people!

I was asked if it's possible to change the sense of the helixes.

The routine named HELCON has a line

(setq spin -1); -1=CW, 1=CCW

If you change it -with any text editor- like this

(setq spin 1); -1=CW, 1=CCW

you will reverse the sense. But I think is more easy to draw the helix as it is, and apply a mirror with the AutoCAD command. If somebody draw more helixes at a time, with different senses, try to change the mentioned line with this one

(setq spin (getint 'spin? -1=CW, 1=CCW'))

You will be asked about the spin for every helix.

In the routines HELSURF and HELIX1 you may find the line

(command (list x y z))

and replace

z with (- 0 z)

Happy rendering!

Link to comment
Share on other sites

  • 1 month later...

Here's a link sent to me by Michael Beall. Look at the November Lisp of the Month.

 

Hey, you asked about the helix...

 

Sometime during January I plan to pull all this helix stuff together and present it as a special tutorial (thanks fuccaro).

Link to comment
Share on other sites

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