The SKIRT project
advanced radiative transfer for astrophysics
SphericalCell Class Reference

#include <SphericalCell.hpp>

Public Member Functions

 SphericalCell ()
 SphericalCell (double rmin, double thetamin, double phimin, double rmax, double thetamax, double phimax)
Box boundingBox () const
Position center () const
bool contains (Vec bfr) const
void extent (double &rmin, double &thetamin, double &phimin, double &rmax, double &thetamax, double &phimax) const
double intersection (Vec r, const Vec k) const
double phimax () const
double phimin () const
double rmax () const
double rmin () const
double thetamax () const
double thetamin () const
double volume () const

Private Attributes

double _cosphimax
double _cosphimin
double _costhetamax
double _costhetamin
double _phimax
double _phimin
double _rmax
double _rmin
double _sinphimax
double _sinphimin
double _sinthetamax
double _sinthetamin
double _thetamax
double _thetamin

Detailed Description

SphericalCell is a low-level class for working with basic three-dimensional cells in spherical coordinates. Each SphericalCell instance represents a cell bordered by:

  • two spheres centered on the origin defined by radii \(0 \le r_\text{min} \le r_\text{max}\),
  • two polar half-cones defined by inclination angles \(0 \le \theta_\text{min} \le \theta_\text{max} \le \pi\),
  • two meridional half-planes (with \(r>0\)) defined by azimuth angles \(-\pi \le \varphi_\text{min} \le \varphi_\text{max} \le \pi\) with \(\varphi_\text{max} - \varphi_\text{min} \le \pi\),
Note
Because of the limitations on the range of \(\varphi\), a SphericalCell cannot straddle the negative x-axis of the Cartesian model coordinate system, and it cannot span more than half of the azimuth circle. Also, because of the limitations on the range of \(\theta\), a SphericalCell cannot straddle the z-axis of the Cartesian model coordinate system.

The class offers functions to retrieve various basic properties of the cell, such as its border coordinates and its volume, and for geometric operations such as determining whether a given Cartesian position is inside the cell or calculating the intersection with a ray.

Constructor & Destructor Documentation

◆ SphericalCell() [1/2]

SphericalCell::SphericalCell ( )
inline

The default constructor creates an empty cell at the origin, i.e. it initializes all border coordinates to zero.

◆ SphericalCell() [2/2]

SphericalCell::SphericalCell ( double rmin,
double thetamin,
double phimin,
double rmax,
double thetamax,
double phimax )

This constructor initializes the cell border coordinates to the values provided as arguments. It does not verify that these values conform to the limits described in the class header. Non-conforming values lead to undefined behavior.

Member Function Documentation

◆ boundingBox()

Box SphericalCell::boundingBox ( ) const

This function returns the Cartesian bounding box of the cell, in other words the smallest cuboid lined up with the Cartesian coordinate axes that encloses the cell.

The intersection of a conical cell boundary and a spherical cell boundary is a horizontal circle segment. This means that the z coordinate of the intersection does not depend on \(\varphi\), and the vertical bounds of the cell can be determined by considering the cell's corner points in the meridional plane.

For the projection on the equatorial plane, things are more complicated. If the cell straddles an x or y axis in the azimuthal direction, or if it straddles the xy plane in the polar direction, the projection of the outer sphere boundary on the x and/or y axes extends beyond the projection of the cell corner points. The bounding box must thus enclose the corresponding extreme points in addition to the cell corner points.

◆ center()

Position SphericalCell::center ( ) const

This function returns the "center" of the cell in Cartesian coordinates. This position is defined as the halfway point between the cell borders in spherical coordinates, i.e.

\[\begin{aligned} r_\text{ctr} = (r_\text{min} + r_\text{max})/2 \\ \theta_\text{ctr} = (\theta_\text{min} + \theta_\text{max})/2 \\ \varphi_\text{ctr} = (\varphi_\text{min} + \varphi_\text{max})/2. \end{aligned}\]

As stated above the function returns this position after converting it to Cartesian coordinates.

◆ contains()

bool SphericalCell::contains ( Vec bfr) const

