-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriangle.h
88 lines (74 loc) · 2.44 KB
/
Triangle.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
*
* \copyright
* Copyright (c) 2012-2017, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include <vector>
#include "MathLib/Point3d.h"
namespace GeoLib {
class Point;
/** \brief Class Triangle consists of a reference to a point vector and
* a vector that stores the indices in the point vector.
* A surface is composed by triangles. The class Surface stores the position
* of pointers to the points of triangles in the _pnt_ids vector.
* */
class Triangle final
{
public:
/**
* construction of object, initialization of reference to point vector,
* saves the three indices describing a triangle
*/
Triangle(std::vector<Point*> const& pnt_vec,
std::size_t pnt_a,
std::size_t pnt_b,
std::size_t pnt_c);
/**
* saves three indices describing a triangle
* */
void setTriangle (std::size_t pnt_a, std::size_t pnt_b, std::size_t pnt_c);
/** \brief const access operator to access the index
* of the i-th triangle point
*/
const std::size_t& operator[](std::size_t i) const
{
assert (i < 3);
return _pnt_ids[i];
}
/**
* \brief const access operator to access the i-th triangle Point
*/
const Point* getPoint(std::size_t i) const
{
assert (i < 3);
return _pnts[_pnt_ids[i]];
}
/**
* Checks if point q is within the triangle, uses GeoLib::isPointInTriangle().
* @param q The input point.
* @param eps Checks the 'epsilon'-neighbourhood
* @return true, if point is in triangle, else false
*/
bool containsPoint(
MathLib::Point3d const& q,
double eps = std::numeric_limits<float>::epsilon()) const;
/**
* projects the triangle points to the x-y-plane and
* checks if point pnt is contained into the triangle
* @param pnt the point to test for
* @return true, if the point is into the projected triangle
*/
bool containsPoint2D(Point const& pnt) const;
private:
/// a vector of pointers to points the triangle is based on
std::vector<Point*> const& _pnts;
/// position of pointers to the geometric points
std::array<std::size_t, 3> _pnt_ids;
};
void getPlaneCoefficients(Triangle const& tri, double c[3]);
} // end namespace GeoLib