scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | List of all members
scifir::coordinates_2d< T > Class Template Reference

#include <coordinates_2d.hpp>

Public Types

enum  type { CARTESIAN , POLAR }
 

Public Member Functions

 coordinates_2d ()
 
 coordinates_2d (const coordinates_2d< T > &x_coordinates)
 
 coordinates_2d (coordinates_2d< T > &&x_coordinates)
 
 coordinates_2d (const scalar_unit &new_x, const scalar_unit &new_y)
 
 coordinates_2d (const scalar_unit &new_p, const angle &new_theta)
 
 coordinates_2d (coordinates_2d::type coordinates_type, const string &coord1, const string &coord2)
 
 coordinates_2d (const string &init_coordinates_2d)
 
coordinates_2d< T > & operator= (const coordinates_2d< T > &x_coordinates)
 
coordinates_2d< T > & operator= (coordinates_2d< T > &&x_coordinates)
 
coordinates_2d< T > & operator= (const string &init_coordinates_2d)
 
T get_p () const
 
angle get_theta () const
 
void set_position (const scalar_unit &new_x, const scalar_unit &new_y)
 
void set_position (const scalar_unit &new_p, const angle &new_theta)
 
void rotate (const angle &x_angle)
 
void move (const displacement_2d &x_displacement)
 
void move (const scalar_unit &new_x, const scalar_unit &new_y)
 
void move (const scalar_unit &new_p, const angle &new_theta)
 
T distance_to_origin () const
 
string display_cartesian () const
 
string display_polar () const
 

Static Public Member Functions

static coordinates_2d< Torigin (const coordinates_2d< T > &origin, const coordinates_2d< T > &coordinates)
 

Public Attributes

T x
 
T y
 

Private Member Functions

void initialize_from_string (string init_coordinates_2d)
 

Detailed Description

template<typename T = length>
class scifir::coordinates_2d< T >

Definition at line 16 of file coordinates_2d.hpp.

Member Enumeration Documentation

◆ type

Enumerator
CARTESIAN 
POLAR 

Definition at line 19 of file coordinates_2d.hpp.

Constructor & Destructor Documentation

◆ coordinates_2d() [1/7]

template<typename T = length>
scifir::coordinates_2d< T >::coordinates_2d ( )
inline

Definition at line 21 of file coordinates_2d.hpp.

◆ coordinates_2d() [2/7]

template<typename T = length>
scifir::coordinates_2d< T >::coordinates_2d ( const coordinates_2d< T > &  x_coordinates)
inline

Definition at line 24 of file coordinates_2d.hpp.

24 : x(x_coordinates.x),y(x_coordinates.y)
25 {}

◆ coordinates_2d() [3/7]

template<typename T = length>
scifir::coordinates_2d< T >::coordinates_2d ( coordinates_2d< T > &&  x_coordinates)
inline

Definition at line 27 of file coordinates_2d.hpp.

27 : x(std::move(x_coordinates.x)),y(std::move(x_coordinates.y))
28 {}

◆ coordinates_2d() [4/7]

template<typename T = length>
scifir::coordinates_2d< T >::coordinates_2d ( const scalar_unit new_x,
const scalar_unit new_y 
)
inlineexplicit

Definition at line 30 of file coordinates_2d.hpp.

30 : x(new_x),y(new_y)
31 {}

◆ coordinates_2d() [5/7]

template<typename T = length>
scifir::coordinates_2d< T >::coordinates_2d ( const scalar_unit new_p,
const angle new_theta 
)
inlineexplicit

Definition at line 33 of file coordinates_2d.hpp.

34 {
35 set_position(new_p,new_theta);
36 }
void set_position(const scalar_unit &new_x, const scalar_unit &new_y)

◆ coordinates_2d() [6/7]

template<typename T = length>
scifir::coordinates_2d< T >::coordinates_2d ( coordinates_2d< T >::type  coordinates_type,
const string coord1,
const string coord2 
)
inlineexplicit

