7

From here Using Tikz, is it possible to draw a cube within a sphere? I want to draw a circumsribed sphere with centre at O(1,1,1) and radius R = sqrt(3). I tried

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=1]
\def\R{sqrt(3)}
\coordinate (O) at (1,1,1);
\fill[ball color=cyan!10, opacity=1.0] (O) circle (\R); % 3D lighting effect
 \begin{scope}[tdplot_main_coords, shift={(1,1,1)}, rotate=0]
\path
      coordinate (A) at (0,0,0)
      coordinate (B) at (2,0,0)
      coordinate (C) at (2,2,0)
      coordinate (D) at (0,2,0)
      coordinate (S) at (0,0,2)
      coordinate (O) at (1,1,1);
       \draw[ dashed]
     (A)--(S) (A)--(B)
      (A)--(D)
       ;

\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (B) -- (C) -- cycle;
\draw [fill opacity=0.4,fill=orange!80!blue] (S) -- (C) -- (D) -- cycle;

\foreach \v/\position in {A/below,B/below,C/below,D/right,S/above,O/below} {
    \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\end{tikzpicture}
\end{document} 

My result is not correct. How can I repair it?

enter image description here

4
  • Do you want the sphere circumscribed by the pyramid or the pyramid circumscribed by the sphere? But you also only have a circle outside the scope of the 3D coordinates, so it is using the usual coordinate system and not the transformed ones.
    – cfr
    Commented Jun 5, 2017 at 1:40
  • I want the sphere circumscribed by the pyramid . Commented Jun 5, 2017 at 1:45
  • Sorry about the bad advice earlier. I confused \fill with \node. Commented Jun 6, 2017 at 14:27
  • You can delete comments. The button is hidden at the very end of the line (after edit). Commented Jun 6, 2017 at 15:12

2 Answers 2

5

One can also use tdplot_screen-coords and on background layer. This could prove more useful it you intend to use more than one sphere.

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc,backgrounds}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[tdplot_main_coords]
\path
      coordinate (A) at (0,0,0)
      coordinate (B) at (2,0,0)
      coordinate (C) at (2,2,0)
      coordinate (D) at (0,2,0)
      coordinate (S) at (0,0,2)
      coordinate (O) at (1,1,1);

\draw[ dashed] (A)--(S) (A)--(B) (A)--(D);
\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (B) -- (C) -- cycle;
\draw [fill opacity=0.4,fill=orange!80!blue] (S) -- (C) -- (D) -- cycle;

\foreach \v/\position in {A/below,B/below,C/below,D/right,S/above,O/below} {
    \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}

\draw[dashed] (1,1,0) circle[radius={sqrt(2)}];% circle ABCD

\begin{scope}[tdplot_screen_coords, on background layer]
  \pgfmathsetmacro{\R}{sqrt(3)}%
  \fill[ball color=cyan!10, opacity=1.0] (O) circle (\R); % 3D lighting effect
\end{scope}
\end{tikzpicture}
\end{document} 

demo

11
  • How can draw a circle passing throught four points A, B, C, D? Commented Jun 6, 2017 at 14:55
  • I hope, you will find a solution for my question. Commented Jun 6, 2017 at 15:39
  • tikz-3d always draws circles in the xy plane. The center is at (1,1,0) and the radius is sqrt(2). Commented Jun 6, 2017 at 15:50
  • Style of arc B, C, D is dashed. How can I draw it? Commented Jun 7, 2017 at 0:03
  • Arc BCD is easy. In the xy plane B is at -45 degrees and D is at 135 degrees relative to the center. If you want to make the arc which is between the points where the two circles intersect solid, that is a more interesting problem. Commented Jun 7, 2017 at 12:22
5

I did so.

\documentclass[border=2mm12pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows,calc}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=2]
\def\R{sqrt(3)}
\coordinate (O) at (0,0,0);
\fill[ball color=cyan!10, opacity=1.0]  (O) circle (\R); % 3D lighting effect
 \begin{scope}[tdplot_main_coords, shift={(0,0)}, rotate=0]
\path
      coordinate (A) at (-1,-1,-1)
      coordinate (B) at (1,-1,-1)
      coordinate (C) at (1,1,-1)
      coordinate (D) at (-1,1,-1)
      coordinate (S) at (-1,-1,1);
      \draw[ dashed]
     (A)--(S) (A)--(B)
      (A)--(D)
       ;
\draw [fill opacity=0.4,fill=green!80!blue] (S) -- (B) -- (C) -- cycle;
\draw [fill opacity=0.4,fill=orange!80!blue] (S) -- (C) -- (D) -- cycle;
\foreach \v/\position in {A/below,B/below,C/below,D/right,S/above,O/right} {
    \draw[fill=black] (\v) circle (0.7pt) node [\position=0.2mm] {$\v$};
}
\end{scope}
\end{tikzpicture}
\end{document} 

enter image description here

2
  • Is this an answer? What 'so' did you?
    – cfr
    Commented Jun 8, 2017 at 23:31
  • @cfr This is my answer. My method have to transform the sphere so that center of sphere is origion. When I saw John Kormylo, I saw that, his method faster than my solution. Commented Jun 9, 2017 at 0:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .