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 | Public Attributes | Private Member Functions | List of all members
scifir::coordinates_3d< float > Class Reference

Specialization of coordinates_3d, with the same behaviour and functions, that is specialized for float types. It can be used when it's needed to save memory, because a float uses less memory than a scalar_unit. More...

#include <coordinates_3d.hpp>

Public Member Functions

 coordinates_3d ()
 Default constructor. Initializes x, y and z to 0, with the default dimensions.
 
 coordinates_3d (const coordinates_3d< float > &x_coordinates)
 Copy constructor. Initializes x, y and z to the x, y and z of x_coordinates.
 
 coordinates_3d (coordinates_3d< float > &&x_coordinates)
 Move constructor. Initializes x, y and z to the x, y and z of x_coordinates.
 
 coordinates_3d (float new_x, float new_y, float new_z)
 Constructor. Initializes x, y and z to be new_x, new_y and new_z.
 
 coordinates_3d (float new_p, const angle &new_theta, float new_z)
 Constructor. Initializes x, y and z with cylindrical coordinates.
 
 coordinates_3d (float new_r, const angle &new_theta, const angle &new_phi)
 Constructor. Initializes x, y and z with spherical coordinates.
 
 coordinates_3d (const angle &new_latitude, const angle &new_longitude, float new_altitude)
 Constructor. Initializes x, y and z with geographical coordinates. Currently geographical coordinates aren't ready.
 
 coordinates_3d (coordinates_3d< length >::type coordinates_type, const string &coord1, const string &coord2, const string &coord3)
 
 coordinates_3d (const string &init_coordinates_3d)
 Constructor. Initializes x, y and z with the initialization string of coordinates_3d init_coordinates_3d.
 
coordinates_3d< float > & operator= (const coordinates_3d< float > &x_coordinates)
 Copy assignment. Assigns x, y and z to the same values as the x, y and z of x_coordinates.
 
coordinates_3d< float > & operator= (coordinates_3d< float > &&x_coordinates)
 Move assignment. Assigns x, y and z moved from the x, y and z of x_coordinates.
 
coordinates_3d< float > & operator= (const string &init_coordinates_3d)
 Assignment. Assigns x, y and z to the values specified in the initialization string of coordinates_3d init_coordinates_3d.
 
float get_p () const
 Returns the value of p in cylindrical coordinates.
 
