Function Repository Resource:

SphericalCap

Source Notebook

Represent a spherical cap in 3D graphics

Contributed by: Jaroslav Kysela

ResourceFunction["SphericalCap"][]

represents a hemisphere.

ResourceFunction["SphericalCap"][p]

represents a spherical cap with protrusion p.

ResourceFunction["SphericalCap"][p,prop]

returns a given property prop.

Details

ResourceFunction["SphericalCap"] represents a spherical cap corresponding to a unit-radius sphere.
ResourceFunction["SphericalCap"] can be used as a 3D graphics primitive, which is internally represented by a BSplineSurface expression.
ResourceFunction["SphericalCap"] is affected by styling directives such as EdgeForm, Opacity, RGBColor, etc.
The position, size, and rotation of the cap can be modified by Translate, Scale, and Rotate, respectively.
The protrusion parameter p must lie between -1 and 1. By default, this parameter is set to 0.
The following properties can be supplied:
"Surface"BSplineSurface expression; default property
"Function"explicit function corresponding to the BSplineSurface expression
"Formula"explicit formula corresponding to the BSplineSurface expression
"ControlPoints"control points of BSplineSurface expression
"Weights"weights of BSplineSurface expression
"Properties"list of all properties

Examples

Basic Examples (3) 

Show a hemisphere:

In[1]:=
Graphics3D[ResourceFunction["SphericalCap"][]]
Out[1]=

Show a spherical cap:

In[2]:=
Graphics3D[ResourceFunction["SphericalCap"][0.6]]
Out[2]=

Apply styling:

In[3]:=
Graphics3D[{Opacity[0.8], Orange, EdgeForm[{Purple, Dashed, Thickness[0.02]}], ResourceFunction["SphericalCap"][0.5]}]
Out[3]=

Scope (9) 

Protrusion (2) 

Spherical caps with different protrusion parameters:

In[4]:=
Graphics3D[ResourceFunction["SphericalCap"][#], Sequence[
   Method -> {"SplinePoints" -> {30, 30}}, ViewPoint -> {-1.3, -2.4, -2.}]] & /@ {-0.9, -0.5, 0.2, 0.8}
Out[4]=

As the parameter approaches -1, the cap approaches the unit sphere:

In[5]:=
Graphics3D[ResourceFunction["SphericalCap"][-0.9999, True], Sequence[
 Method -> {"SplinePoints" -> {200, 200}}, PlotRange -> {{-1, 1}, {-1, 1}, {0, 2}}, ViewPoint -> {-1.3, -2.4, -2.}]]
Out[5]=

Properties (7) 

List all available properties:

In[6]:=
ResourceFunction["SphericalCap"]["Properties"]
Out[6]=

By default, the "Surface" property is returned:

In[7]:=
{
 Graphics3D[ResourceFunction["SphericalCap"][]],
 Graphics3D[ResourceFunction["SphericalCap"][0, "Surface"]]
 }
Out[7]=

Retrieve the control points of the spline surface for a symbolic protrusion:

In[8]:=
ResourceFunction["SphericalCap"][p, "ControlPoints"]
Out[8]=

Retrieve the weights of the spline surface:

In[9]:=
ResourceFunction["SphericalCap"][p, "Weights"]
Out[9]=

Get the function internally used by the spline surface:

In[10]:=
fun = ResourceFunction["SphericalCap"][p, "Function"];
fun[tx, ty] // Short[#, 4] &
Out[11]=

Plot the function for a specific protrusion parameter:

In[12]:=
ParametricPlot3D[
 ResourceFunction["SphericalCap"][0.5, "Function"][tx, ty], {tx, 0, 1}, {ty, 0, 1}]
Out[12]=

Consider only a part of the surface:

In[13]:=
{txmin, txmax} = {0.1, 0.9};
{tymin, tymax} = {0.2, 0.3};
ParametricPlot3D[
 ResourceFunction["SphericalCap"][0.5, "Function"][tx, ty], {tx, txmin, txmax}, {ty, tymin, tymax}, PlotRange -> 1, Mesh -> None]
