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 Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | List of all members
scifir::coordinates_2dr< T > Class Template Reference

#include <coordinates_2dr.hpp>

Collaboration diagram for scifir::coordinates_2dr< T >:
Collaboration graph
[legend]

Public Member Functions

 coordinates_2dr ()
 
 coordinates_2dr (const coordinates_2dr< T > &x_coordinates)
 
 coordinates_2dr (coordinates_2dr< T > &&x_coordinates)
 
 coordinates_2dr (const scalar_unit &new_x, const scalar_unit &new_y, const angle &new_theta)
 
 coordinates_2dr (const scalar_unit &new_p, const angle &new_polar_theta, const angle &new_theta)
 
template<typename U >
 coordinates_2dr (const scifir::coordinates_2d< U > &new_coordinates, const angle &new_theta)
 
template<typename U >
 coordinates_2dr (scifir::coordinates_2d< U > &&new_coordinates, const angle &new_theta)
 
 coordinates_2dr (const string &init_coordinates_2dr)
 
coordinates_2dr< T > & operator= (const coordinates_2dr< T > &x_coordinates)
 
coordinates_2dr< T > & operator= (coordinates_2dr< T > &&x_coordinates)
 
coordinates_2dr< T > & operator= (const coordinates_2d< T > &x_coordinates)
 
coordinates_2dr< T > & operator= (coordinates_2d< T > &&x_coordinates)
 
coordinates_2dr< T > & operator= (const string &init_coordinates_2dr)
 
T get_p () const
 
angle get_polar_theta () const
 
void point_to (direction::name x)
 
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_2dr< Torigin (const coordinates_2dr< T > &origin, const coordinates_2dr< T > &coordinates)
 

Public Attributes

T x
 
T y
 
angle theta
 

Private Member Functions

void initialize_from_string (string init_coordinates_2dr)
 

Detailed Description

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

Definition at line 17 of file coordinates_2dr.hpp.

Constructor & Destructor Documentation

◆ coordinates_2dr() [1/8]

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

◆ coordinates_2dr() [2/8]

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

Definition at line 23 of file coordinates_2dr.hpp.

23 : x(x_coordinates.x),y(x_coordinates.y),theta(x_coordinates.theta)
24 {}

◆ coordinates_2dr() [3/8]

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

Definition at line 26 of file coordinates_2dr.hpp.

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

◆ coordinates_2dr() [4/8]

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

Definition at line 29 of file coordinates_2dr.hpp.

29 : x(new_x),y(new_y),theta(new_theta)
30 {}

◆ coordinates_2dr() [5/8]

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

Definition at line 32 of file coordinates_2dr.hpp.

32 : x(),y(),theta(new_theta)
33 {
34 set_position(new_p,new_polar_theta);
35 }
void set_position(const scalar_unit &new_x, const scalar_unit &new_y)

◆ coordinates_2dr() [6/8]

template<typename T = length>
template<typename U >
scifir::coordinates_2dr< T >::coordinates_2dr ( const scifir::coordinates_2d< U > &  new_coordinates,
const angle new_theta 
)
inlineexplicit

Definition at line 38 of file coordinates_2dr.hpp.

38 : x(new_coordinates.x),y(new_coordinates.y),theta(new_theta)
39 {}

◆ coordinates_2dr() [7/8]

template<typename T = length>
template<typename U >
scifir::coordinates_2dr< T >::coordinates_2dr ( scifir::coordinates_2d< U > &&  new_coordinates,
const angle new_theta 
)
inlineexplicit

Definition at line 42 of file coordinates_2dr.hpp.

42 : x(std::move(new_coordinates.x)),y(std::move(new_coordinates.y)),theta(new_theta)
43 {}

◆ coordinates_2dr() [8/8]

template<typename T = length>
scifir::coordinates_2dr< T >::coordinates_2dr ( const string init_coordinates_2dr)
inlineexplicit

Definition at line 45 of file coordinates_2dr.hpp.

46 {
47 initialize_from_string(init_coordinates_2dr);
48 }
void initialize_from_string(string init_coordinates_2dr)

Member Function Documentation

◆ display_cartesian()

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

Definition at line 182 of file coordinates_2dr.hpp.

183 {
184 ostringstream out;
185 out << "(" << x << "," << y << ";" << theta << ")";
186 return out.str();
187 }

◆ display_polar()

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

Definition at line 189 of file coordinates_2dr.hpp.

190 {
191 ostringstream out;
192 out << "(" << get_p() << "," << get_polar_theta() << ";" << theta << ")";
193 return out.str();
194 }

◆ distance_to_origin()

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

Definition at line 177 of file coordinates_2dr.hpp.

178 {
179 return T(scifir::sqrt(scifir::pow(x,2) + scifir::pow(y,2)));
180 }
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_2dr< T >::get_p ( ) const
inline

Definition at line 93 of file coordinates_2dr.hpp.

94 {
95 return T(scifir::sqrt(scifir::pow(x,2) + scifir::pow(y,2)));
96 }

◆ get_polar_theta()

template<typename T = length>
angle scifir::coordinates_2dr< T >::get_polar_theta ( ) const
inline

Definition at line 98 of file coordinates_2dr.hpp.

99 {
100 return scifir::atan2(y.get_value(),x.get_value());
101 }
angle atan2(float y, float x)
Definition angle.cpp:456

◆ initialize_from_string()

template<typename T = length>
void scifir::coordinates_2dr< T >::initialize_from_string ( string  init_coordinates_2dr)
inlineprivate