angle get_theta () const
 Returns the value of theta in cylindrical and spherical coordinates (it's the same theta).
 
float get_r () const
 Returns the value of r in spherical coordinates.
 
angle get_phi () const
 Returns the value of phi in spherical coordinates.
 
latitude get_latitude () const
 Returns the latitude in geographical coordinates. In this case, coordinates_3d represents all the astronomical object surrounded by an imaginary sphere of the geographical coordinates.
 
longitude get_longitude () const
 Returns the longitude in geographical coordinates. In this case, coordinates_3d represents all the astronomical object surrounded by an imaginary sphere of the geographical coordinates.
 
float get_altitude () const
 Returns the altitude in geographical coordinates. In this case, coordinates_3d represents all the astronomical object surrounded by an imaginary sphere of the geographical coordinates.
 
void set_position (float new_x, float new_y, float new_z)
 Sets x, y and z to the new_x, new_y and new_z.
 
void set_position (float new_p, const angle &new_theta, float new_z)
 Sets x, y and z calculated from the cylindrical coordinates given.
 
void set_position (float new_r, const angle &new_theta, const angle &new_phi)
 Sets x, y and z calculated from the spherical coordinates given.
 
void set_position (const angle &new_latitude, const angle &new_longitude, float new_altitude)
 Sets x, y and z calculated from the geographical coordinates given.
 
void rotate_in_x (const angle &x_angle)
 Rotates around the edge x the amount of the param x_angle.
 
void rotate_in_y (const angle &x_angle)
 Rotates around the edge y the amount of the param x_angle.
 
void rotate_in_z (const angle &x_angle)
 Rotates around the edge z the amount of the param x_angle.
 
void move (const displacement_3d &x_displacement)
 Moves x, y and z in the vector x_displacement given.
 
void move (float new_x, float new_y, float new_z)
 Moves x in new_x, y in new_y and z in new_z.
 
void move (float new_p, const angle &new_theta, float new_z)
 Moves x, y and z in the cylindrical coordinates given.
 
void move (float new_r, const angle &new_theta, const angle &new_phi)
 Moves x, y and z in the spherical coordinates given.
 
float distance_to_origin () const
 Calculates the distance to the origin.
 
string display_cartesian () const
 Displays the coordinates in cartesian coordinates.
 
string display_cylindrical () const
 Displays the coordinates in cylindrical coordinates.
 
string display_spherical () const
 Displays the coordinates in spherical coordinates.
 
string display_geographical () const
 Displays the coordinates in geographical coordinates.
 

Public Attributes

float x
 The position in the edge x, with type float.
 
float y
 The position in the edge y, with type float.
 
float z
 The position in the edge z, with type float.
 

Private Member Functions

void initialize_from_string (string init_coordinates_3d)
 Internal function. Initializes x, y and z with the initialization string of coordinates_3d init_coordinates_3d.
 

Detailed Description

Specialization of coordinates_3d, with the same behaviour and functions, that is specialized for float types. It can be used when it's needed to save memory, because a float uses less memory than a scalar_unit.

Definition at line 423 of file coordinates_3d.hpp.

Constructor & Destructor Documentation

◆ coordinates_3d() [1/9]

scifir::coordinates_3d< float >::coordinates_3d ( )
inline

Default constructor. Initializes x, y and z to 0, with the default dimensions.

Definition at line 426 of file coordinates_3d.hpp.

426 : x(),y(),z()
427 {}
float y
The position in the edge y, with type float.
float x
The position in the edge x, with type float.
float z
The position in the edge z, with type float.

◆ coordinates_3d() [2/9]

scifir::coordinates_3d< float >::coordinates_3d ( const coordinates_3d< float > &  x_coordinates)
inline

Copy constructor. Initializes x, y and z to the x, y and z of x_coordinates.

Definition at line 429 of file coordinates_3d.hpp.

429 : x(x_coordinates.x),y(x_coordinates.y),z(x_coordinates.z)
430 {}

◆ coordinates_3d() [3/9]

scifir::coordinates_3d< float >::coordinates_3d ( coordinates_3d< float > &&  x_coordinates)
inline

Move constructor. Initializes x, y and z to the x, y and z of x_coordinates.

Definition at line 432 of file coordinates_3d.hpp.

432 : x(std::move(x_coordinates.x)),y(std::move(x_coordinates.y)),z(std::move(x_coordinates.z))
433 {}

◆ coordinates_3d() [4/9]

scifir::coordinates_3d< float >::coordinates_3d ( float  new_x,
float  new_y,
float  new_z 
)
inlineexplicit

Constructor. Initializes x, y and z to be new_x, new_y and new_z.

Definition at line 435 of file coordinates_3d.hpp.

435 : x(new_x),y(new_y),z(new_z)
436 {}

◆ coordinates_3d() [5/9]

scifir::coordinates_3d< float >::coordinates_3d ( float  new_p,
const angle new_theta,
float  new_z 
)
inlineexplicit

Constructor. Initializes x, y and z with cylindrical coordinates.

Definition at line 438 of file coordinates_3d.hpp.

439 {
440 set_position(new_p,new_theta,new_z);
441 }
void set_position(float new_x, float new_y, float new_z)
Sets x, y and z to the new_x, new_y and new_z.

◆ coordinates_3d() [6/9]

scifir::coordinates_3d< float >::coordinates_3d ( float  new_r,
const angle new_theta,
const angle new_phi 
)
inlineexplicit

Constructor. Initializes x, y and z with spherical coordinates.

Definition at line 443 of file coordinates_3d.hpp.

444 {
445 set_position(new_r,new_theta,new_phi);
446 }

◆ coordinates_3d() [7/9]

scifir::coordinates_3d< float >::coordinates_3d ( const angle new_latitude,
const angle new_longitude,
float  new_altitude 
)
inlineexplicit

Constructor. Initializes x, y and z with geographical coordinates. Currently geographical coordinates aren't ready.

Definition at line 448 of file coordinates_3d.hpp.

449 {
450 set_position(new_latitude,new_longitude,new_altitude);
451 }
coordinates_3d()
Default constructor. Initializes x, y and z to 0, with the default dimensions.

◆ coordinates_3d() [8/9]

scifir::coordinates_3d< float >::coordinates_3d ( coordinates_3d< length >::type  coordinates_type,
const string coord1,
const string coord2,
const string coord3 
)
inlineexplicit

Definition at line 453 of file coordinates_3d.hpp.

454 {
455 if (coordinates_type == coordinates_3d<length>::CARTESIAN)
456 {
457 set_position(stof(coord1),stof(coord2),stof(coord3));
458 }
459 else if (coordinates_type == coordinates_3d<length>::CYLINDRICAL)
460 {
461 set_position(stof(coord1),angle(coord2),stof(coord3));
462 }
463 else if (coordinates_type == coordinates_3d<length>::SPHERICAL)
464 {
465 set_position(stof(coord1),angle(coord2),angle(coord3));
466 }
467 else if (coordinates_type == coordinates_3d<length>::GEODESIC)
468 {
469 set_position(angle(coord1),angle(coord2),stof(coord3));
470 }
471 }

◆ coordinates_3d() [9/9]

scifir::coordinates_3d< float >::coordinates_3d ( const string init_coordinates_3d)
inlineexplicit

Constructor. Initializes x, y and z with the initialization string of coordinates_3d init_coordinates_3d.

Definition at line 473 of file coordinates_3d.hpp.

474 {
475 initialize_from_string(init_coordinates_3d);
476 }
void initialize_from_string(string init_coordinates_3d)
Internal function. Initializes x, y and z with the initialization string of coordinates_3d init_coord...

Member Function Documentation

◆ display_cartesian()

string scifir::coordinates_3d< float >::display_cartesian ( ) const
inline

Displays the coordinates in cartesian coordinates.

Definition at line 620 of file coordinates_3d.hpp.

621 {
622 ostringstream out;
623 out << "(" << display_float(x) << "," << display_float(y) << "," << display_float(z) << ")";
624 return out.str();
625 }
string display_float(const float &value, int number_of_decimals)
Definition types.cpp:36

◆ display_cylindrical()

string scifir::coordinates_3d< float >::display_cylindrical ( ) const
inline

Displays the coordinates in cylindrical coordinates.

Definition at line 627 of file coordinates_3d.hpp.

628 {
629 ostringstream out;
630 out << "(" << display_float(get_p()) << "," << get_theta() << "," << display_float(z) << ")";
631 return out.str();
632 }
angle get_theta() const
Returns the value of theta in cylindrical and spherical coordinates (it's the same theta).
float get_p() const
Returns the value of p in cylindrical coordinates.

◆ display_geographical()

string scifir::coordinates_3d< float >::display_geographical ( ) const
inline

Displays the coordinates in geographical coordinates.

Definition at line 641 of file coordinates_3d.hpp.

642 {
643 ostringstream out;
644 out << "(" << get_latitude() << "," << get_longitude() << "," << display_float(get_altitude()) << ")";
645 return out.str();
646 }
longitude get_longitude() const
Returns the longitude in geographical coordinates. In this case, coordinates_3d represents all the as...
float get_altitude() const
Returns the altitude in geographical coordinates. In this case, coordinates_3d represents all the ast...
latitude get_latitude() const
Returns the latitude in geographical coordinates. In this case, coordinates_3d represents all the ast...

◆ display_spherical()

string scifir::coordinates_3d< float >::display_spherical ( ) const
inline

Displays the coordinates in spherical coordinates.

Definition at line 634 of file coordinates_3d.hpp.

635 {
636 ostringstream out;
637 out << "(" << display_float(get_r()) << "," << get_theta() << "," << get_phi() << ")";
638 return out.str();
639 }
float get_r() const
Returns the value of r in spherical coordinates.
angle get_phi() const
Returns the value of phi in spherical coordinates.

◆ distance_to_origin()

float scifir::coordinates_3d< float >::distance_to_origin ( ) const
inline

Calculates the distance to the origin.

Definition at line 615 of file coordinates_3d.hpp.

616 {
617 return float(std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)));
618 }

