SuperNOVAS C++ API v1.6
High-precision C/C++ astrometry library
Loading...
Searching...
No Matches
supernovas::Vector Class Reference

A generic 3D spatial vector, expressed in arbitrary units. More...

#include <supernovas.h>

Inheritance diagram for supernovas::Vector:

Public Member Functions

virtual ~Vector ()
const double * _array () const
 Returns the underlying double[3] C array that stores the components of this vector internally.
double abs () const
 Returns the absolute value (length / magnitude) of this vector.
double dot (const Vector &v) const
 Returns the dot product of this vector and the specified other vector.
bool is_zero () const
 Checks if this verctor is a null vector, that is all of its components are zero.
Vector operator* (double r) const
 Scales a vector by a factor, for example to cast it to/from a physical unit.
double operator[] (int idx) const
 Returns the component at the specified index.
Angle phi () const
 Returns the azumithal angle of this vector.
double projection_on (const Vector &v) const
 Returns the projection of this vector along the direction of another vector.
Vector scaled (double factor) const
 Returns a rescaled version of this vector, for example to cast it to/from a physical unit.
Angle theta () const
 Returns the polar angleof this vector, that is the angle from the z axis.
virtual std::string to_string (int decimals=3) const
 Returns a string representation of this vector.
Vector unit_vector () const
 Returns a unit vector in the direction of this vector.
double x () const
 Returns the x component of this vector.
double y () const
 Returns the y component of this vector.
double z () const
 Returns the z component of this vector.
Public Member Functions inherited from supernovas::Validating
bool is_valid () const
 Returns the previously set 'valid' stae of the implementing instance.
 operator bool () const
 Objects that implement Validating can be used in conditionals directly, without explicitly calling is_valid().

Protected Member Functions

 Vector ()
 Instantiates an undefined vector.
 Vector (double x, double y, double z)
 Instantiates a vector from its cartesian components.
bool equals (const Vector &v, double precision) const
 Checks if this vector is the same as another vector, within the specified precision.
Protected Member Functions inherited from supernovas::Validating
 Validating ()
 dummy constructor;

Protected Attributes

double _component [3]
 [arb.u] Array containing the x, y, z components.
Protected Attributes inherited from supernovas::Validating
bool _valid = false
 the state variable.

Detailed Description

A generic 3D spatial vector, expressed in arbitrary units.

See also
Position, Velocity

Constructor & Destructor Documentation

◆ Vector() [1/2]

◆ Vector() [2/2]

supernovas::Vector::Vector ( double x,
double y,
double z )
explicitprotected

Instantiates a vector from its cartesian components.

Parameters
x[arb.u.] x component
y[arb.u.] y component
z[arb.u.] z component

References _component, supernovas::Validating::_valid, abs(), x(), y(), and z().

◆ ~Vector()

virtual supernovas::Vector::~Vector ( )
inlinevirtual

Member Function Documentation

◆ _array()

const double * supernovas::Vector::_array ( ) const

Returns the underlying double[3] C array that stores the components of this vector internally.

Such an array may be used with the SuperNOVAS C functions.

Returns
the uderlying double[3] array that stores the components of this vector.

References _component.

Referenced by supernovas::GeodeticObserver::GeodeticObserver(), supernovas::SolarSystemObserver::SolarSystemObserver(), supernovas::AstrometricPosition::as_equatorial(), supernovas::Site::enu_to_itrs(), supernovas::Site::enu_to_itrs(), supernovas::ScalarVelocity::in_direction(), supernovas::Site::itrs_to_enu(), and supernovas::Site::itrs_to_enu().

◆ abs()

double supernovas::Vector::abs ( ) const

Returns the absolute value (length / magnitude) of this vector.

Returns
the absolute value (length / magnitude) of this vector.

References _component, and novas_vlen().

Referenced by Vector(), supernovas::Velocity::Velocity(), supernovas::Position::distance(), supernovas::ScalarVelocity::in_direction(), supernovas::Position::operator==(), projection_on(), supernovas::Velocity::speed(), and unit_vector().

◆ dot()

double supernovas::Vector::dot ( const Vector & v) const

Returns the dot product of this vector and the specified other vector.

Parameters
vthe other vector
Returns
the dot product of this vector and the argument.

References Vector(), and _component.

Referenced by projection_on().

◆ equals()

bool supernovas::Vector::equals ( const Vector & v,
double precision ) const
protected

Checks if this vector is the same as another vector, within the specified precision.

Parameters
vthe reference vector
precisionprecision for the equality test
Returns
true if this vector is equal to the argument within the specified precision, or else false.

References Vector(), and _component.

Referenced by supernovas::Position::equals(), and supernovas::Velocity::equals().

◆ is_zero()

bool supernovas::Vector::is_zero ( ) const

Checks if this verctor is a null vector, that is all of its components are zero.

Returns
true if this is a null vector, with all components being zero; or else false.

References _component.

Referenced by supernovas::GeocentricObserver::to_string(), supernovas::GeodeticObserver::to_string(), and supernovas::SolarSystemObserver::to_string().

◆ operator*()

Vector supernovas::Vector::operator* ( double r) const

Scales a vector by a factor, for example to cast it to/from a physical unit.

Parameters
rscaling factor on the right-hand side
Returns
a new vector that is the rescaled version of this vector.
See also
operator/()

References Vector(), supernovas::Validating::is_valid(), and scaled().

◆ operator[]()

double supernovas::Vector::operator[] ( int idx) const

Returns the component at the specified index.

Parameters
idx[0:2] The 0-based coordinate index.
Returns
The component value at that index, or else NAN if the index is out of the [0:2] (errno will be set to ERANGE).

References _component.

◆ phi()

Angle supernovas::Vector::phi ( ) const

Returns the azumithal angle of this vector.

Returns
the azimuthal angle φ.
See also
theta()

References _component, and supernovas::Validating::is_valid().

◆ projection_on()

double supernovas::Vector::projection_on ( const Vector & v) const

Returns the projection of this vector along the direction of another vector.

Parameters
vthe other vector
Returns
the projection of this vector along the direction of the argument vector.

References Vector(), abs(), and dot().

◆ scaled()

Vector supernovas::Vector::scaled ( double factor) const

Returns a rescaled version of this vector, for example to cast it to/from a physical unit.

Parameters
factorscaling factor, such as a cast to/from a physical unit
Returns
a new vector that is the rescaled version of this vector with the specified scaling factor.

References Vector(), _component, and supernovas::Validating::is_valid().

Referenced by supernovas::GeodeticObserver::GeodeticObserver(), supernovas::SolarSystemObserver::SolarSystemObserver(), operator*(), and unit_vector().

◆ theta()

Angle supernovas::Vector::theta ( ) const

Returns the polar angleof this vector, that is the angle from the z axis.

Returns
the polar angle θ.
See also
phi()

References _component, and supernovas::Validating::is_valid().

◆ to_string()

std::string supernovas::Vector::to_string ( int decimals = 3) const
virtual

Returns a string representation of this vector.

Parameters
decimals(optional) the numberof decimal places to print for the components (default: 3).
Returns

Reimplemented in supernovas::AstrometricPosition, supernovas::Position, and supernovas::Velocity.

References _component.

◆ unit_vector()

Vector supernovas::Vector::unit_vector ( ) const

Returns a unit vector in the direction of this vector.

Returns
a new unit vector in the same direction as this vector.

References Vector(), abs(), supernovas::Validating::is_valid(), and scaled().

◆ x()

◆ y()

◆ z()

Member Data Documentation

◆ _component

double supernovas::Vector::_component[3]
protected