Definition at line 38 of file coordinates_2d.hpp.

39 {
40 if (coordinates_type == coordinates_2d<length>::CARTESIAN)
41 {
42 set_position(T(coord1),T(coord2));
43 }
44 else if (coordinates_type == coordinates_2d<length>::POLAR)
45 {
46 set_position(T(coord1),angle(coord2));
47 }
48 }

◆ coordinates_2d() [7/7]

template<typename T = length>
scifir::coordinates_2d< T >::coordinates_2d ( const string init_coordinates_2d)
inlineexplicit

Definition at line 50 of file coordinates_2d.hpp.

51 {
52 initialize_from_string(init_coordinates_2d);
53 }
void initialize_from_string(string init_coordinates_2d)

Member Function Documentation

◆ display_cartesian()

template<typename T = length>
string scifir::coordinates_2d< T >::display_cartesian ( ) const
inline

Definition at line 135 of file coordinates_2d.hpp.

136 {
137 ostringstream out;
138 out << "(" << x << "," << y << ")";
139 return out.str();
140 }

◆ display_polar()

template<typename T = length>
string scifir::coordinates_2d< T >::display_polar ( ) const
inline

Definition at line 142 of file coordinates_2d.hpp.

143 {
144 ostringstream out;
145 out << "(" << get_p() << "," << get_theta() << ")";
146 return out.str();
147 }

◆ distance_to_origin()

template<typename T = length>
T scifir::coordinates_2d< T >::distance_to_origin ( ) const
inline

Definition at line 130 of file coordinates_2d.hpp.

131 {
132 return T(scifir::sqrt(scifir::pow(x,2) + scifir::pow(y,2)));
133 }
scalar_unit pow(const scalar_unit &x, int exponent)
Exponentiates a scalar_unit to some numeric type, the dimensions are also exponentiated.
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
Definition angle.cpp:416

◆ get_p()

template<typename T = length>
T scifir::coordinates_2d< T >::get_p ( ) const
inline

Definition at line 82 of file coordinates_2d.hpp.

83 {
84 return T(scifir::sqrt(scifir::pow(x,2) + scifir::pow(y,2)));
85 }

◆ get_theta()

template<typename T = length>
angle scifir::coordinates_2d< T >::get_theta ( ) const
inline

Definition at line 87 of file coordinates_2d.hpp.

88 {
89 return scifir::atan2(y.get_value(),x.get_value());
90 }
angle atan2(float y, float x)
Definition angle.cpp:456

◆ initialize_from_string()

template<typename T = length>
void scifir::coordinates_2d< T >::initialize_from_string ( string  init_coordinates_2d)
inlineprivate

Definition at line 153 of file coordinates_2d.hpp.

154 {
155 vector<string> values;
156 if (init_coordinates_2d.front() == '(')
157 {
158 init_coordinates_2d.erase(0,1);
159 }
160 if (init_coordinates_2d.back() == ')')
161 {
162 init_coordinates_2d.erase(init_coordinates_2d.size()-1,1);
163 }
164 boost::split(values,init_coordinates_2d,boost::is_any_of(","));
165 if (values.size() == 2)
166 {
167 if (is_angle(values[1]))
168 {
169 set_position(T(values[0]),angle(values[1]));
170 }
171 else
172 {
173 set_position(T(values[0]),T(values[1]));
174 }
175 }
176 }
bool is_angle(const string &init_angle)
Checks if some string is an initialization string of an angle.
Definition angle.cpp:336

◆ move() [1/3]

template<typename T = length>
void scifir::coordinates_2d< T >::move ( const displacement_2d x_displacement)
inline

Definition at line 112 of file coordinates_2d.hpp.

113 {
114 x += x_displacement.x_projection();
115 y += x_displacement.y_projection();
116 }

◆ move() [2/3]