◆ get_altitude()

float scifir::coordinates_3d< float >::get_altitude ( ) const
inline

Returns the altitude in geographical coordinates. In this case, coordinates_3d represents all the astronomical object surrounded by an imaginary sphere of the geographical coordinates.

Definition at line 530 of file coordinates_3d.hpp.

531 {
532 return ECEF_to_LLA_altitude(x,y,z);
533 }
scalar_unit ECEF_to_LLA_altitude(const scalar_unit &x, scalar_unit y, const scalar_unit &z)

◆ get_latitude()

angle scifir::coordinates_3d< float >::get_latitude ( ) const
inline

Returns the latitude in geographical coordinates. In this case, coordinates_3d represents all the astronomical object surrounded by an imaginary sphere of the geographical coordinates.

Definition at line 520 of file coordinates_3d.hpp.

521 {
522 return ECEF_to_LLA_latitude(x,y,z);
523 }
latitude ECEF_to_LLA_latitude(const scalar_unit &x, scalar_unit y, const scalar_unit &z)

◆ get_longitude()

angle scifir::coordinates_3d< float >::get_longitude ( ) const
inline

Returns the longitude in geographical coordinates. In this case, coordinates_3d represents all the astronomical object surrounded by an imaginary sphere of the geographical coordinates.

Definition at line 525 of file coordinates_3d.hpp.

