# Solid of revolution about arbitrary axis

I'd like to rotate the region between y=cos(x) and y=x^2 - 0.25*pi^2 about the line x=pi. How to do this? So far I have only managed to rotate around the x-axis:

\documentclass[letterpaper]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[view={60}{30}]
samples=20,
color=red, opacity=0.15,
domain=-0.5*pi:0.5*pi, y domain=0:2*pi,
z buffer=sort]
({x * cos(deg(y))}, {x * sin(deg(y)) }, {cos(deg(x))});
samples=20,
color=red, opacity=0.15,
domain=-0.5*pi:0.5*pi, y domain=0:2*pi,
z buffer=sort]
({x * cos(deg(y))}, {x * sin(deg(y)) }, {x*x - 0.25*pi^2});
\end{axis}
\end{tikzpicture}

\end{document}


Which produces: However, the solid should be more of a donut shape.

Edit: To clarify, I wish to produce a graphic of the solid that this rotation will generate: • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Adam Liter Jul 27 '14 at 23:04
• Revolution about an arbitrary axis sounds more like you need to look up how a rotation matrix looks like in 3D. – Turion Jul 30 '14 at 15:04
• Also, how is x=pi a line? It's a plane, I'd say. – Turion Jul 30 '14 at 15:06
• @Turion That rotation matrix stuff looks complicated. Even if I understood the mathematical basis behind it (which I probably could if I spent some time on it), I still wouldn't know how to implement it in tikz\LaTex. Also, from my problem set, "revolved around the line x = pi". The original question was not presented in an x,y,z coordinate system, I only introduced x,y,z in an attempt to plot the solid of revolution. – thejmazz Jul 30 '14 at 15:44
• @thejmazz, ok, if you're not interested in rotations about arbitrary axes, we should be able to do it without. I still don't understand what is meant by "the line x = pi". To specify a line, you either need two constraints on coordinates (like x=pi, y=0) or a base vector and a direction vector. – Turion Jul 30 '14 at 15:52

You first need to find out how to describe the coordinates in term of your chosen coordinates. I choose x running between the values of the intersections of y=cos(x) and y=x²-0.25π, which is roughly -1.11 to 1.11. The other coordinate (y) then is the angle of rotation. If you then express the three kartesian components in term of these variables, you get:

• x' = (π-x)*cos(y)+π
• y' = cos(x) or y = x²-0.25π
• z' = (π-x)*sin(y)

This you then can plot.

## Code

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}
\begin{axis}[view={60}{30}]
samples=20,
color=red, opacity=0.15,
domain=-1.11:1.11, y domain=0:2*pi,
z buffer=sort
]
({(pi-x)*cos(deg(y))+pi}, {cos(deg(x))}, {(pi-x)*sin(deg(y))});
samples=20,
color=blue, opacity=0.15,
domain=-1.11:1.11, y domain=0:2*pi,
z buffer=sort]
({(pi-x)*cos(deg(y))+pi}, {x*x-0.25*pi}, {(pi-x)*sin(deg(y))});
\end{axis}
\end{tikzpicture}

\end{document}


## Output Edit 1: If you want to see the "donut" shape clearer, you can use make all axes scale the same, with the unit vector ratio option:

## Code

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}

\begin{tikzpicture}
\begin{axis}
[   view={45}{20},
unit vector ratio=1 1 1,
xmin=-2, xmax=8,
ymin=-3, ymax=2,
zmin=-5, zmax=5,
width=15cm,
]
samples=20,
color=red, opacity=0.15,
domain=-1.11:1.11, y domain=0:2*pi,
z buffer=sort,
]
({(pi-x)*cos(deg(y))+pi}, {cos(deg(x))}, {(pi-x)*sin(deg(y))});
samples=20,
color=red, opacity=0.15,
domain=-1.11:1.11, y domain=0:2*pi,
z buffer=sort]
({(pi-x)*cos(deg(y))+pi}, {x*x-0.25*pi}, {(pi-x)*sin(deg(y))});
\end{axis}
\end{tikzpicture}

\end{document}


## Output • That's awesome! This question was quite old (and I've long since handed in the assignment), but thanks for the answer! Definitely play around with this in the future :) – thejmazz Nov 7 '15 at 18:54
• @thejmazz: I'm glad you like it. It was quite fun to solve this! – Tom Bombadil Nov 7 '15 at 21:48