scsl  1.1.1
Shimmering Clarity Standard Library
Coord2D.h
Go to the documentation of this file.
1 
25 #ifndef SCMATH_GEOM_COORD2D_H
26 #define SCMATH_GEOM_COORD2D_H
27 
28 
29 #include <cmath>
30 #include <ostream>
31 #include <vector>
32 
33 #include <scmp/geom/Vector.h>
34 
35 
36 namespace scmp {
37 namespace geom {
38 
39 
40 class Point2D;
41 
42 class Polar2D;
43 
45 class Point2D : public Vector<int, 2> {
46 public:
49 
51  Point2D(int _x, int _y);
52 
54  Point2D(const Polar2D &pol);
55 
57  int X() const;
58 
60  void X(int _x);
61 
63  int Y() const;
64 
66  void Y(int _y);
67 
69  std::string ToString();
70 
73  void ToPolar(Polar2D &);
74 
79  void Rotate(Point2D& rotated, double theta);
80 
86  std::vector<Point2D> Rotate(std::vector<Polar2D> vertices, double theta);
87 
93  void Translate(const Point2D &other, Point2D &translated);
94 
96  int Distance(const Point2D &other) const;
97 
98  friend std::ostream &operator<<(std::ostream &outs, const Point2D &pt);
99 };
100 
104 class Polar2D : public Vector<double, 2> {
105 public:
108 
111 
117  Polar2D(double _r, double _theta);
118 
124  Polar2D(const Point2D& point);
125 
127  double R() const;
128 
130  void R(const double _r);
131 
133  double Theta() const;
134 
136  void Theta(const double _theta);
137 
139  std::string ToString();
140 
142  void ToPoint(Point2D &point);
143 
149  void Rotate(Polar2D &rotated, double delta);
150 
156  void RotateAround(const Point2D &other, Point2D &result, double delta);
157 
158  friend std::ostream &operator<<(std::ostream &, const Polar2D &);
159 };
160 
161 
162 } // end namespace geom
163 } // end namespace math
164 #endif
Linear algebraic vector class.
Point2D is a cartesian (X,Y) pairing.
Definition: Coord2D.h:45
void ToPolar(Polar2D &)
ToPolar converts the Point2D to a polar coordinate in-place.
void Rotate(Point2D &rotated, double theta)
Rotate rotates the point by theta radians.
Point2D()
A Point2D defaults to (0,0).
Point2D(int _x, int _y)
Initialize a Point2D At (_x, _y).
int Distance(const Point2D &other) const
Distance returns the distance from this point to another.
friend std::ostream & operator<<(std::ostream &outs, const Point2D &pt)
std::string ToString()
ToString returns a string in the format (x,y).
std::vector< Point2D > Rotate(std::vector< Polar2D > vertices, double theta)
Rotate this point around a series of vertices.
int Y() const
Return the Y component of the point.
void Translate(const Point2D &other, Point2D &translated)
Translate adds this point to the first argument, storing the result in the second argument.
void X(int _x)
Set the X component of the point.
void Y(int _y)
Set the Y component of the point.
Point2D(const Polar2D &pol)
Initialize a Point2D from a Polar2D coordinate.
int X() const
Return the X component of the point.
Polar2D is a pairing of a radius r and angle θ from some reference point; in this library,...
Definition: Coord2D.h:104
double Theta() const
Return the angle component of this coordinate.
double R() const
Return the radius component of this coordinate.
void Theta(const double _theta)
Set the angle component of this coordinate.
Polar2D(double _r, double _theta)
Construct a polar coordinate from a radius and angle.
void RotateAround(const Point2D &other, Point2D &result, double delta)
Rotate this polar coordinate around a 2D point.
Polar2D(const Point2D &point)
Construct a polar coordinate from a point.
void R(const double _r)
Set the radius component of this coordinate.
void ToPoint(Point2D &point)
Construct a Point2D representing this Polar2D.
friend std::ostream & operator<<(std::ostream &, const Polar2D &)
Polar2D()
Construct a zero polar coordinate.
std::string ToString()
Return the coordinate in string form.
void Rotate(Polar2D &rotated, double delta)
Rotate polar coordinate by some angle.
Vectors represent a direction and Magnitude.
Definition: Vector.h:57
Shimmering Clarity Math & Physics toolkit.
Definition: estimation.h:31