This function returns true if the Cartesian position \(\bf{r}=(x,y,z)\) is inside the cell, and false otherwise. A position on an edge or face on the "lower" side of the cell is considered to be contained in the cell, while a position on an edge or face on the "upper" side of the cell is considered not to be contained in the cell. This approach avoids duplicate containment of adjacent cells.

◆ extent()

void SphericalCell::extent ( double & rmin,
double & thetamin,
double & phimin,
double & rmax,
double & thetamax,
double & phimax ) const
inline

This function stores the cell border coordinates in the provided arguments.

◆ intersection()

double SphericalCell::intersection ( Vec r,
const Vec k ) const

This function intersects the receiving cell with a ray (half-line) defined by the specified starting position \(\bf{r}\) and direction \(\bf{k}\). If the ray does not intersect the cell, the function returns zero. If the ray does intersect the cell, the function returns the length of the intersection segment, or if applicable, the sum of the two intersection segments (because a spherical cell is concave, a ray can intersect it multiple times). If the starting position is inside the cell, only the portion of the ray inside the cell is taken into account.

A ray that touches the cell border in a single point is not considered to intersect. A ray along an edge or face on the "lower" side of the cell is considered to intersect, while ray along an edge or face on the "upper" side of the cell is considered not to intersect. This approach avoids duplicate intersection of adjacent cells.

Implementation

The function uses the following strategy. First it calculates all intersection points with the bordering surfaces and sorts them on distance along the ray. Then, for each segment between consecutive intersections beyond the ray's starting point, it determines whether the segment's midpoint is inside the cell or not, and accumulates the lengths of the inside segments. This automatically takes care of the cases where the ray lies in one of the bordering surfaces.

The ray can be represented by its parameter equation \({\bf{x}}={\bf{r}}+s\,{\bf{k}}\), with \({\bf{k}}\) a unit vector.

The two intersection points with a radial boundary sphere \({\bf{x}}^2=r_*^2\) are obtained by solving the quadratic equation \(s^2 + 2\,({\bf{r}}\cdot{\bf{k}})\,s + ({\bf{r}}^2-r_*^2)=0\) for \(s\).

The two intersection points with an angular boundary cone \(x_z^2=c^2\,{\bf{x}}^2\) (with \(c=\cos\theta_*\)) are obtained by solving the quadratic equation \((c^2-k_z^2)\,s^2 + 2\,(c^2\,{\bf{r}}\cdot{\bf{k}}-r_z k_z)\,s + (c^2\,{\bf{r}}^2-r_z^2)=0\) for \(s\).

The intersection point with a meriodonal plane \(\sin\varphi_* x = \cos\varphi_* y\) is obtained by

\[ s = -\;\frac{r_\text{x}\sin\varphi_* - r_\text{y}\cos\varphi_*} {k_\text{x}\sin\varphi_* - k_\text{y}\cos\varphi_*} \]

◆ phimax()

double SphericalCell::phimax ( ) const
inline

This function returns the \(\varphi_\text{max}\) border coordinate of the cell.

◆ phimin()

double SphericalCell::phimin ( ) const
inline

This function returns the \(\varphi_\text{min}\) border coordinate of the cell.

◆ rmax()

double SphericalCell::rmax ( ) const
inline

This function returns the \(R_\text{max}\) border coordinate of the cell.

◆ rmin()

double SphericalCell::rmin ( ) const
inline

This function returns the \(r_\text{min}\) border coordinate of the cell.

◆ thetamax()

double SphericalCell::thetamax ( ) const
inline

This function returns the \(\theta_\text{max}\) border coordinate of the cell.

◆ thetamin()

double SphericalCell::thetamin ( ) const
inline

This function returns the \(\theta_\text{min}\) border coordinate of the cell.

◆ volume()

double SphericalCell::volume ( ) const

This function returns the volume of the cell, given by \(\frac{1}{3} \left(r_\text{max}^3-r_\text{min}^3\right) \left(\cos\theta_\text{min}-\cos\theta_\text{max}\right) \left(\varphi_\text{max}-\varphi_\text{min}\right)\).


The documentation for this class was generated from the following file: