2

I would like to draw a real screw like in image below. Any codes in tikz, asymptote or pstricks are welcomed!

screw1 In order do not confuse with my linked question about laser who as well is based on helix I would like to add a note: I do need Corkscrew in order to predict the direction of the magnetic field lines around a straight conductor through which a steady electric current is flowing.

enter image description hereenter image description here

and my attempts do not correspond to reality screw2

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings,decorations.pathmorphing,arrows.meta}
\begin{document}
\begin{tikzpicture}[line cap=round, line join=round]
\draw [line width=0.2mm,double=gray!70,decorate, decoration={zigzag,pre length=0.1cm,post
length=0.1cm,segment length=6},line join=round](0,-.75)  -> (1,-.75);
\draw [line width=0.1mm,double=gray!70,decorate, decoration={coil,pre length=0.1cm,post
length=0.1cm,segment length=2,amplitude=1mm},line join=round](0,-1.25)  ->   (1,-1.25); 
\draw [thick,double=gray!70,decorate, decoration={snake,pre length=0.1cm,post
length=0.1cm,segment length=6},line join=round](0,-1.75)  -> (1,-1.75);    
\end{tikzpicture}
\end{document}

or maybe Reproducing image of a spiral using TikZ

screw3 please any ideas?

  • This could help parametric plot 3D, helix and astroidal sphere though I'm not sure TikZ is the right tool for this. – Rico Jan 2 '16 at 14:02
  • Yes, something similar, but I prefer in tikz – Andrei Jan 2 '16 at 14:09
  • 1
    Your linked question should be the way to go, since all the answers there define a helix. – Mike Renfro Jan 2 '16 at 15:11
  • 1
    I'm so disappointed by your edit: I thought you planned to build a laser enhanced corkscrew that would blast the cork with a red lightsaber – David Carlisle Jan 2 '16 at 17:36
  • I'm glad that now you got it! – Andrei Jan 2 '16 at 17:43
10

With the help of the stl file reader in asymptote and an stl file rendering a corkscrew, you can get this:

enter image description here

settings.outformat = "png";
settings.render = 8;
import three;
size(20cm);

struct stringpointer { string s; }

surface readstlfile(string filename, stringpointer returnsurfacename=null, bool ascii=true) {
  assert(ascii, "Reading binary stl files not implemented.");
  file stlfile = input(filename).word();  // Set up a file to read whitespace-delimited items.
  string nextword;
  real x, y, z;

  nextword = stlfile;  // Reading from a file is done by assignment in Asymptote.
  assert(nextword == "solid", filename + " is not a well-formed stl file.");

  string name = stlfile;
  if (returnsurfacename != null) returnsurfacename.s = name;

  surface toreturn;

  while (!eof(stlfile)) {
    nextword = stlfile;
    if (nextword == "endsolid") break;
    else if (nextword == "facet") {

      nextword = stlfile;
      assert(nextword == "normal");

      x = stlfile; y = stlfile; z = stlfile;
      triple normal = (x, y, z);

      nextword = stlfile; assert(nextword == "outer");
      nextword = stlfile; assert(nextword == "loop");
      triple[] vertices = new triple[3];
      for (int i = 0; i < 3; ++i) {
    nextword = stlfile; assert(nextword == "vertex");
    x = stlfile; y = stlfile; z = stlfile;
    vertices[i] = (x,y,z);
      }
      nextword = stlfile; assert(nextword == "endloop");
      nextword = stlfile; assert(nextword == "endfacet");

      patch triangle = patch(vertices[0] -- vertices[1] -- vertices[2] -- cycle);
      triangle.normals = array(4, value=normal);
      toreturn.s.push(triangle);

    } else assert(false, filename + " is not a well-formed stl file.");
  }
  assert(nextword == "endsolid", filename + " does not end correctly.");
  nextword = stlfile;
  assert(nextword == name, filename + " does not end with the solid's correct name " + name);
  return toreturn;
}

currentprojection = perspective(-30, 10, 60);
surface corkscrew = readstlfile("Corkscrew1.stl");
draw(corkscrew, blue);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.