Debian Codegraph @

07p/plaut04/src/polygon3d.h

raw symbols SCIP
1 #ifndef _POLYGON_3D_
2 #define _POLYGON_3D_
3
4 #include <math.h>
5 #include <Inventor/SbLinear.h>
6
7 // this switches on normalization of normal vectors; does it help anything?
8 // #define _normalize_normals_
9
10 //////////////////////////////////////////////////////////////////////////////
11 //
12 // Class: Polygon3D
13 //
14 // This class describes regular plane polygons placed in 3D space,
15 // intended to be used to approximate circles
16 //
17 // To do: define Polygon3D and then RegularPolygon3D? Then, a projection is a
18 // polygon, etc.
19 //
20 //////////////////////////////////////////////////////////////////////////////
21
22 class Polygon3D {
23 public:
24 // Constructs a regular polygon given radius and number of vertices
25 // The normal is in the z-direction, the center is the origin
26 Polygon3D(float r=1.0, int nv=16);
27
28 // Constructs a regular polygon given center, normal, radius and number of vertices
29 Polygon3D(const SbVec3f &c, const SbVec3f &n, float r, int nv);
30
31 // Destructor: frees memory used to store vertices
32 ~Polygon3D();
33
34 // Rotates the polygon wrt its center (normal becomes new_normal)
35 void rotate(const SbVec3f &new_normal);
36
37 // Parallel translates the polygon by vector t (center becomes center+t)
38 void translate(const SbVec3f &t);
39
40 // Parallel translates the polygon to a new center c
41 void moveTo(const SbVec3f &c);
42
43 // Scales the polygon by s (radius becomes radius*s)
44 void scale(float s);
45
46 // Projects vertices onto a plane along the normal of the polygon
47 void project(const SbPlane &p, float pj[][3]);
48
49 // Projects vertices onto a plane along the normal of the plane
50 void project1(const SbPlane &p, float pj[][3]);
51
52 // Rotates the vertices n steps (counterclockwise if n>0)
53 void rotate(const int n);
54
55 // Accessors
56 const float & getRadius() const { return radius; }
57 const SbVec3f & getNormal() const { return normal; }
58 const SbVec3f & getCenter() const { return center; }
59
60 // Accesses indexed vertices
61 SbVec3f & operator [](int i) { return (points[i]); }
62 const SbVec3f & operator [](int i) const { return (points[i]); }
63
64 // Prints coordinates of the verteces for testing purposes
65 void print();
66
67 protected:
68 int n_points;
69 float radius;
70 SbVec3f normal, center;
71 SbVec3f *points;
72
73 private:
74 // Common code for constructors
75 void init(float r, int nv);
76 };
77
78 #endif /* _POLYGON_3D_ */