526 {
527 return ECEF_to_LLA_longitude(x,y,z);
528 }
longitude ECEF_to_LLA_longitude(const scalar_unit &x, scalar_unit y, const scalar_unit &z)

◆ get_p()

float scifir::coordinates_3d< float >::get_p ( ) const
inline

Returns the value of p in cylindrical coordinates.

Definition at line 500 of file coordinates_3d.hpp.

501 {
502 return float(std::sqrt(std::pow(x,2) + std::pow(y,2)));
503 }

◆ get_phi()

angle scifir::coordinates_3d< float >::get_phi ( ) const
inline

Returns the value of phi in spherical coordinates.

Definition at line 515 of file coordinates_3d.hpp.

516 {
517 return angle(scifir::acos_degree(float(z/std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)))));
518 }
float acos_degree(float x)
Calculates the acos receiving x in degrees. It uses the acos() function of the standard library of C+...
Definition angle.hpp:247

◆ get_r()

float scifir::coordinates_3d< float >::get_r ( ) const
inline

Returns the value of r in spherical coordinates.

Definition at line 510 of file coordinates_3d.hpp.

511 {
512 return float(std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)));
513 }

◆ get_theta()

angle scifir::coordinates_3d< float >::get_theta ( ) const
inline

Returns the value of theta in cylindrical and spherical coordinates (it's the same theta).

Definition at line 505 of file coordinates_3d.hpp.

506 {
507 return scifir::atan(float(y/x));
508 }
angle atan(float x)
Calculates the atan of some value x and returns the result as angle in degrees.
Definition angle.cpp:451

◆ initialize_from_string()

void scifir::coordinates_3d< float >::initialize_from_string ( string  init_coordinates_3d)
inlineprivate

Internal function. Initializes x, y and z with the initialization string of coordinates_3d init_coordinates_3d.

Definition at line 653 of file coordinates_3d.hpp.

654 {
655 vector<string> values;
656 if (init_coordinates_3d.front() == '(')
657 {
658 init_coordinates_3d.erase(0,1);
659 }
660 if (init_coordinates_3d.back() == ')')
661 {
662 init_coordinates_3d.erase(init_coordinates_3d.size()-1,1);
663 }
664 boost::split(values,init_coordinates_3d,boost::is_any_of(","));
665 if (values.size() == 3)
666 {
667 if (values[0] == "" or values[1] == "" or values[2] == "")
668 {
669 return;
670 }
671 if (is_latitude(values[0]))
672 {
673 if (is_longitude(values[1]))
674 {
675 if (!is_angle(values[2]))
676 {
677 set_position(angle(values[0]),angle(values[1]),stof(values[2]));
678 }
679 }
680 }
681 else
682 {
683 if (is_angle(values[1]))
684 {
685 if (is_angle(values[2]))
686 {
687 set_position(stof(values[0]),angle(values[1]),angle(values[2]));
688 }
689 else
690 {
691 set_position(stof(values[0]),angle(values[1]),stof(values[2]));
692 }
693 }
694 else
695 {
696 if (!is_angle(values[2]))
697 {
698 set_position(stof(values[0]),stof(values[1]),stof(values[2]));
699 }
700 }
701 }
702 }
703 }
bool is_latitude(const string &init_latitude)
Definition latitude.cpp:199
bool is_longitude(const string &init_longitude)
bool is_angle(const string &init_angle)
Checks if some string is an initialization string of an angle.
Definition angle.cpp:336

◆ move() [1/4]

void scifir::coordinates_3d< float >::move ( const displacement_3d x_displacement)
inline

Moves x, y and z in the vector x_displacement given.

Definition at line 587 of file coordinates_3d.hpp.

588 {
589 x += float(x_displacement.x_projection());
590 y += float(x_displacement.y_projection());
591 z += float(x_displacement.z_projection());
592 }

◆ move() [2/4]

void scifir::coordinates_3d< float >::move ( float  new_p,
const angle new_theta,
float  new_z 
)
inline

Moves x, y and z in the cylindrical coordinates given.

Definition at line 601 of file coordinates_3d.hpp.

602 {
603 x += new_p * scifir::cos(new_theta);
604 y += new_p * scifir::sin(new_theta);
605 z += new_z;
606 }
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/4]

