Basically, I ultimately want to make something like this:
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.
Answer
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]
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]
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))
One can also specify the normals adding the option NormalsFunction
.
SphericalPlot3D[..., NormalsFunction -> Function[{x, y, z, θ, ϕ, r}, {x, y, z}]]
Comments
Post a Comment