30 int TPolygon::numberInstance = 0;
32 int TPolygon::generateId() {
33 return TPolygon::numberInstance++;
36 TPolygon::TPolygon() {
39 area_is_actual =
false;
40 center_is_actual =
false;
41 center.SetCoord(0, 0, 0);
45 TPolygon::~TPolygon() {
64 stream <<
"V" << i <<
" = " << (*iv)->GetPoint() <<
"\n";
70 void TPolygon::Add(
const TPoint& P) {
74 if ((*iv)->GetPoint() == P)
78 int insertPos = InsertPosition(*V);
79 area_is_actual =
false;
80 center_is_actual =
false;
81 verteces.insert(verteces.begin() + insertPos, V);
85 double TPolygon::GetArea() {
86 if (!center_is_actual)
94 void TPolygon::ComputeCenter() {
96 double D[ 3 ] = {0, 0, 0};
98 if (verteces.size() < 3) {
99 center.SetCoord(D[ 0 ], D[ 1 ], D[ 2 ]);
104 for (i = 0; i < 3; i++)
105 D[ i ] += (*iv)->GetPoint().Get(i + 1);
107 for (i = 0; i < 3; i++)
108 D[ i ] /= verteces.size();
109 center.SetCoord(D[ 0 ], D[ 1 ], D[ 2 ]);
110 center_is_actual =
true;
115 if (center_is_actual)
121 int TPolygon::InsertPosition(
const TVertex& Vx) {
127 if (verteces.size() < 2)
128 return verteces.size();
131 if (verteces.size() == 2) {
132 V1 = (*(verteces.begin()));
133 V2 = (*(verteces.begin() + 1));
137 normal_vector =
Cross(U1, U2);
138 return verteces.size();
141 for (
unsigned int i=0; i<verteces.size(); ++i) {
142 V1 = (*(verteces.begin() + i));
143 if (i == verteces.size() - 1)
144 V2 = (*(verteces.begin()));
146 V2 = (*(verteces.begin() + i + 1));
150 if (
Dot(N, normal_vector) < 0) {
151 if (pos > 0)
MessageOut() <<
"TPolygon::InsertPosition - ERROR: only one vector product must be negative\n";
156 if (pos == 0)
MessageOut() <<
"TPolygon::InsertPosition - ERROR: no vector product is negative\n";
160 void TPolygon::ComputeArea() {
167 area_is_actual =
true;
168 if (verteces.size() < 3)
173 P2 = (*iv)->GetPoint();
174 if (iv == verteces.end() - 1)
175 P3 = (*verteces.begin())->GetPoint();
177 P3 = (*(iv + 1))->GetPoint();
#define MessageOut()
Macro defining 'message' record of log.
double Dot(const TVector &, const TVector &)
#define FOR_POL_VERTECES(i, j)
void SetPoints(const TPoint &, const TPoint &, const TPoint &)
TVector Cross(const TVector &, const TVector &)
std::ostream & operator<<(std::ostream &stream, const TPolygon &p)