Out[15]=
In[16]:=
ParametricPlot3D[
   ResourceFunction["SphericalCap"][0.5, "Function"][tx, ty], {tx, #1, #2}, {ty, #3, #4}, PlotRange -> 1, Mesh -> None] & @@@ {{0.5, 1, 0, 1}, {0, 1, 0.5, 1}, {0.2, 0.8, 0.2, 0.8}}
Out[16]=

Get the corresponding formula in formal variables x and y:

In[17]:=
form = ResourceFunction["SphericalCap"][p, "Formula"];
form // Short[#, 4] &
Out[18]=

Applications (2) 

Create a bowl of water graphic:

In[19]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/21a44d45-64ba-4cd4-bf94-53d76d0b7994"]
Out[20]=

Show a spherical lens:

In[21]:=
lens = {Opacity[0.5], ResourceFunction["SphericalCap"][0.8], Rotate[ResourceFunction["SphericalCap"][0.8], \[Pi], {0, 1, 0}]};
Graphics3D[Rotate[lens, \[Pi]/2, {0, 1, 0}], Sequence[
 ViewPoint -> {0.88, -2.98, 1.32}, Method -> {"SplinePoints" -> {40, 40}}, Boxed -> False]]
Out[22]=

Properties and Relations (5) 

Obtain a spherical cap using Ball and ClipPlanes:

In[23]:=
Manipulate[
 Graphics3D[{Opacity[0.5], Style[Scale[Ball[{0, 0, -p}], If[scale, 1, 1/Sqrt[1 - p^2]], {0, 0, 0}], ClipPlanes -> InfinitePlane[{0, 0, 0}, {{1, 0, 0}, {0, 1, 0}}]]}, PlotRange -> 2], {{p, 0}, -1, 1}, {{scale, False}, {True, False}}]
Out[23]=

Obtain a spherical cap using SphericalPlot3D:

In[24]:=
Manipulate[
 limang = ArcCos[p];
 cap = SphericalPlot3D[
   1, {\[Theta], -limang, limang}, {\[Phi], -\[Pi]/2, \[Pi]/2}];
 cap = First@Cases[cap, _GraphicsComplex, Infinity, 1];
 Graphics3D[
  Scale[Translate[cap, {0, 0, -p}], If[scale, 1, 1/Sqrt[1 - p^2]], {0, 0, 0}], Axes -> True]
 , {{p, 0}, -1 + 0.01, 1 - 0.01}, {{scale, False}, {True, False}}]
Out[24]=

Represent a flat 3D disk:

In[25]:=
Graphics3D[{ResourceFunction["SphericalCap"][1]}, Method -> {"SplinePoints" -> {20, 20}}]
Out[25]=

Compare with the resource function Disk3D:

In[26]:=
Graphics3D[ResourceFunction["Disk3D"][]]
Out[26]=

Despite the stark similarity, the underlying spline surfaces differ substantially:

In[27]:=
ResourceFunction["SphericalCap"][1]
Out[27]=
In[28]:=
ResourceFunction["Disk3D"][]
Out[28]=

Move, scale, and rotate the cap:

In[29]:=
cap = ResourceFunction["SphericalCap"][0.8];
{
 Graphics3D[Translate[cap, {1, 0, 1.2}], Axes -> True, PlotRange -> 2],
 Graphics3D[Scale[cap, 2], Axes -> True, PlotRange -> 2],
 Graphics3D[Rotate[cap, \[Pi]/2, {0, 1, 0}], Axes -> True, PlotRange -> 2]
 }
Out[30]=

A spherical cap returned by SphericalCap satisfies the equation for a shifted (unit) sphere:

In[31]:=
cap = ResourceFunction["SphericalCap"][p, "Formula", False];
{x, y, z} = PiecewiseExpand[cap, 0 <= \[FormalX] < 1/2 && 0 <= \[FormalY] < 1/2] // Quiet;
sphereEq = x^2 + y^2 + (z + p /Sqrt[1 - p^2])^2 == 1/(1 - p^2);
Simplify[sphereEq, {-1 < p < 1}]
Out[34]=

Possible Issues (2) 

Artefacts occur at poles:

In[35]:=
Graphics3D[ResourceFunction["SphericalCap"][0.5]]
Out[35]=

Increase the rendering parameter for spline surfaces to mitigate the artefacts:

In[36]:=
Graphics3D[ResourceFunction["SphericalCap"][0.5], Method -> {"SplinePoints" -> {30, 30}}]
Out[36]=

The protrusion parameter cannot be set exactly to -1:

In[37]:=
Graphics3D[ResourceFunction["SphericalCap"][-1]]
Out[37]=

For such a case, use Ball instead:

In[38]:=
{
 Graphics3D[ResourceFunction["SphericalCap"][-0.99], ViewPoint -> {-1.3`, -2.4`, 2.`}, Method -> {"SplinePoints" -> {30, 30}}],
 Graphics3D[Ball[], ViewPoint -> {-1.3`, -2.4`, 2.`}]
 }
Out[38]=

Neat Examples (3) 

Bubbles made by a bubble wand:

In[39]:=
wand = {Gray, Torus[{0, 0, 0}, {0.8, 1.1}], Cylinder[{{0.9, 0, 0}, {5, 0, 0}}, 0.1]};
bubbles = {Opacity[0.5], ResourceFunction["SphericalCap"][0], Ball[Table[{RandomReal[], RandomReal[], 1 + i}, {i, 5}], RandomReal[{0, 1}, 5]]};
Graphics3D[Rotate[{wand, bubbles}, \[Pi]/2, {0, 1, 0}], ViewPoint -> {-1.3, -2.4, 2.}, Boxed -> False]
Out[40]=

Visualize the control points:

In[41]:=
cols = {Yellow, Red, Green, Blue, Black};
Manipulate[
 arrx = ResourceFunction["SphericalCap"][p, "ControlPoints"];
 Graphics3D[{PointSize[0.02], Table[{cols[[idx]], Line[arrx[[idx]]], Point[arrx[[idx]]]}, {idx, Range[5]}], Opacity[0.5, Gray], ResourceFunction["SphericalCap"][p]}, PlotRange -> {3 {-1, 1}, 3 {-1, 1}, {0, 4}}, Axes -> True], {{p, 0}, -1 + 0.01, 1}]
Out[42]=

Visualize the weights:

In[43]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/25c302d7-684d-44c5-9c39-6a871981cd10"]
Out[44]=

Publisher

Jaroslav Kysela

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 22 November 2023

Related Resources

License Information