forked from i-RIC/iriclib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiricsolverlib_quadcell.cpp
75 lines (61 loc) · 1.61 KB
/
iricsolverlib_quadcell.cpp
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
75
#include "iricsolverlib_point2d.h"
#include "iricsolverlib_quadcell.h"
#include "iricsolverlib_rect2d.h"
#include "iricsolverlib_tricell.h"
#include <vector>
using namespace iRICSolverLib;
namespace {
const double INSIDE_DELTA = 1.0E-8;
bool interpolateTri(const QuadCell& cell, const Point2D& point, int id1, int id2, int id3, double* weights)
{
double s, t, u;
TriCell::calcSTU(point, cell.node(id1), cell.node(id2), cell.node(id3), &s, &t, &u);
if (s < - INSIDE_DELTA || t < - INSIDE_DELTA || u < - INSIDE_DELTA) {
return false;
}
*(weights) = s;
*(weights + 1) = t;
*(weights + 2) = u;
return true;
}
} // namespace
QuadCell::QuadCell(size_t id1, size_t id2, size_t id3, size_t id4, Grid2D* const grid) :
Cell2D(grid)
{
addNode(id1);
addNode(id2);
addNode(id3);
addNode(id4);
}
QuadCell::~QuadCell()
{}
bool QuadCell::interpolate(const Point2D& point, double* weight) const
{
if (! boundingRect().contains(point)) {return false;}
double tmpWeights[3];
bool ok;
// try triangle with, 0, 1, 2
ok = interpolateTri(*this, point, 1, 2, 3, &(tmpWeights[0]));
if (ok) {
* (weight ) = tmpWeights[0];
* (weight + 1) = tmpWeights[1];
* (weight + 2) = tmpWeights[2];
* (weight + 3) = 0;
return true;
}
// try triangle with 0, 2, 3
ok = interpolateTri(*this, point, 1, 3, 4, &(tmpWeights[0]));
if (ok) {
* (weight ) = tmpWeights[0];
* (weight + 1) = 0;
* (weight + 2) = tmpWeights[1];
* (weight + 3) = tmpWeights[2];
return true;
}
return false;
}
double QuadCell::area() const
{
return TriCell::calcArea(node(1), node(2), node(3)) +
TriCell::calcArea(node(1), node(3), node(4));
}