86

What a good question! I'm surprised that no-one's asked this before ... There are two pieces to the puzzle here: getting the end circles right, and deciding where to draw the edges. The first turns out to actually be easy - if you know what to look for in the TikZ manual. The second takes a little bit of maths, but not too much. Let's deal with the ...


36

One option using TikZ: The code: \documentclass{article} \usepackage{tikz} \usetikzlibrary{intersections} \begin{document} \begin{tikzpicture}[xscale=0.8,>=latex] % axis \draw[ultra thick,->] (0.3,-3.5) -- +(0,7) node[yshift=5pt] {$\mu$}; \draw[ultra thick,->] (0.3,-3.5) -- +(220:4) node[yshift=-5pt,xshift=-5pt] {$p$}; \draw[ultra thick,->] (...


31

Well, no prizes for speed (not just because there is some duplication of calculations: TikZ is slow for this kind of stuff), but this shows one way of doing it. I expect asymptote/PSTricks could do it quicker, but I don't see any other way of doing it in TikZ. The maths is straightforward "back-of-the-envelope" trigonometry (in this case literally). The ...


31

Here is some code I made some time ago (uses gnuplot). You probably adapt it to draw simpler cylinders... \tikzset{math3d/.style= {x={(1cm,0cm)}, y={(0.353cm,0.353cm)}, z={(0cm,1cm)}}} \begin{tikzpicture}[math3d] \newcommand{\n}{11} \newcommand{\h}{2} \newcommand{\rl}{2} \newcommand{\rh}{1} \path[draw,fill=white] plot[domain=0:2*pi,...


25

It is much easier to just draw everything in the correct order instead of using 3d coordinates (or layers). The crucial part is the last dozen of lines: \documentclass{standalone} \usepackage{xifthen} \usepackage{tikz} \usetikzlibrary{math} \begin{document} \begin{tikzpicture} \newdimen\r \newdimen\R \newcount\n \tikzmath{ \n = 19; ...


22

Here's an alternative using Asymptote. It fulfills some version of most of your requests; for instance, the colors are defined in the preamble (but in Asymptote code rather than TeX code, so you might need to define TeX versions separately). % To run: pdflatex --shell-escape filename.tex \documentclass[margin=10pt,convert]{standalone} \usepackage{...


20

Using Asymptote. The surface $\beta$ has an element of randomness to it; to see other possibilities, change the integer in the srand(int); command. The routine to compute the intersection of the two Bezier patches is one I designed for this scenario; it will not work more generally. Here's the Asymptote code: settings.outformat="png"; settings.render=16; ...


19

You can copy-and-paste LaTeX directly from a Mathematica notebook: It is assumed the content is math-related, so non-math functions are set using \text (requires amsmath).


18

Asymptote solution. It uses a function (from the Wiki) to calculate the curve of intersection. Adjust the placement of the circles as needed. s.asy: size(300,300); size3(300,300,300); import graph3; currentprojection=orthographic(-5,-4,2,center=true); guide3 sphere_x_cyl(real a, real r, real R, int n=10){ // return a closed curve of the Sphere–cylinder ...


18

You can use object=fusion to merge all the spheres to a single object. For that you must also set the option solidmemory: \documentclass[11pt]{standalone} \usepackage[utf8]{inputenc} \usepackage{pstricks,pst-solides3d} \begin{document} \begin{pspicture}(-6,-6)(6,6) \psset{viewpoint=100 100 100,Decran=150} \axesIIID[showOrigin=true,mathLabel=false,...


18

Using the assumption that cross-sections behave as rigid bodies: \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.12} \begin{document} \begin{tikzpicture}[ declare function={squarex(\t) = (\t < 0.25) ? 1 : ( (\t < 0.5) ? (1 - (\t-0.25) * 8) : ( (\t < 0.75) ? -1 : (-1 + (\t - 0.75) * 8) ...


17

This is one possibility via tikz-3dplot Code \documentclass{article} \usepackage{tikz} \usepackage{tikz-3dplot} \usetikzlibrary{shapes,calc,positioning} \tdplotsetmaincoords{70}{120} \begin{document} \begin{tikzpicture}[scale=2, tdplot_main_coords,axis/.style={->,dashed},thick] % -- remove these 3 lines if no axis is preferred \draw[axis] (-4, 0, 0) --...


15

Would you possibly mean something like the following picture? It's quite easy once you understand the basic limitation of arc: it only works on 2D planes. This means that if you simply define a 3rd coordinate system that lies perpendicular to the second and is aligned in a way that the points of x'+alpha0 and z' are coincident with the plane, you will be ...


15

This exploits that coordinates are global. Even though we draw a new picture in each frame, the coordinates A-\Z and B-Z are still known. And it is arguably simpler to draw the rectangle in the yz plane, and to use rotated coordinates. \documentclass[border=2mm,12pt,tikz]{standalone} \usepackage{tikz-3dplot} \begin{document} \pgfmathsetmacro{\myr}{3} ...


14

Here are the first and the last. The ball takes some more time: Edit Improved the drawing of the axis, which is not covered and added third sketch Edit 2 Changed the intersection point with the sphere and plane drawing for a more beautiful output. Corners are now calculated with the help of analytical geometry, \documentclass[tikz,border=3mm]{standalone}...


14

It is always hard to get answers to questions on the form "draw this for me" without showing any effort your self. Next time try to start a solution and add a MWE to your question, then you have much higher chance of getting someone to dig into your problem. Here I guess the problem is the equator, where you can use \arc with different x- and y-radius. \...


14

Here is one way to do it which adapts the code you were already using to draw the cylinders (i.e. using ellipses). This method uses the intersections library to calculate the intersection point of a line drawn radially out from the centre of the ellipse to the edge of the ellipse. \documentclass[tikz,margin=0.5cm]{standalone} \usetikzlibrary{intersections}...


12

A pure tikz-3dplot solution is based on the macro tdplotsetthetaplanecoords and tdplotdrawarc. At first, the tdplotdrawarc macro draws an arc in the x-y plane. The tdplotsetthetaplanecoords(\phi) will let you choose a plane based on the z-axis having a phi angle with the z-y plane. Be careful, once in the theta plane, I don't know how to get back to the x-...


12

Here's a way of doing this using PGFPlots: \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[hide axis, axis equal, samples=15] \foreach \posx/\posy in {0/-0.1, 0.6/0.1, 0.6/-0.4, 0.1/-0.7}{ \addplot3 [red, thick, domain=0:360, samples=20] ( {cos(x)*0.2+\posx}, {sin(x)*0.2+\posy}, {0} ...


12

Here's a macro \tdseteulerxyz that sets the Euler matrix to use an XYZ (yaw-pitch-roll) order for the rotations. The matrix is taken from Wikipedia, where you can also find the matrices for the other rotation orders. Note that this is the reverse of how tikz-3dplot normally uses its arguments to \tdplotsetrotatedcoords; the first argument is roll and the ...


12

\documentclass[10pt,a4paper]{article} \usepackage{pgfplots} \pgfplotsset{compat=1.3} \begin{document} \begin{tikzpicture} \begin{axis}[ %hide axis, xlabel=$x$,ylabel=$y$, mesh/interior colormap name=hot, colormap/blackwhite, ] \addplot3[domain=-3:3,surf,samples=41] {x*y*sin(deg(x^2+y^2))}; \end{axis} \end{tikzpicture} \end{document}


11

I think the lines in black (or magenta) are the ones you are looking for: To compute the Cartesian coordinates I use \pgfmathsetmacro. Notes: I don't know if one can easily extract the x, y, and z coordinates directly from setting of \tdplotsetcoord so I had to resort to defining them separately. Code: \documentclass[tikz]{standalone} \usepackage{tikz-...


11

This alternative provides Cartesian coordinates, serving as a complement to Perter Grill's solution. Code \documentclass[tikz,border=1cm]{standalone} \usepackage{tikz-3dplot} \begin{document} \tdplotsetmaincoords{60}{120} \begin{tikzpicture} [scale=3, tdplot_main_coords, axis/.style={->,blue,thick}, vector/.style={-stealth,red,very thick}, vector ...


Only top voted, non community-wiki answers of a minimum length are eligible