I want to create a TikZ diagram showing a unit sphere intersected by a plane. I'd like to highlight the spherical cap (the portion of the sphere on one side of the plane).
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
I'll help you create a TikZ diagram of a unit sphere intersected by a plane with the spherical cap highlighted. Here's a complete example:
latex
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,calc}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords, scale=3]
% Define the plane height
\def\h{0.3} % height of the plane above the center
% Draw the sphere (back part)
\shade[ball color=blue!20!white, opacity=0.3] (0,0,0) circle (1);
% Calculate the radius of the intersection circle
\pgfmathsetmacro{\r}{sqrt(1-\h*\h)}
% Draw the spherical cap (highlighted part)
\begin{scope}
\clip (0,0,\h) circle (\r);
\shade[ball color=red!50!white, opacity=0.8] (0,0,0) circle (1);
\end{scope}
% Draw the intersection circle
\draw[thick, blue] (0,0,\h) circle (\r);
% Draw the plane
\fill[gray!30, opacity=0.5]
(-1.5,-1.5,\h) -- (1.5,-1.5,\h) -- (1.5,1.5,\h) -- (-1.5,1.5,\h) -- cycle;
\draw[gray!50, thick]
(-1.5,-1.5,\h) -- (1.5,-1.5,\h) -- (1.5,1.5,\h) -- (-1.5,1.5,\h) -- cycle;
% Draw the sphere outline
\draw[thick] (0,0,0) circle (1);
% Draw coordinate axes (optional)
\draw[->, thick] (0,0,0) -- (1.5,0,0) node[anchor=north east]{$x$};
\draw[->, thick] (0,0,0) -- (0,1.5,0) node[anchor=north west]{$y$};
\draw[->, thick] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
% Add labels
\node at (0,0,1.3) {Spherical Cap};
\node at (1.2,1.2,\h) {Plane};
\end{tikzpicture}
\end{document}
This code creates a 3D visualization where:
The unit sphere is drawn with a light blue shading
The plane intersects the sphere at height z = 0.3 (you can adjust the \h parameter)
The spherical cap above the plane is highlighted in red
The intersection circle is drawn in blue
The plane is shown as a semi-transparent gray rectangle
You can customize this diagram by:
Changing \h to adjust the plane height (between -1 and 1)
Modifying the viewing angles in \tdplotsetmaincoords{70}{110}
Adjusting colors and opacity values
Removing the coordinate axes if not needed
For a simpler 2D cross-section view, here's an alternative:
latex
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=3]
% Define the plane height
\def\h{0.4}
% Draw the sphere
\draw[thick] (0,0) circle (1);
% Fill the spherical cap
\begin{scope}
\clip (-1,\h) rectangle (1,1);
\fill[red!30] (0,0) circle (1);
\end{scope}
% Draw the plane
\draw[thick, blue] (-1.2,\h) -- (1.2,\h);
% Add labels
\node at (0,-1.3) {Unit Sphere};
\node[blue] at (1.3,\h) {Plane};
\node at (0,0.7) {Cap};
% Mark the center
\fill (0,0) circle (1pt);
\node[below left] at (0,0) {O};
% Show height
\draw[<->, dashed] (1.1,0) -- (1.1,\h) node[midway, right] {$h$};
\end{tikzpicture}
\end{document}
This 2D version shows a cross-section of the sphere and makes it easier to see the geometric relationship between the plane height and the spherical cap.
User
The sphere looks like a circle. How can i fix it?
Assistant
You're right! The sphere appears as a circle because we need to properly render it as a 3D object. Here's an improved version that makes the sphere look three-dimensional:
latex
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,calc,intersections,fillbetween}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords, scale=3]
% Define the plane height
\def\h{0.3}
% Calculate the radius of the intersection circle
\pgfmathsetmacro{\r}{sqrt(1-\h*\h)}
% Draw the lower hemisphere (below the plane)
\shade[ball color=blue!20!white, opacity=0.6] (0,0,0) circle (1);
% Draw the spherical cap with proper 3D shading
\begin{scope}
\clip (0,0,0) circle (1);
\begin{scope}[canvas is xy plane at z=\h]
\clip (0,0) circle (\r);
\shade[ball color=red!60!white, opacity=0.9,
shading angle=45] (0,0) circle ({1/cos(atan(\h))});
\end{scope}
\end{scope}
% Draw the visible meridians (longitude lines)
\foreach \angle in {0,30,60,90,120,150}
{
\tdplotsetrotatedcoords{\angle}{90}{0}
\begin{scope}[tdplot_rotated_coords]
\draw[gray!50, thin] plot[variable=\t,domain=0:180,smooth]
({cos(\t)},{0},{sin(\t)});
\end{scope}
}
% Draw the visible parallels (latitude lines)
\foreach \lat in {-60,-30,0,30,60}
{
\pgfmathsetmacro{\radius}{cos(\lat)}
\pgfmathsetmacro{\height}{sin(\lat)}
\draw[gray!50, thin] (0,0,\height) circle (\radius);
}
% Draw the intersection circle
\draw[thick, blue] (0,0,\h) circle (\r);
% Draw the plane
\fill[gray!20, opacity=0.5]
(-1.5,-1.5,\h) -- (1.5,-1.5,\h) -- (1.5,1.5,\h) -- (-1.5,1.5,\h) -- cycle;
\draw[gray!70, thick]
(-1.5,-1.5,\h) -- (1.5,-1.5,\h) -- (1.5,1.5,\h) -- (-1.5,1.5,\h) -- cycle;
% Draw the sphere outline (equator and visible meridian)
\draw[thick] (0,0,0) circle (1);
\draw[thick] plot[variable=\t,domain=0:180,smooth] ({cos(\t)},{0},{sin(\t)});
% Draw coordinate axes
\draw[->, thick] (0,0,0) -- (1.5,0,0) node[anchor=north east]{$x$};
\draw[->, thick] (0,0,0) -- (0,1.5,0) node[anchor=north west]{$y$};
\draw[->, thick] (0,0,0) -- (0,0,1.5) node[anchor=south]{$z$};
\end{tikzpicture}
\end{document}
For an even more realistic 3D appearance, here's a version using parametric equations to draw the sphere properly:
latex
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={70}{20},
axis lines=center,
xlabel={$x$}, ylabel={$y$}, zlabel={$z$},
xmin=-1.5, xmax=1.5,
ymin=-1.5, ymax=1.5,
zmin=-1.5, zmax=1.5,
unit vector ratio=1 1 1,
width=12cm,
height=12cm,
]
% Define the plane height
\def\h{0.3}
% Draw the lower part of the sphere (below the plane)
\addplot3[
surf,
colormap/cool,
opacity=0.6,
samples=25,
domain=0:360,
y domain=0:180,
z filter/.code={\pgfmathparse{sin(\pgfmathresult)}\pgfmathresult<\h?\pgfmathresult:\pgfkeysvalueof{/pgfplots/unbounded coords=jump}},
]
({cos(x)*sin(y)}, {sin(x)*sin(y)}, {cos(y)});
% Draw the spherical cap (above the plane)
\addplot3[
surf,
colormap/hot,
opacity=0.8,
samples=25,
domain=0:360,
y domain=0:180,
z filter/.code={\pgfmathparse{sin(\pgfmathresult)}\pgfmathresult>=\h?\pgfmathresult:\pgfkeysvalueof{/pgfplots/unbounded coords=jump}},
]
({cos(x)*sin(y)}, {sin(x)*sin(y)}, {cos(y)});
% Draw the plane
\addplot3[
surf,
opacity=0.3,
colormap={gray}{color=(gray!30) color=(gray!30)},
samples=2,
domain=-1.5:1.5,
y domain=-1.5:1.5,
]
{0.3};
% Draw the intersection circle
\pgfmathsetmacro{\r}{sqrt(1-\h*\h)}
\addplot3[
thick,
blue,
samples=100,
domain=0:360,
]
({\r*cos(x)}, {\r*sin(x)}, {\h});
\end{axis}
\end{tikzpicture}
\end{document}
The key improvements in these versions:
Meridians and parallels: The first version adds longitude and latitude lines that help visualize the sphere's curvature
Proper shading: Uses ball color shading to create a 3D effect
Parametric surface: The second version uses pgfplots to draw the sphere as a proper 3D surface
Separate rendering: The sphere is split into two parts (above and below the plane) with different colors
Choose the version that best suits your needs. The first is more customizable with TikZ, while the second provides a more mathematically accurate 3D surface rendering.