Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::math::TSphere< T > Class Template Referencefinal

A sphere in 3-D space. More...

#include <TSphere.h>

Public Member Functions

 TSphere ()=default
 
 TSphere (T radius)
 
bool isIntersecting (const TLineSegment< T > &segment, real *out_hitT) const
 Checks whether the segment is interseting with this sphere.
 
bool isInside (const TVector3< T > &point) const
 Same as isIntersecting(), except the cost is slightly higher to reduce numerical error.
 
getRadius () const
 
getArea () const
 
TAABB3D< T > getAABB () const
 
bool mayOverlapVolume (const TAABB3D< T > &volume) const
 Conservatively checks whether this sphere overlaps a volume. By conservative, it means true can be returned even though the sphere does not overlap the volume; but if it actually does, true must be returned. The test considers the sphere as hollow and the volume is solid.
 
uniformSurfaceSamplePdfA () const
 
TVector2< T > surfaceToLatLong01 (const TVector3< T > &surface) const
 
TVector2< T > latLong01ToPhiTheta (const TVector2< T > &latLong01) const
 
TVector3< T > latLong01ToSurface (const TVector2< T > &latLong01) const
 
TVector2< T > surfaceToPhiTheta (const TVector3< T > &surface) const
 Map Cartesian to spherical coordinates on the surface of the sphere.
 
TVector3< T > phiThetaToSurface (const TVector2< T > &phiTheta) const
 Map spherical to Cartesian coordinates on the surface of the sphere.
 
template<typename SurfaceToUv >
std::pair< TVector3< T >, TVector3< T > > surfaceDerivativesWrtUv (const TVector3< T > &surface, SurfaceToUv surfaceToUv, T hInRadians=to_radians< T >(1)) const
 Calculate dPdU and dPdV with finite difference.
 
Map 2-D sample to a position on the surface.
TVector3< T > sampleToSurfaceArchimedes (const std::array< T, 2 > &sample) const
 
TVector3< T > sampleToSurfaceArchimedes (const std::array< T, 2 > &sample, T *out_pdfA) const
 
TVector3< T > sampleToSurfaceAbsCosThetaWeighted (const std::array< T, 2 > &sample) const
 
TVector3< T > sampleToSurfaceAbsCosThetaWeighted (const std::array< T, 2 > &sample, T *out_pdfA) const
 

Static Public Member Functions

static TSphere makeUnit ()
 

Detailed Description

template<typename T>
class ph::math::TSphere< T >

A sphere in 3-D space.

The center of the sphere is at the origin.

Constructor & Destructor Documentation

◆ TSphere() [1/2]

template<typename T >
ph::math::TSphere< T >::TSphere ( )
default

◆ TSphere() [2/2]

template<typename T >
ph::math::TSphere< T >::TSphere ( T radius)
inlineexplicit
Parameters
radiusRadius of the sphere.

Member Function Documentation

◆ getAABB()

template<typename T >
TAABB3D< T > ph::math::TSphere< T >::getAABB ( ) const
inline

◆ getArea()

template<typename T >
T ph::math::TSphere< T >::getArea ( ) const
inline

◆ getRadius()

template<typename T >
T ph::math::TSphere< T >::getRadius ( ) const
inline

◆ isInside()

template<typename T >
bool ph::math::TSphere< T >::isInside ( const TVector3< T > & point) const
inline

Same as isIntersecting(), except the cost is slightly higher to reduce numerical error.

◆ isIntersecting()

template<typename T >
bool ph::math::TSphere< T >::isIntersecting ( const TLineSegment< T > & segment,
real * out_hitT ) const
inline

Checks whether the segment is interseting with this sphere.

Parameters
segmentThe line section to intersect with.
[out]out_hitTThe parametric distance of the hit point for segment.

◆ latLong01ToPhiTheta()

template<typename T >
TVector2< T > ph::math::TSphere< T >::latLong01ToPhiTheta ( const TVector2< T > & latLong01) const
inline

◆ latLong01ToSurface()

