3
// triangle used for Anders's DropCutter code
4
// written by Dan Heeks starting on May 2nd 2008
8
double m_p[9]; // three points
9
double m_n[3]; // normal, calculate this when loading stl file ( or creating from solid )
10
double m_box[4]; // minx miny maxx maxy
12
GTri(const double* x){memcpy(m_p, x, 9*sizeof(double)); calculate_box_and_normal();}
14
void calculate_box_and_normal(){
15
double v1[3] = {m_p[3] - m_p[0], m_p[4] - m_p[1], m_p[5] - m_p[2]};
16
double v2[3] = {m_p[6] - m_p[0], m_p[7] - m_p[1], m_p[8] - m_p[2]};
18
m_n[0] = v1[1] * v2[2] - v1[2] * v2[1];
19
m_n[1] = v1[2] * v2[0] - v1[0] * v2[2];
20
m_n[2] = v1[0] * v2[1] - v1[1] * v2[0];
23
double m = sqrt(m_n[0] * m_n[0] + m_n[1] * m_n[1] + m_n[2] * m_n[2]);
32
if(m_p[3] < m_box[0])m_box[0] = m_p[3];
33
if(m_p[6] < m_box[0])m_box[0] = m_p[6];
35
if(m_p[4] < m_box[1])m_box[1] = m_p[4];
36
if(m_p[7] < m_box[1])m_box[1] = m_p[7];
38
if(m_p[3] > m_box[2])m_box[2] = m_p[3];
39
if(m_p[6] > m_box[2])m_box[2] = m_p[6];
41
if(m_p[4] > m_box[3])m_box[3] = m_p[4];
42
if(m_p[7] > m_box[3])m_box[3] = m_p[7];
45
static bool box_in_box(double *this_box, double *box){
46
if(this_box[0]<box[0]-heeksCAD->GetTolerance()){
47
// left of tri is left of box
48
if(this_box[2]<box[0]-heeksCAD->GetTolerance()){
49
// right of tri is left of box
52
else if(this_box[2]<box[2] + heeksCAD->GetTolerance()){
53
// right of tri is in box
54
if(this_box[1]<box[1]-heeksCAD->GetTolerance()){
55
// bottom of tri is below box
56
if(this_box[3]<box[1]-heeksCAD->GetTolerance()){
57
// top of tri is below of box
61
// top of tri is in box or above it
65
else if(this_box[1]<box[3]+heeksCAD->GetTolerance()){
66
// bottom of tri is in box
70
// bottom of tri is above box
75
// right of tri is right of box
76
if(this_box[1]>box[1]-heeksCAD->GetTolerance() && this_box[3]<box[3]+heeksCAD->GetTolerance()){
77
// top and bottom within box
85
else if(this_box[0]<box[2]+heeksCAD->GetTolerance()){
86
// left of tri is within box
87
if(this_box[1]<box[1]-heeksCAD->GetTolerance()){
88
// bottom of tri is below box
89
if(this_box[3]<box[1]-heeksCAD->GetTolerance()){
90
// top of tri is below of box
94
// top of tri is in box or above it
98
else if(this_box[1]<box[3]+heeksCAD->GetTolerance()){
99
// bottom of tri is in box
103
// bottom of tri is above box
108
// left of tri is right of box
b'\\ No newline at end of file'