KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
g_cylinder_section.h
Go to the documentation of this file.
1 /* $Id: g_cylinder_section.h 12850 2012-08-16 01:07:41Z elh $ */
35 /* =========================================================================== *
36 |
37 | Copyright (c) 1994-2008 by Kobus Barnard (author).
38 |
39 | Personal and educational use of this code is granted, provided that this
40 | header is kept intact, and that the authorship is not misrepresented, that
41 | its use is acknowledged in publications, and relevant papers are cited.
42 |
43 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
44 |
45 | Please note that the code in this file has not necessarily been adequately
46 | tested. Naturally, there is no guarantee of performance, support, or fitness
47 | for any particular task. Nonetheless, I am interested in hearing about
48 | problems that you encounter.
49 |
50 | Authors:
51 | Emily Hartley
52 |
53 * =========================================================================== */
54 
63 #ifndef KJB_CYLINDER_SECTION_H
64 #define KJB_CYLINDER_SECTION_H
65 
66 #include <g_cpp/g_cylinder.h>
67 #include <l_cpp/l_readable.h>
68 #include <l_cpp/l_writeable.h>
69 
70 #define TWO_PI 6.28319
71 
72 namespace kjb
73 {
74 
80 class Cylinder_section : public Cylinder
81 {
82 
83 public:
85  Cylinder_section(const Vector& p1, const Vector& p2, double radius, double angle, const Vector& angle_startpt, const Vector& angle_endpt) :
86  Cylinder(p1, p2, radius),
87  angle_(angle),
88  angle_startpt_(angle_startpt),
89  angle_endpt_(angle_endpt)
90  {
91  if(angle_ < (-1 * TWO_PI) || angle_ > TWO_PI)
92  {
93  KJB_THROW_2(Illegal_argument, "Cylinder_section(): angle must be between -2*PI and 2*PI");
94  }
95 
96  if(angle_startpt_.size() < 3 || angle_startpt_.size() > 4)
97  {
98  KJB_THROW_2(Illegal_argument, "Cylinder_section(): start point of angle must be 3-dimensional");
99  }
100 
101  if(angle_endpt_.size() < 3 || angle_endpt_.size() > 4)
102  {
103  KJB_THROW_2(Illegal_argument, "Cylinder_section(): end point of angle must be 3-dimensional");
104  }
105  }
106 
109  Cylinder(fname),
110  angle_startpt_(3, 0.0),
111  angle_endpt_(3, 0.0)
112  {
113 
114  }
115 
118  Cylinder(in),
119  angle_startpt_(3, 0.0),
120  angle_endpt_(3, 0.0)
121  {
122  read(in);
123  }
124 
127 
129  virtual Cylinder_section& operator= (const Cylinder_section& c);
130 
132  virtual ~Cylinder_section();
133 
134  virtual void read(std::istream & in);
135 
136  virtual void write(std::ostream & out) const;
137 
138  double get_angle() const
139  {
140  return angle_;
141  }
142 
144  {
145  return angle_startpt_;
146  }
147 
149  {
150  return angle_endpt_;
151  }
152 
153 
154 private:
155  /* If angle is positive, then go counter-clockwise starting from
156  * angle_startpt.
157  * If angle is negative, then go clockwise starting from
158  * angle_startpt.
159  */
160  double angle_;
161 
162  /* angle_startpt is a point on the base of the cylinder_section (on
163  * the side containing p2) that is located on the edge of the
164  * cylinder_section. The sign of the angle denotes the direction with
165  * respect to this point.
166  */
167  Vector angle_startpt_;
168 
169  /* angle_endpt is the other point on the base of the cylinder_section
170  * (on the side containing p2) that is located on the edge of the
171  * cylinder_section.
172  */
173  Vector angle_endpt_;
174 };
175 
176 } // namespace kjb
177 
178 #endif
Cylinder_section: a section of a cylinder, specified by angle and position.
Definition: g_cylinder_section.h:80
virtual void write(std::ostream &out) const
Writes this Writeable to an output stream.
Definition: g_cylinder_section.cpp:159
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
#define TWO_PI
Definition: g_cylinder_section.h:70
virtual Cylinder_section & operator=(const Cylinder_section &c)
Copies a cylinder section into this one.
Definition: g_cylinder_section.cpp:94
virtual ~Cylinder_section()
Destructor of a cylinder section.
Definition: g_cylinder_section.cpp:81
Cylinder_section(const Vector &p1, const Vector &p2, double radius, double angle, const Vector &angle_startpt, const Vector &angle_endpt)
Constructs a cylinder section.
Definition: g_cylinder_section.h:85
const Vector & get_startpoint_of_angle() const
Definition: g_cylinder_section.h:143
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
virtual void read(std::istream &in)
Reads this Readable from an input stream.
Definition: g_cylinder_section.cpp:111
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
Cylinder(const Vector &p1, const Vector &p2, double radius)
Definition: g_cylinder.h:35
Cylinder_section(const char *fname)
Reads a cylinder section from an input file.
Definition: g_cylinder_section.h:108
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
Definition: g_cylinder.h:32
Object thrown when input or output fails.
Definition: l_exception.h:496
const Vector & get_endpoint_of_angle() const
Definition: g_cylinder_section.h:148
Cylinder_section(std::istream &in)
Reads a cylinder section from an input file.
Definition: g_cylinder_section.h:117
double get_angle() const
Definition: g_cylinder_section.h:138