template<typename T = length>
void scifir::coordinates_2d< T >::move ( const scalar_unit new_p,
const angle new_theta 
)
inline

Definition at line 124 of file coordinates_2d.hpp.

125 {
126 x += new_p * scifir::cos(new_theta);
127 y += new_p * scifir::sin(new_theta);
128 }
float cos(const angle &x)
Calculates the cos of angle x. It uses the cos() function of the standard library of C++,...
Definition angle.cpp:431
float sin(const angle &x)
Calculates the sin of angle x. It uses the sin() function of the standard library of C++,...
Definition angle.cpp:426

◆ move() [3/3]

template<typename T = length>
void scifir::coordinates_2d< T >::move ( const scalar_unit new_x,
const scalar_unit new_y 
)
inline

Definition at line 118 of file coordinates_2d.hpp.

119 {
120 x += new_x;
121 y += new_y;
122 }

◆ operator=() [1/3]

template<typename T = length>
coordinates_2d< T > & scifir::coordinates_2d< T >::operator= ( const coordinates_2d< T > &  x_coordinates)
inline

Definition at line 55 of file coordinates_2d.hpp.

56 {
57 x = x_coordinates.x;
58 y = x_coordinates.y;
59 return *this;
60 }

◆ operator=() [2/3]

template<typename T = length>
coordinates_2d< T > & scifir::coordinates_2d< T >::operator= ( const string init_coordinates_2d)
inline

Definition at line 69 of file coordinates_2d.hpp.

70 {
71 initialize_from_string(init_coordinates_2d);
72 return *this;
73 }

◆ operator=() [3/3]

template<typename T = length>
coordinates_2d< T > & scifir::coordinates_2d< T >::operator= ( coordinates_2d< T > &&  x_coordinates)
inline

Definition at line 62 of file coordinates_2d.hpp.

63 {
64 x = std::move(x_coordinates.x);
65 y = std::move(x_coordinates.y);
66 return *this;
67 }

◆ origin()

template<typename T = length>
static coordinates_2d< T > scifir::coordinates_2d< T >::origin ( const coordinates_2d< T > &  origin,
const coordinates_2d< T > &  coordinates 
)
inlinestatic

Definition at line 75 of file coordinates_2d.hpp.

76 {
77 coordinates_2d<T> new_coordinates(origin);
78 new_coordinates.move(coordinates.x,coordinates.y);
79 return new_coordinates;
80 }
static coordinates_2d< T > origin(const coordinates_2d< T > &origin, const coordinates_2d< T > &coordinates)

◆ rotate()

template<typename T = length>
void scifir::coordinates_2d< T >::rotate ( const angle x_angle)
inline

Definition at line 104 of file coordinates_2d.hpp.

105 {
106 T x_coord = x;
107 T y_coord = y;
108 x = x_coord * scifir::cos(x_angle) - y_coord * scifir::sin(x_angle);
109 y = x_coord * scifir::sin(x_angle) + y_coord * scifir::cos(x_angle);
110 }

◆ set_position() [1/2]

template<typename T = length>
void scifir::coordinates_2d< T >::set_position ( const scalar_unit new_p,
const angle new_theta 
)
inline

Definition at line 98 of file coordinates_2d.hpp.

99 {
100 x = T(new_p * scifir::cos(new_theta));
101 y = T(new_p * scifir::sin(new_theta));
102 }

◆ set_position() [2/2]

template<typename T = length>
void scifir::coordinates_2d< T >::set_position ( const scalar_unit new_x,
const scalar_unit new_y 
)
inline

Definition at line 92 of file coordinates_2d.hpp.

93 {
94 x = new_x;
95 y = new_y;
96 }

Member Data Documentation

◆ x

template<typename T = length>
T scifir::coordinates_2d< T >::x

Definition at line 149 of file coordinates_2d.hpp.

◆ y

template<typename T = length>
T scifir::coordinates_2d< T >::y

Definition at line 150 of file coordinates_2d.hpp.


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