void scifir::coordinates_3d< float >::move ( float  new_r,
const angle new_theta,
const angle new_phi 
)
inline

Moves x, y and z in the spherical coordinates given.

Definition at line 608 of file coordinates_3d.hpp.

609 {
610 x += new_r * scifir::cos(new_theta) * scifir::sin(new_phi);
611 y += new_r * scifir::sin(new_theta) * scifir::sin(new_phi);
612 z += new_r * scifir::cos(new_phi);
613 }

◆ move() [4/4]

void scifir::coordinates_3d< float >::move ( float  new_x,
float  new_y,
float  new_z 
)
inline

Moves x in new_x, y in new_y and z in new_z.

Definition at line 594 of file coordinates_3d.hpp.

595 {
596 x += new_x;
597 y += new_y;
598 z += new_z;
599 }

◆ operator=() [1/3]

coordinates_3d< float > & scifir::coordinates_3d< float >::operator= ( const coordinates_3d< float > &  x_coordinates)
inline

Copy assignment. Assigns x, y and z to the same values as the x, y and z of x_coordinates.

Definition at line 478 of file coordinates_3d.hpp.

479 {
480 x = x_coordinates.x;
481 y = x_coordinates.y;
482 z = x_coordinates.z;
483 return *this;
484 }

◆ operator=() [2/3]

coordinates_3d< float > & scifir::coordinates_3d< float >::operator= ( const string init_coordinates_3d)
inline

Assignment. Assigns x, y and z to the values specified in the initialization string of coordinates_3d init_coordinates_3d.

Definition at line 494 of file coordinates_3d.hpp.

495 {
496 initialize_from_string(init_coordinates_3d);
497 return *this;
498 }

◆ operator=() [3/3]

coordinates_3d< float > & scifir::coordinates_3d< float >::operator= ( coordinates_3d< float > &&  x_coordinates)
inline

