-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTriunghi.cpp
75 lines (56 loc) · 2.37 KB
/
Triunghi.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 "Triunghi.h"
Triunghi::Triunghi (Vec3 v1, Vec3 v2, Vec3 v3) : m_v1(v1), m_v2(v2), m_v3(v3) {}
Triunghi::Triunghi (const Triunghi& t) : m_v1(t.m_v1), m_v2(t.m_v2), m_v3(t.m_v3) {}
Vec3 Triunghi::getV1 () const { return m_v1; }
Vec3 Triunghi::getV2 () const { return m_v2; }
Vec3 Triunghi::getV3 () const { return m_v3; }
void Triunghi::setV1 (Vec3 v) { m_v1 = v; }
void Triunghi::setV2 (Vec3 v) { m_v2 = v; }
void Triunghi::setV3 (Vec3 v) { m_v3 = v; }
std::ostream& operator<< (std::ostream& os, const Triunghi& t) {
os << t.m_v1 << " " << t.m_v2 << " " << t.m_v3;
return os;
}
std::istream& operator>> (std::istream& is, Triunghi& t) {
is >> t.m_v1;
is >> t.m_v2;
is >> t.m_v3;
return is;
}
double Triunghi::calculeazaArie () const {
double arie;
arie = (m_v2.getC1() - m_v1.getC1()) * (m_v3.getC2() - m_v1.getC2())
- (m_v3.getC1() - m_v1.getC1()) * (m_v2.getC2() - m_v1.getC2());
return abs(arie) / 2;
}
double Triunghi::calculeazaArie (const Vec3& v1, const Vec3& v2, const Vec3& v3) {
double arie;
arie = (v2.getC1() - v1.getC1()) * (v3.getC2() - v1.getC2())
- (v3.getC1() - v1.getC1()) * (v2.getC2() - v1.getC2());
return abs(arie) / 2;
}
bool Triunghi::continePunct (const Vec3& v) const {
// Punctul P se gaseste in interiorul triunghiului
// sau pe laturile sale daca suma ariilor subtriungiurilor
// (ABP, ACP, BCP) este egala cu suma triunhiului ABC.
double arie_ABP = Triunghi::calculeazaArie(m_v1, m_v2, v);
double arie_ACP = Triunghi::calculeazaArie(m_v1, m_v3, v);
double arie_BCP = Triunghi::calculeazaArie(m_v2, m_v3, v);
double arie_subtriunghiuri = arie_ABP + arie_ACP + arie_BCP;
if (abs(calculeazaArie() - arie_subtriunghiuri) < 0.0001)
return true;
return false;
}
bool Triunghi::continePunct (double x, double y, double z) const {
Vec3 v(x, y, z);
// Punctul P se gaseste in interiorul triunghiului
// sau pe laturile sale daca suma ariilor subtriungiurilor
// (ABP, ACP, BCP) este egala cu suma triunhiului ABC.
double arie_ABP = Triunghi::calculeazaArie(m_v1, m_v2, v);
double arie_ACP = Triunghi::calculeazaArie(m_v1, m_v3, v);
double arie_BCP = Triunghi::calculeazaArie(m_v2, m_v3, v);
double arie_subtriunghiuri = arie_ABP + arie_ACP + arie_BCP;
if (abs(calculeazaArie() - arie_subtriunghiuri) < 0.0001)
return true;
return false;
}