1
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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 ... $\endgroup$
    – Domen
    Feb 23, 2023 at 22:28
  • $\begingroup$ @ulvi : I am going to apply the method to arbitrary domains. $\endgroup$ Feb 23, 2023 at 22:28
  • $\begingroup$ @Domen : I am not looking for an exact result, but some accuracy is needed, say 3 digits after the comma. $\endgroup$ Feb 23, 2023 at 22:29

2 Answers 2

4
$\begingroup$

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).

$\endgroup$
4
$\begingroup$
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]

enter image description here

$\endgroup$

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.