cylinder.h
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef STIM_CYLINDER_H
#define STIM_CYLINDER_H
#include <iostream>
#include <stim/math/circle.h>
#include <stim/math/vector.h>
namespace stim
{
template<typename T>
class cylinder
{
private:
stim::circle<T> s;
std::vector< stim::vec<T> > pos;
std::vector< stim::vec<T> > mags;
void
init()
{
}
void
init(std::vector<stim::vec<T> > &inP, std::vector<stim::vec<T> > &inM)
{
pos = inP;
mags = inM;
}
public:
cylinder()
{
}
///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder.
///The higher the number of sides, the more rectangeles compose the surface of the cylinder.
///@param inP: Vector of stim vecs composing the points of the centerline.
///@param inM: Vector of stim vecs composing the radii of the centerline.
cylinder(std::vector<stim::vec<T> > &inP, std::vector<stim::vec<T> > &inM)
{
init(inP, inM);
}
std::vector<std::vector<vec<T> > >
getPoints(int sides)
{
if(pos.size() < 2)
{
return;
} else {
std::vector<std::vector <vec<T> > > points;
points.resize(pos.size());
stim::vec<T> d = (pos[0] - pos[1]).norm();
s = stim::circle<T>(pos[0], mags[0][0], d);
points[0] = s.getPoints(sides);
for(int i = 1; i < pos.size(); i++)
{
d = (pos[i] - pos[i-1]).norm();
s.center(pos[i]);
s.normal(d);
s.scale(mags[i][0]/mags[i-1][0], mags[i][0]/mags[i-1][0]);
points[i] = s.getPoints(sides);
}
return points;
}
}
};
}
#endif