The SKIRT project
advanced radiative transfer for astrophysics
Public Member Functions | Private Attributes | List of all members
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:

Note
Because of the limitations on the range of φ, 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 θ, 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 φ, 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.

rctr=(rmin+rmax)/2θctr=(θmin+θmax)/2φctr=(φmin+φmax)/2.

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 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 r and direction 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 x=r+sk, with k a unit vector.

The two intersection points with a radial boundary sphere x2=r2 are obtained by solving the quadratic equation s2+2(rk)s+(r2r2)=0 for s.

The two intersection points with an angular boundary cone xz2=c2x2 (with c=cosθ) are obtained by solving the quadratic equation (c2kz2)s2+2(c2rkrzkz)s+(c2r2rz2)=0 for s.

The intersection point with a meriodonal plane sinφx=cosφy is obtained by

s=rxsinφrycosφkxsinφkycosφ

◆ phimax()

double SphericalCell::phimax ( ) const
inline

This function returns the φmax border coordinate of the cell.

◆ phimin()

double SphericalCell::phimin ( ) const
inline

This function returns the φmin border coordinate of the cell.

◆ rmax()

double SphericalCell::rmax ( ) const
inline

This function returns the Rmax border coordinate of the cell.

◆ rmin()

double SphericalCell::rmin ( ) const
inline

This function returns the rmin border coordinate of the cell.

◆ thetamax()

double SphericalCell::thetamax ( ) const
inline

This function returns the θmax border coordinate of the cell.

◆ thetamin()

double SphericalCell::thetamin ( ) const
inline

This function returns the θmin border coordinate of the cell.

◆ volume()

double SphericalCell::volume ( ) const

This function returns the volume of the cell, given by 13(rmax3rmin3)(cosθmincosθmax)(φmaxφmin).


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