KJB
g_circle.h
Go to the documentation of this file.
1 /* \$Id\$ */
2 /* ===========================================================================*
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Emily Hartley
18  * ===========================================================================*/
19
20 #ifndef KJB_CIRCLE_H
21 #define KJB_CIRCLE_H
22
23 #include <m_cpp/m_vector.h>
24 #include <m_cpp/m_matrix.h>
25 #include <m/m_incl.h>
26 #include <i_cpp/i_image.h>
27 #include <i/i_draw.h>
29 #include <l_cpp/l_writeable.h>
30
31 namespace kjb {
32
33 class Circle{
34 public:
36  const kjb::Vector & GetCenter();
37  Circle(kjb::Vector * p1, kjb::Vector* p2, kjb::Vector* p3);
38  //Contructor for radius & center
40  Circle(const std::vector<kjb::Vector> & ipoints);
42  Circle();
43  double CalcCircle(Vector* pt1, Vector* pt2, Vector* pt3);
44  bool IsPerpendicular(Vector* pt1, Vector* pt2, Vector* pt3);
45  Image draw_circle(Matrix* points_to_show);
46
47 private:
48  Circle computeCircleGivenPoints(Matrix* mp);
49  Circle computeCircleGivenPoints(const std::vector<kjb::Vector> & ipoints);
51  Vector center;
52 };
53
54 // Constructs a circle in 3d space which is defined by its center, its radius,
55 // and the normal vector to the plane that the circle lies in.
56 class Circle_in_3d : public Readable, public Writeable
57 {
58 public:
60  (
61  const Vector& center,
63  const Vector& normal
65  Writeable(),
66  circle_center(center),
68  circle_normal(normal)
69  {
70  if(circle_center.size() != 3)
71  {
73  "The center point must be a 3d coordinate.");
74  }
75
77  {
79  "The radius must be a positive value.");
80  }
81
82  if(circle_normal.size() != 3)
83  {
85  "The normal vector must have size 3.");
86  }
87  }
88
89  Circle_in_3d(const char * filename)
90  : Readable(), Writeable(), circle_center(3, 0.0), circle_normal(3, 0.0)
91  {
93  }
94
95  Circle_in_3d(std::istream & in)
96  : Readable(), Writeable(), circle_center(3, 0.0), circle_normal(3, 0.0)
97  {
99  }
100
101  virtual Circle_in_3d& operator= (const Circle_in_3d& c);
102
103  virtual void read(std::istream & in);
104
105  virtual void read(const char * filename)
106  {
108  }
109
110  virtual void write(std::ostream & out) const;
111
112  virtual void write(const char * filename) const
113  {
114  Writeable::write(filename);
115  }
116
117  const Vector& get_circle_center() const { return circle_center; }
119  const Vector& get_circle_normal() const { return circle_normal; }
120
121 protected:
125 };
126
127 } // namespace kjb
128 #endif
Circle_in_3d(const Vector &center, const double radius, const Vector &normal)
Definition: g_circle.h:60
Circle_in_3d(std::istream &in)
Definition: g_circle.h:95
const Vector & get_circle_center() const
Definition: g_circle.h:117
Abstract class to write this object to an output stream.
Definition: l_writeable.h:41
Definition: g_circle.cpp:123
Definition: g_circle.h:118
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
Abstract class to read this object from an input stream.
Definition: g_circle.h:105
virtual void write(std::ostream &out) const
Writes this Writeable to an output stream.
Definition: g_circle.cpp:415
virtual void write(const char *filename) const
Writes this Writeable to a file.
Definition: g_circle.h:112
Definition: g_circle.h:33
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Definition: g_circle.h:123
virtual void write(std::ostream &out) const =0
Writes this Writeable to an output stream.
virtual Circle_in_3d & operator=(const Circle_in_3d &c)
Definition: g_circle.cpp:354
Image draw_circle(Matrix *points_to_show)
Definition: g_circle.cpp:273
Vector circle_normal
Definition: g_circle.h:124
Definition: g_circle.h:56
Definition: g_circle.cpp:364
Circle()
Definition: g_circle.cpp:35
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
const kjb::Vector & GetCenter()
Definition: g_circle.cpp:118
const Vector & get_circle_normal() const
Definition: g_circle.h:119
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
double CalcCircle(Vector *pt1, Vector *pt2, Vector *pt3)
Definition: g_circle.cpp:93
bool IsPerpendicular(Vector *pt1, Vector *pt2, Vector *pt3)
Definition: g_circle.cpp:70
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Code for a wrapper class around the C struct KJB_Image.
Circle_in_3d(const char *filename)
Definition: g_circle.h:89
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
struct memorypool points
Definition: triangle.c:637
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
Vector circle_center
Definition: g_circle.h:122