Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to draw circular patches of given angular radii around arbitrary points on a sphere. I am able to use, for example,

SphericalPlot3D[1, {θ, 0, Pi/3}, {ϕ, 0, 2 Pi}, PlotStyle -> {Black, Opacity[0.7]}, 
                Mesh -> None]

and

SphericalPlot3D[1, {θ, (2 Pi)/3, Pi}, {ϕ, 0, 2 Pi}, PlotStyle -> {Black, Opacity[0.7]},
                Mesh -> None]

to create angular patches of (angular) radius Pi/3 around the north and south poles of the sphere, respectively, but what if I want to create two patches around two arbitrary points on the surface of the sphere and then draw in the rest of the sphere in some other background color? Thank you!

share|improve this question
up vote 4 down vote accepted
Show[
 SphericalPlot3D[1, {θ, 0, Pi}, {ϕ, 0, 2 Pi}, Mesh -> None,  RegionFunction -> 
    Function[{x, y, z, θ, ϕ, r}, Norm[{x, y, z} - {1, 1, 0}] > 1], PlotStyle -> Red], 
 SphericalPlot3D[1, {θ, 0, Pi}, {ϕ, 0, 2 Pi}, Mesh -> None, RegionFunction -> 
   Function[{x, y, z, θ, ϕ, r}, Norm[{x, y, z} - {1, 1, 0}] < 1], PlotStyle -> Blue]]

Mathematica graphics

share|improve this answer
    
Thank you very much! I'm still digging into the specifics of RegionFunction and its implementation in your answer, but it seems as though I can control the radius of the circular patch by changing the inequality threshold value and the point about which the patch is centered by changing the constant vector ({1,1,0} in your example). – PhysicsCodingEnthusiast Feb 23 at 0:26
    
@PhysicsCodingEnthusiast yep, that's it :) – Dr. belisarius Feb 23 at 0:37
    
Just for future reference (this can be added into the answer above), Norm[{x,y,z}-{x1,y1,z1}] < c defines a ball of radius c centered at (x1,y1,z1). It is, to me, easier to define the center of the ball to be on the surface of the sphere, so (x1,y1,z1) = R(sin\theta cos\phi, sin\theta sin\phi, cos\theta). Then, to get a circular patch with angular radius \gamma centered at (\theta, \phi) (or, equivalently, (x1,y1,z1)), the radius of the ball (with center (x1,y1,z1)) should be c = R \sqrt{ 2(1 - cos\gamma) }. – PhysicsCodingEnthusiast Feb 23 at 4:00

Here's a way using MeshFunctions and MeshShading that generalized to any number of points.

pts = Normalize /@ RandomReal[{-1, 1}, {2, 3}];
angles = Table[{Pi/3}, Length@pts];
SphericalPlot3D[1, {θ, 0, Pi}, {ϕ, 0, 2 Pi}, 
 MeshFunctions -> 
  Table[With[{v0 = v0}, 
    Function[{x, y, z, θ, ϕ}, 
     VectorAngle[{x, y, z}, v0]]], {v0, pts}],
 Mesh -> angles,
 MeshShading -> {{Black, Black}, {Black, Automatic}},
 BoundaryStyle -> None]

Mathematica graphics

More random points, random angles:

SeedRandom[7];
pts = Normalize /@ RandomReal[{-1, 1}, {3, 3}];
angles = RandomReal[0.66, {Length@pts, 1}];
shading = ReplacePart[
   ConstantArray[Black, Table[2, Length@pts]], 
   Table[-1, Length@pts] -> Automatic];
SphericalPlot3D[1, {θ, 0, Pi}, {ϕ, 0, 2 Pi},
 PlotPoints -> 50, 
 MeshFunctions -> 
  Table[With[{v0 = v0}, 
    Function[{x, y, z, θ, ϕ}, 
     VectorAngle[{x, y, z}, v0]]], {v0, pts}],
 Mesh -> angles,
 MeshShading -> shading,
 BoundaryStyle -> None, MeshStyle -> None]

Mathematica graphics

share|improve this answer
    
Thank you for your answer! I had already accepted the first answer, as it worked for my purposes, but I definitely appreciate you taking the time to answer my question! – PhysicsCodingEnthusiast Feb 23 at 4:10
    
@PhysicsCodingEnthusiast You're welcome! Sometimes you'll find people giving advice to wait 24 hours before accepting an answer. Not having an accepted answer encourages other to take a look to see if they can do better. Also, since our active users are found all around the world, which is really cool, imo, some may not get a chance to view your question until well after you've posted it. But feel free to accept whichever answer you think is best whenever you want. – Michael E2 Feb 23 at 14:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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