Move assignment. Assigns x, y and z moved from the x, y and z of x_coordinates.

Definition at line 486 of file coordinates_3d.hpp.

487 {
488 x = std::move(x_coordinates.x);
489 y = std::move(x_coordinates.y);
490 z = std::move(x_coordinates.z);
491 return *this;
492 }

◆ rotate_in_x()

void scifir::coordinates_3d< float >::rotate_in_x ( const angle x_angle)
inline

Rotates around the edge x the amount of the param x_angle.

Definition at line 563 of file coordinates_3d.hpp.

564 {
565 float y_coord = y;
566 float z_coord = z;
567 y = y_coord * scifir::cos(x_angle) - z_coord * scifir::sin(x_angle);
568 z = y_coord * scifir::sin(x_angle) + z_coord * scifir::cos(x_angle);
569 }

◆ rotate_in_y()

void scifir::coordinates_3d< float >::rotate_in_y ( const angle x_angle)
inline

Rotates around the edge y the amount of the param x_angle.

Definition at line 571 of file coordinates_3d.hpp.

572 {
573 float x_coord = x;
574 float z_coord = z;
575 x = x_coord * scifir::cos(x_angle) - z_coord * scifir::sin(x_angle);
576 z = x_coord * scifir::sin(x_angle) + z_coord * scifir::cos(x_angle);
577 }

◆ rotate_in_z()

void scifir::coordinates_3d< float >::rotate_in_z ( const angle x_angle)
inline

Rotates around the edge z the amount of the param x_angle.

Definition at line 579 of file coordinates_3d.hpp.

580 {
581 float x_coord = x;
582 float y_coord = y;
583 x = x_coord * scifir::cos(x_angle) - y_coord * scifir::sin(x_angle);
584 y = x_coord * scifir::sin(x_angle) + y_coord * scifir::cos(x_angle);
585 }

◆ set_position() [1/4]

void scifir::coordinates_3d< float >::set_position ( const angle new_latitude,
const angle new_longitude,
float  new_altitude 
)
inline

Sets x, y and z calculated from the geographical coordinates given.

Definition at line 556 of file coordinates_3d.hpp.

557 {
558 x = new_altitude * scifir::cos(new_latitude) * scifir::cos(new_longitude);
559 y = new_altitude * scifir::cos(new_latitude) * scifir::sin(new_longitude);
560 z = new_altitude * scifir::sin(new_latitude);
561 }

◆ set_position() [2/4]

void scifir::coordinates_3d< float >::set_position ( float  new_p,
const angle new_theta,
float  new_z 
)
inline

Sets x, y and z calculated from the cylindrical coordinates given.

Definition at line 542 of file coordinates_3d.hpp.

543 {
544 x = new_p * scifir::cos(new_theta);
545 y = new_p * scifir::sin(new_theta);
546 z = new_z;
547 }

◆ set_position() [3/4]

void scifir::coordinates_3d< float >::set_position ( float  new_r,
const angle new_theta,
const angle new_phi 
)
inline

Sets x, y and z calculated from the spherical coordinates given.

Definition at line 549 of file coordinates_3d.hpp.

550 {
551 x = new_r * scifir::cos(new_theta) * scifir::sin(new_phi);
552 y = new_r * scifir::sin(new_theta) * scifir::sin(new_phi);
553 z = new_r * scifir::cos(new_phi);
554 }

◆ set_position() [4/4]

void scifir::coordinates_3d< float >::set_position ( float  new_x,
float  new_y,
float  new_z 
)
inline

Sets x, y and z to the new_x, new_y and new_z.

Definition at line 535 of file coordinates_3d.hpp.

536 {
537 x = new_x;
538 y = new_y;
539 z = new_z;
540 }

Member Data Documentation

◆ x

The position in the edge x, with type float.

Definition at line 648 of file coordinates_3d.hpp.

◆ y

The position in the edge y, with type float.

Definition at line 649 of file coordinates_3d.hpp.

◆ z

The position in the edge z, with type float.

Definition at line 650 of file coordinates_3d.hpp.


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