# How to find the minimal and maximal polar angles covered by the following domain?

Consider some region in 3D space. Example is

reg = Cylinder[{{0, 24, 14}, {0, 42.7, 14}}, 9]


I want to find the minimal and maximal polar angle $$\theta = \arccos\left(\frac{z}{r}\right)$$ covered by this region. A brute-force way would be just to generate random points belonging to the region, convert to $$\theta$$, and find min/max:

points = {ArcCos[#[[3]]/Sqrt[#[[1]]^2 + #[[2]]^2 + #[[3]]^2]]} & /@
Table[RandomPoint[reg], 10^4]//Flatten;
thmin=Min[points]
thmax=Max[points]


0.81

1.44

However, the method is slow: accurate enough results (say, 3 digits after the comma) would require a large number of generated points. In addition, it would be much slower for more complicated figures. Is there any other way to evaluate the minimal and maximal angles?

P.S. The brute method may be made a bit more efficient if generating points belonging to RegionBoundary[reg]. However, I have found that Mathematica gets stuck in this case if reg is parallelepiped.

• Are you looking for an exact result, or would you be satisfied with some numerical approximation? For example, insted of random sampling in the region, you could discretize the boundary, and calculate min/max of $\theta$ on these points ... Feb 23, 2023 at 22:28
• @ulvi : I am going to apply the method to arbitrary domains. Feb 23, 2023 at 22:28
• @Domen : I am not looking for an exact result, but some accuracy is needed, say 3 digits after the comma. Feb 23, 2023 at 22:29

You can discretize the boundary of the region, and calculate the minimal and maximal $$\theta$$ of resulting mesh points.

reg = Cylinder[{{0, 24, 14}, {0, 42.7, 14}}, 9];
θ[x_, y_, z_] := ArcCos[z/Sqrt[x^2 + y^2 + z^2]];
MinMax[θ @@@ MeshCoordinates[BoundaryDiscretizeRegion[reg]]]

(* {0.806672, 1.45423} *)


You can further control the mesh quality by different options of BoundaryDiscretizeRegion (such as MaxCellMeasure or AccuracyGoal).

reg = Cylinder[{{0, 24, 14}, {0, 42.7, 14}}, 9];
max = NMaximize[
ArcCos[z/Sqrt[x^2 + y^2 + z^2]], {x, y, z} ∈ reg];
min =NMinimize[ArcCos[z/Sqrt[x^2 + y^2 + z^2]], {x, y, z} ∈ reg];
{min[[1]], max[[1]]}


{0.806672, 1.45423}

Graphics3D[{reg, Arrow[{{0, 0, 0}, {x, y, z}}] /. max[[2]],
Arrow[{{0, 0, 0}, {x, y, z}}] /. min[[2]]}, ViewPoint -> Right]