The SKIRT project
advanced radiative transfer for astrophysics
Public Member Functions | Private Attributes | List of all members
CylindricalCell Class Reference

#include <CylindricalCell.hpp>

Public Member Functions

 CylindricalCell ()
 
 CylindricalCell (double Rmin, double phimin, double zmin, double Rmax, double phimax, double zmax)
 
Box boundingBox () const
 
Position center () const
 
bool contains (Vec r) const
 
void extent (double &Rmin, double &phimin, double &zmin, double &Rmax, double &phimax, double &zmax) const
 
double intersection (Vec r, const Vec k) const
 
double phimax () const
 
double phimin () const
 
double Rmax () const
 
double Rmin () const
 
double volume () const
 
double zmax () const
 
double zmin () const
 

Private Attributes

double _cosphimax
 
double _cosphimin
 
double _phimax
 
double _phimin
 
double _Rmax
 
double _Rmin
 
double _sinphimax
 
double _sinphimin
 
double _zmax
 
double _zmin
 

Detailed Description

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

Note
Because of the limitations on the range of φ, a CylindricalCell cannot straddle the negative x-axis of the Cartesian model coordinate system, and it cannot span more than half of the azimuth circle.

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

◆ CylindricalCell() [1/2]

CylindricalCell::CylindricalCell ( )
inline

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

◆ CylindricalCell() [2/2]

CylindricalCell::CylindricalCell ( double  Rmin,
double  phimin,
double  zmin,
double  Rmax,
double  phimax,
double  zmax 
)

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 CylindricalCell::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 bounds along the z-axis are the same for Cylindrical and Cartesian coordinates, but the function needs to specifically determine the bounding rectangle projected on the xy plane. This bounding rectangle must of course enclose the four corner points of the cell. In addition, if the cell straddles one of the coordinate axes, the bounding rectangle must also enclose a point on that axis at radius Rmax.

◆ center()

Position CylindricalCell::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 cylindrical coordinates, i.e.

Rctr=(Rmin+Rmax)/2φctr=(φmin+φmax)/2zctr=(zmin+zmax)/2.

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

◆ contains()

bool CylindricalCell::contains ( Vec  r) 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 CylindricalCell::extent ( double &  Rmin,
double &  phimin,
double &  zmin,
double &  Rmax,
double &  phimax,
double &  zmax 
) const
inline

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

◆ intersection()

double CylindricalCell::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 cell is concave at the inner radial cylinder, a ray can intersect it twice). 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 planes and cylinders 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 planes or cylinders.

The ray equation can be written as

{x=rx+kxsy=ry+kysz=rz+kzswiths>0.

Intersection with a horizontal plane with equation z=z easily yields s=(zrz)/kz.

Intersection with a meridional plane with equation sinφx=cosφy yields

s=rxsinφrycosφkxsinφkycosφ

Intersection with a vertical cylinder centered on the origin with equation x2+y2=R2 yields a quadratic equation of the form s2+2bs+c=0 with

b=rxkx+rykykx2+ky2c=rx2+ry2R2kx2+ky2

◆ phimax()

double CylindricalCell::phimax ( ) const
inline

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

◆ phimin()

double CylindricalCell::phimin ( ) const
inline

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

◆ Rmax()

double CylindricalCell::Rmax ( ) const
inline

This function returns the Rmax border coordinate of the cell.

◆ Rmin()

double CylindricalCell::Rmin ( ) const
inline

This function returns the Rmin border coordinate of the cell.

◆ volume()

double CylindricalCell::volume ( ) const

This function returns the volume of the cell, given by 12(Rmax2Rmin2)(φmaxφmin)(zmaxzmin).

◆ zmax()

double CylindricalCell::zmax ( ) const
inline

This function returns the zmax border coordinate of the cell.

◆ zmin()

double CylindricalCell::zmin ( ) const
inline

This function returns the zmin border coordinate of the cell.


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