Definition at line 201 of file coordinates_2dr.hpp.

202 {
203 vector<string> init_coordinates;
204 vector<string> init_values;
205 vector<string> init_angles;
206 if (init_coordinates_2dr.front() == '(')
207 {
208 init_coordinates_2dr.erase(0,1);
209 }
210 if (init_coordinates_2dr.back() == ')')
211 {
212 init_coordinates_2dr.erase(init_coordinates_2dr.size()-1,1);
213 }
214 boost::split(init_coordinates,init_coordinates_2dr,boost::is_any_of(";"));
215 if (init_coordinates.size() > 0)
216 {
217 boost::split(init_values,init_coordinates[0],boost::is_any_of(","));
218 }
219 if (init_coordinates.size() > 1)
220 {
221 boost::split(init_angles,init_coordinates[1],boost::is_any_of(","));
222 }
223 if (init_values.size() == 2 and init_angles.size() == 1)
224 {
225 if (is_angle(init_values[1]))
226 {
227 set_position(T(init_values[0]),angle(init_values[1]));
228 }
229 else
230 {
231 set_position(T(init_values[0]),T(init_values[1]));
232 }
233 theta = angle(init_angles[0]);
234 }
235 }
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_2dr< T >::move ( const displacement_2d x_displacement)
inline

Definition at line 159 of file coordinates_2dr.hpp.

160 {
161 x += x_displacement.x_projection();
162 y += x_displacement.y_projection();
163 }

◆ move() [2/3]

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

Definition at line 171 of file coordinates_2dr.hpp.

172 {
173 x += new_p * scifir::cos(new_theta);
174 y += new_p * scifir::sin(new_theta);
175 }
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_2dr< T >::move ( const scalar_unit new_x,
const scalar_unit new_y 
)
inline

Definition at line 165 of file coordinates_2dr.hpp.

166 {
167 x += new_x;
168 y += new_y;
169 }

◆ operator=() [1/5]

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

Definition at line 66 of file coordinates_2dr.hpp.

67 {
68 x = x_coordinates.x;
69 y = x_coordinates.y;
70 return *this;
71 }

◆ operator=() [2/5]

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

Definition at line 50 of file coordinates_2dr.hpp.

51 {
52 x = x_coordinates.x;
53 y = x_coordinates.y;
54 theta = x_coordinates.theta;
55 return *this;
56 }

◆ operator=() [3/5]

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

Definition at line 80 of file coordinates_2dr.hpp.

81 {
82 initialize_from_string(init_coordinates_2dr);
83 return *this;
84 }

◆ operator=() [4/5]

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

Definition at line 73 of file coordinates_2dr.hpp.

74 {
75 x = std::move(x_coordinates.x);
76 y = std::move(x_coordinates.y);
77 return *this;
78 }

◆ operator=() [5/5]

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

Definition at line 58 of file coordinates_2dr.hpp.

59 {
60 x = std::move(x_coordinates.x);
61 y = std::move(x_coordinates.y);
62 theta = std::move(x_coordinates.theta);
63 return *this;
64 }

◆ origin()

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

Definition at line 86 of file coordinates_2dr.hpp.

87 {
88 coordinates_2dr<T> new_coordinates(origin);
89 new_coordinates.move(coordinates.x,coordinates.y);
90 return new_coordinates;
91 }
static coordinates_2dr< T > origin(const coordinates_2dr< T > &origin, const coordinates_2dr< T > &coordinates)

◆ point_to()

template<typename T = length>
void scifir::coordinates_2dr< T >::point_to ( direction::name  x)
inline

Definition at line 103 of file coordinates_2dr.hpp.

104 {
105 if (x == direction::LEFT)
106 {
107 theta = 180.0f;
108 }
109 else if(x == direction::RIGHT)
110 {
111 theta = 0.0f;
112 }
113 else if(x == direction::TOP)
114 {
115 theta = 90.0f;
116 }
117 else if(x == direction::BOTTOM)
118 {
119 theta = 270.0f;
120 }
121 else if(x == direction::LEFT_TOP)
122 {
123 theta = 135.0f;
124 }
125 else if(x == direction::RIGHT_TOP)
126 {
127 theta = 45.0f;
128 }
129 else if(x == direction::RIGHT_BOTTOM)
130 {
131 theta = 315.0f;
132 }
133 else if(x == direction::LEFT_BOTTOM)
134 {
135 theta = 225.0f;
136 }
137 }

◆ rotate()

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

Definition at line 151 of file coordinates_2dr.hpp.

152 {
153 T x_coord = x;
154 T y_coord = y;
155 x = x_coord * scifir::cos(x_angle) - y_coord * scifir::sin(x_angle);
156 y = x_coord * scifir::sin(x_angle) + y_coord * scifir::cos(x_angle);
157 }

◆ set_position() [1/2]

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

Definition at line 145 of file coordinates_2dr.hpp.

146 {
147 x = T(new_p * scifir::cos(new_theta));
148 y = T(new_p * scifir::sin(new_theta));
149 }

◆ set_position() [2/2]

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

Definition at line 139 of file coordinates_2dr.hpp.

140 {
141 x = new_x;
142 y = new_y;
143 }

Member Data Documentation

◆ theta

template<typename T = length>
angle scifir::coordinates_2dr< T >::theta

Definition at line 198 of file coordinates_2dr.hpp.

◆ x

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

Definition at line 196 of file coordinates_2dr.hpp.

◆ y

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

Definition at line 197 of file coordinates_2dr.hpp.


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