template<typename T >
TVector3< T > ph::math::TSphere< T >::latLong01ToSurface ( const TVector2< T > & latLong01) const
inline

◆ makeUnit()

template<typename T >
TSphere< T > ph::math::TSphere< T >::makeUnit ( )
inlinestatic

◆ mayOverlapVolume()

template<typename T >
bool ph::math::TSphere< T >::mayOverlapVolume ( const TAABB3D< T > & volume) const
inline

Conservatively checks whether this sphere overlaps a volume. By conservative, it means true can be returned even though the sphere does not overlap the volume; but if it actually does, true must be returned. The test considers the sphere as hollow and the volume is solid.

◆ phiThetaToSurface()

template<typename T >
TVector3< T > ph::math::TSphere< T >::phiThetaToSurface ( const TVector2< T > & phiTheta) const
inline

Map spherical to Cartesian coordinates on the surface of the sphere.

◆ sampleToSurfaceAbsCosThetaWeighted() [1/2]

template<typename T >
TVector3< T > ph::math::TSphere< T >::sampleToSurfaceAbsCosThetaWeighted ( const std::array< T, 2 > & sample) const
inline

The mapped positions are weighted according to the cosine of the zenith angle.

Parameters
sampleUniform 2-D sample in [0, 1].
Returns
The sampled surface position.

◆ sampleToSurfaceAbsCosThetaWeighted() [2/2]

template<typename T >
TVector3< T > ph::math::TSphere< T >::sampleToSurfaceAbsCosThetaWeighted ( const std::array< T, 2 > & sample,
T * out_pdfA ) const
inline

An overload with PDF.

Parameters
[out]out_pdfAArea domain PDF of sampling this surface position.

◆ sampleToSurfaceArchimedes() [1/2]

template<typename T >
TVector3< T > ph::math::TSphere< T >::sampleToSurfaceArchimedes ( const std::array< T, 2 > & sample) const
inline

A common mapping method that is based on Archimedes' derivation that the horizontal slices of a sphere have equal area. The mapped positions are distributed uniformly if the sample is uniform. For a unit sphere, this method effectively generates normalized directions.

Parameters
sampleUniform 2-D sample in [0, 1].
Returns
The sampled surface position.

◆ sampleToSurfaceArchimedes() [2/2]

template<typename T >
TVector3< T > ph::math::TSphere< T >::sampleToSurfaceArchimedes ( const std::array< T, 2 > & sample,
T * out_pdfA ) const
inline

An overload with PDF.

Parameters
[out]out_pdfAArea domain PDF of sampling this surface position.

◆ surfaceDerivativesWrtUv()

template<typename T >
template<typename SurfaceToUv >
std::pair< TVector3< T >, TVector3< T > > ph::math::TSphere< T >::surfaceDerivativesWrtUv ( const TVector3< T > & surface,
SurfaceToUv surfaceToUv,
T hInRadians = to_radians<T>(1) ) const
inline

Calculate dPdU and dPdV with finite difference.

This is a partial derivatives calculator for arbitrary UV maps; however, as it is only a finite difference approximation, artifacts can occur around the discontinuities of the underlying UV mapping.

Parameters
surfaceCoordinates of the point of interest on the surface.
surfaceToUvA mapper that maps surface coordinates to UV.
hInRadiansHalf inverval in radians used in the finite difference. Should within (0, pi/4].
Returns
A pair containing dPdU and dPdV.

◆ surfaceToLatLong01()

template<typename T >
TVector2< T > ph::math::TSphere< T >::surfaceToLatLong01 ( const TVector3< T > & surface) const
inline

◆ surfaceToPhiTheta()

template<typename T >
TVector2< T > ph::math::TSphere< T >::surfaceToPhiTheta ( const TVector3< T > & surface) const
inline

Map Cartesian to spherical coordinates on the surface of the sphere.

◆ uniformSurfaceSamplePdfA()

template<typename T >
T ph::math::TSphere< T >::uniformSurfaceSamplePdfA ( ) const
inline

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