TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}]
    \addplot3[surf,shader=flat,
      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))});
   \addplot3[surf,shader=flat,
     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:
solid of revolution

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: question

share|improve this question
    
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
up vote 1 down vote accepted

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}]
    \addplot3[surf,shader=flat,
      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))});
   \addplot3[surf,shader=flat,
     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

enter image description here


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,
    ]
    \addplot3[surf,shader=flat,
      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))});
   \addplot3[surf,shader=flat,
     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

enter image description here

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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