#include <Direction.hpp>
Public Member Functions | |
Direction () | |
Direction (double kx, double ky, double kz, bool normalize) | |
Direction (double theta, double phi) | |
Direction (Vec k, bool normalize) | |
void | cartesian (double &kx, double &ky, double &kz) const |
double | kx () const |
double | ky () const |
double | kz () const |
Vec & | operator*= (Vec v)=delete |
Vec & | operator+= (Vec v)=delete |
Direction | operator- () const |
Vec & | operator-= (Vec v)=delete |
Vec & | operator/= (Vec v)=delete |
void | set (double kx, double ky, double kz, bool normalize) |
void | set (double, double, double)=delete |
void | set (Vec k, bool normalize) |
void | spherical (double &theta, double &phi) const |
![]() | |
Vec () | |
Vec (double x, double y, double z) | |
void | clear () |
bool | isNull () const |
double | norm () const |
double | norm2 () const |
Vec & | operator*= (double s) |
Vec & | operator+= (Vec v) |
Vec & | operator-= (Vec v) |
Vec & | operator/= (double s) |
void | set (double x, double y, double z) |
double | x () const |
double | y () const |
double | z () const |
Private Member Functions | |
void | normalize () |
Additional Inherited Members | |
![]() | |
static Vec | cross (Vec a, Vec b) |
static double | dot (Vec a, Vec b) |
![]() | |
double | _x |
double | _y |
double | _z |
An object of the Direction class represents a direction in three-dimensional space. In principle only two coordinates are necessary to fully characterize a direction; a possible choice is spherical coordinates on the unit sphere. However in this class, a direction is internally represented by means of its three cartesian coordinates
To assist client code using the Direction class with ensuring this normalization, the constructors and the set() functions offer the Boolean normalize argument. If set to true, the constructor or function will automatically normalize the components passed by the caller. If set to false, the components are copied as given without any further verification. This can be used to avoid redundant calculations in case the caller has already ensured normalization.
An important exception to the normalization invariant occurs when all three direction components are zero, resulting in an invalid "null" direction. This can happen, for example, when constructing a direction from user input or from the cross product of two parallel vectors. In situations where a null direction may occur, client code should test for this using the Vec::isNull() function.
The Direction class is publicly based on the Vec class, and the direction coordinates
|
inline |
The default constructor for the class Direction creates a direction parallel to the
|
inline |
Constructor for a direction with given cartesian coordinates
|
inline |
Constructor for a direction with given cartesian coordinates
Direction::Direction | ( | double | theta, |
double | phi | ||
) |
Constructor for a direction with a given azimuth and polar angle. The cartesian coordinates are calculated as
It is explicitly checked whether
void Direction::cartesian | ( | double & | kx, |
double & | ky, | ||
double & | kz | ||
) | const |
|
inline |
|
inline |
|
inline |
|
private |
This private function normalizes the coordinates already stored in this instance by dividing them by the value of the Vec::norm() function. As an exception, if the norm() function returns zero, all coordinates are set to zero, resulting in an invalid direction. The function is called from constructors and setters for this class in case the client code sets normalize to true.
Disable this compound assignment operator inherited from Vec because it breaks the normalization.
Disable this compound assignment operator inherited from Vec because it breaks the normalization.
|
inline |
This operator returns the opposite direction (negating each coordinate).
Disable this compound assignment operator inherited from Vec because it breaks the normalization.
Disable this compound assignment operator inherited from Vec because it breaks the normalization.
|
inline |
This function sets the direction to the given cartesian coordinates
|
inlinedelete |
Disable the setter inherited from Vec so that callers are forced to specify a normalization option.
|
inline |
This function sets the direction to the given cartesian coordinates
void Direction::spherical | ( | double & | theta, |
double & | phi | ||
) | const |
This function determines the two spherical coordinates