Loading...
Searching...
No Matches
supernovas::Vector Class Reference
Helpers and utilities

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.
Public Member Functions inherited from supernovas::Validating
bool | is_valid () const
| Returns the previously set 'valid' state 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.

Since
  1.6

See also
  Position, Velocity, Interferometric

## Constructor & Destructor Documentation

## Vector() [1/2]

supernovas::Vector::Vector | ( |  | ) |

protected

Instantiates an undefined vector.

References _component.

Referenced by supernovas::Interferometric::Interferometric(), supernovas::Position::Position(), supernovas::Position::Position(), supernovas::Position::Position(), supernovas::Velocity::Velocity(), supernovas::Velocity::Velocity(), dot(), equals(), operator*(), projection_on(), scaled(), and unit_vector().

## Vector() [2/2]

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

explicit protected

Instantiates a vector from its cartesian components.

Parameters

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

Since
  1.6

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

## ~Vector()

virtual supernovas::Vector::~Vector | ( |  | ) |

inline virtual

## 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.

Since
  1.6

References _component.

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

## abs()

double supernovas::Vector::abs | ( |  | ) | const

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

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

Since
  1.6

References _component, and novas_vlen().

Referenced by Vector(), supernovas::Velocity::Velocity(), supernovas::Position::distance(), supernovas::ScalarVelocity::in_direction(), supernovas::Interferometric::operator==(), 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

  v | the other vector

Returns
  the dot product of this vector and the argument.

Since
  1.6

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.

Note, that a vector may not equal itself if it contains NAN or infinite components.

Parameters

  v | the reference vector
  precision | precision for the equality test

Returns
  true if this vector is equal to the argument within the specified precision, or else false.

Since
  1.6

References Vector(), _component, and novas_equals_vector().

Referenced by supernovas::Interferometric::equals(), 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.

Since
  1.6

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

  r | scaling factor on the right-hand side

Returns
  a new vector that is the rescaled version of this vector.

Since
  1.6

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).

Since
  1.6

References _component.

## phi()

Angle supernovas::Vector::phi | ( |  | ) | const

Returns the azumithal angle of this vector.

Returns
  the azimuthal angle φ.

Since
  1.6

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

  v | the other vector

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

Since
  1.6

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

  factor | scaling 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.

Since
  1.6

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

Referenced by supernovas::GeodeticObserver::GeodeticObserver(), supernovas::SolarSystemObserver::SolarSystemObserver(), operator*(), supernovas::AstrometricPosition::to_interferometric(), supernovas::Observer::to_interferometric(), 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 θ.

Since
  1.6

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
  a string representation of this 3D vector.

Since
  1.6

Reimplemented in supernovas::AstrometricPosition, supernovas::Interferometric, 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.

Since
  1.6

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

## Member Data Documentation

## _component

double supernovas::Vector::_component[3]

protected

[arb.u] Array containing the x, y, z components.

Referenced by Vector(), Vector(), _array(), abs(), dot(), equals(), supernovas::Position::inv(), supernovas::Velocity::inv(), is_zero(), supernovas::Interferometric::operator+(), supernovas::Position::operator+(), supernovas::Velocity::operator+(), supernovas::Interferometric::operator-(), supernovas::Position::operator-(), supernovas::Velocity::operator-(), supernovas::Position::operator/(), operator[](), phi(), scaled(), theta(), supernovas::Position::to_spherical(), supernovas::Position::to_string(), to_string(), supernovas::Velocity::to_string(), supernovas::Velocity::travel(), supernovas::Interferometric::u(), supernovas::Interferometric::v(), supernovas::Interferometric::w(), supernovas::Position::x(), supernovas::Velocity::x(), supernovas::Position::y(), supernovas::Velocity::y(), supernovas::Position::z(), and supernovas::Velocity::z().