3
$\begingroup$

Basically, I ultimately want to make something like this:

enter image description here

However, I am unsure of how to do this in Mathematica. I'm trying to do this via RegionPlot3D, and for starters, I was trying to draw a little disk in a sphere. But RegionPlot3d does not draws a sphere. For example:

RegionPlot3D[
 x^2 + y^2 + z^2 <= 1  && 
  z > 0 && 
  (x - Cos[π/4] Cos[π/3])^2 + (y - 
       Cos[π/4] Sin[π/3])^2 + (z - Sin[π/4])^2 <= 1/2, 
  {x, -1.5, 1.5}, {y, -1.5, 1.5}, {z, -1.5, 1.5}]

only makes a little blob. If I change this $1/2$ to, say, $1/10$, then it completely vanishes. Also, if I use x^2+y^2+z^2 == 1 instead of x^2+y^2+z^2 <= 1, nothing is drawn. I tried to cheat and use x^2+y^2+z^2 <= 1 && x^2+y^2+z^2 => 1, but it didn't worked. I don't know what to do.

$\endgroup$
2
  • $\begingroup$ Are you using V9 or V10? (The tools available are different.) $\endgroup$
    – Michael E2
    Mar 1, 2015 at 20:00
  • 1
    $\begingroup$ I am using version 9. $\endgroup$
    – Ivo Terek
    Mar 1, 2015 at 20:01

1 Answer 1

3
$\begingroup$

Is this what you would like?

SphericalPlot3D[1, {θ, 0, Pi/2}, {ϕ, 0, 2 Pi}, 
 RegionFunction -> 
  Function[{x, y, z, θ, ϕ, r}, 
   z > 0 &&
    (x - Cos[π/4] Cos[π/3])^2 + (y - Cos[π/4] Sin[π/3])^2 + (z - Sin[π/4])^2 <= 1/10],
  PlotRange -> 1.5]

Mathematica graphics


Response to comment:

plot = SphericalPlot3D[1, {θ, 0, Pi}, {ϕ, 0, 2 Pi}, 
 MeshFunctions -> {Function[{x, y, z, θ, ϕ, r},
   (x - Cos[π/4] Cos[π/3])^2 + (y - Cos[π/4] Sin[π/3])^2 + (z - Sin[π/4])^2]}, 
 Mesh -> {{1/10}}, MeshShading -> {Red, Yellow}, 
 BoundaryStyle -> None, PlotPoints -> 50, PlotRange -> 1.5]

Mathematica graphics

The apparent "seam" is the meeting of the boundaries ϕ == 0 and ϕ == 2 π. Since it's a sphere centered at the origin, there is a relatively easy fix. It isn't always so easy.

plot /. GraphicsComplex[pts_, stuff__] :> (GraphicsComplex[pts, stuff] /. 
   (VertexNormals -> _) :> (VertexNormals -> pts))

Mathematica graphics

One can also specify the normals adding the option NormalsFunction.

SphericalPlot3D[..., NormalsFunction -> Function[{x, y, z, θ, ϕ, r}, {x, y, z}]]
$\endgroup$
9
  • $\begingroup$ Yes, that's pretty much it. I hadn't thought about using SphericalPlot3D, in fact I know very little about the program, I'm still learning, thanks. However, if I wanted to make a plot of the whole sphere, stressing this little disk, what you'd think it would be better? Do everything separated and then using Show, or trying to figure out how RegionFunction works? $\endgroup$
    – Ivo Terek
    Mar 1, 2015 at 20:24
  • $\begingroup$ I found out that Plot3D[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, RegionFunction -> Function[{x, y, z}, (x - Cos[\[Pi]/4] Cos[\[Pi]/3])^2 + (y - Cos[\[Pi]/4] Sin[\[Pi]/3])^2 + (z - Sin[\[Pi]/4])^2 <= 1/2]] works nice, too. $\endgroup$
    – Ivo Terek
    Mar 1, 2015 at 20:38
  • 1
    $\begingroup$ @IvoTerek You could also sometimes use ParametricPlot3D, which is suitable for surfaces that aren't graphs of an f(x,y), and allows you to specify the region in terms of parameters or the coordinates. $\endgroup$
    – Michael E2
    Mar 1, 2015 at 20:41
  • $\begingroup$ I understood. Thank you very much for taking the time to explain :) $\endgroup$
    – Ivo Terek
    Mar 1, 2015 at 20:46
  • 1
    $\begingroup$ @IvoTerek Region functions are boolean (true/false values) and mesh functions are numeric. So in your example, you should have had MeshFunctions -> {Function[{x, y, z, u, v}, (x - Cos[\[Pi]/4] Cos[\[Pi]/3])^2 + (y - Cos[\[Pi]/4] Sin[\[Pi]/3])^2 + (z - Sin[\[Pi]/4])^2]}, Mesh -> {{1/20}}. You might want to look at the doc page of each plot function; under "Options" you'll find examples that will show how to create nice illustrations. $\endgroup$
    – Michael E2
    Mar 1, 2015 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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