# Calculate if point lies inside spherical sector

I would like to calculate if a point $$P$$ in $$\mathbb R^3$$ space lies inside a spherical sector, where the radius of the sphere is $$r$$ and the height of the cap is $$h$$. Is there an elegant way to calculate this? Or should the spherical sector be broken down into simpler shapes: a cone and a sphere, and individual calculations done for each shape?

• Inside the sphere and inside the (unbounded) cone.
– user65203
Mar 31, 2021 at 13:28
• How are the bounds of the spherical sector defined? Can you please add an example? Mar 31, 2021 at 13:47
• @MathLover Sorry I don't know how to answer this question. Here is an example of spherical sector I had in mind en.wikipedia.org/wiki/Spherical_sector#/media/…. Mar 31, 2021 at 13:56
• yes I understand that part but how are you fixing its coordinates because all you have is radius of the sphere and $h$ and that does not uniquely identify a spherical sector. So, as long as a point is inside the sphere, it will be in one of the spherical sectors of given dimension. Is its axis along $z$ axis? Mar 31, 2021 at 14:16
• @MathLover My bad, sorry! Yes it's also defined by some arbitrary axis, $z$ (I hope you don't mean the coordinate system's $z$ axis) Mar 31, 2021 at 14:29

In spherical coordinates,

$$x = \rho \cos \theta \sin \phi, y = \rho \sin \theta \sin \phi, z = \rho \cos\phi, \rho = \sqrt{x^2+y^2+z^2}$$

If the radius of the sphere is $$r$$ with origin as the center, height of spherical cap is $$h$$ and radius of the base of the spherical cap is $$a$$, then the vertex angle of the cone is given by,

$$\alpha = \displaystyle \small \arctan \big(\frac{a}{r-h}\big)$$ and the spherical sector is defined by,

$$\displaystyle 0 \leq \rho \leq r, \small \phi_a - \frac{\alpha}{2} \leq \phi \leq \phi_a + \frac{\alpha}{2}, \theta_a - \frac{\alpha}{2} \leq \theta \leq \theta_a + \frac{\alpha}{2} \$$ where $$\phi_a, \theta_a$$ define the axis of the spherical sector.

Now for a given point $$\displaystyle \small P(x_p, y_p, z_p),$$

$$\displaystyle \small \rho_p = \sqrt{x_p^2 + y_p^2 + z_p^2}, \ \phi_p = \arccos \big(\frac{z_p}{\rho_p}\big), \ \theta_p = \arccos \big(\frac{x_p}{\rho_p \sin \phi_p} \big)$$

So for the point $$P$$ to be in the spherical sector,

$$\displaystyle \small 0 \leq \rho_p \leq r, \ \phi_a - \frac{\alpha}{2} \leq \phi_p \leq \phi_a + \frac{\alpha}{2}, \theta_a - \frac{\alpha}{2} \leq \theta_p \leq \theta_a + \frac{\alpha}{2}$$

• Thanks very much! I guess we can follow the same logic to also calculate a circular sector with an arbitrary axis for point $P$ in $\mathbb R^2$ space, but with polar coordinates instead of spherical coordinates. Apr 1, 2021 at 10:46
• Yes that is correct. Apr 1, 2021 at 11:16

In cylindrical coordinates with the cone axis along $$z$$,

$$\begin{cases}\rho^2+z^2\le r^2,\\\rho\le\alpha z.\end{cases}$$

• Thanks! Can I ask what $α$ denotes? Mar 31, 2021 at 13:44
• @LennyWhite: your task to relate $\alpha$ to $h$.
– user65203
Mar 31, 2021 at 13:45

In Cartesian coordinates, if $$\hat{a}$$ is the cone unit axis vector ($$\left\lVert\hat{a}\right\rVert = 1$$), $$\vec{o}$$ is the center of the sphere, $$r$$ is the sphere radius, and either $$\varphi$$ is half the apex angle (aperture angle $$2\varphi$$) or $$h$$ is the cap height, $$\cos\varphi = \frac{r - h}{r} \quad \iff \quad h = r (1 - \cos\varphi)$$ Let $$S^2 = (\sin\varphi)^2 = 1 - (\cos\varphi)^2 = \frac{2 r h - h^2}{r^2}$$ Then, point $$\vec{p}$$ is in the spherical sector if \left\lbrace \begin{aligned} q & = (\vec{p} - \vec{o}) \cdot \hat{a} \ge 0 \\ d^2 & = \left\lVert \vec{p} - \vec{o} \right\rVert^2 \le r^2 \\ q^2 & \le S^2 d^2 \\ \end{aligned} \right. Here, $$d$$ is the distance squared from sphere center to point $$\vec{p}$$, and $$q$$ is the distance from the sphere center to point $$\vec{p}$$ measured along the cone axis. $$q$$ is zero at the center, and positive in the same halfspace as the cone. The last ensures that the point $$\vec{p}$$ is within the cone, by ensuring that $$q/d \le \sin\varphi$$.

The reason for using Euclidean norm squared is to avoid having to compute square roots (useful when programming), as $$\left\lVert\vec{p}\right\rVert^2 = \vec{p} \cdot \vec{p}$$.