Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Özgür Ozan Sen
ogs
Commits
07735c7b
Commit
07735c7b
authored
10 years ago
by
Tom Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[GeoLib::Triangle] Using existing code for containsPoint().
parent
f59cbf25
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GeoLib/Triangle.cpp
+8
-99
8 additions, 99 deletions
GeoLib/Triangle.cpp
GeoLib/Triangle.h
+4
-3
4 additions, 3 deletions
GeoLib/Triangle.h
with
12 additions
and
102 deletions
GeoLib/Triangle.cpp
+
8
−
99
View file @
07735c7b
...
...
@@ -14,6 +14,9 @@
#include
"Triangle.h"
// GeoLib
#include
"AnalyticalGeometry.h"
// MathLib
#include
"LinAlg/Solvers/GaussAlgorithm.h"
#include
"MathTools.h"
...
...
@@ -59,106 +62,12 @@ void Triangle::setTriangle (size_t pnt_a, size_t pnt_b, size_t pnt_c)
_longest_edge
=
sqrt
(
_longest_edge
);
}
bool
Triangle
::
containsPoint
(
Point
const
&
pnt
)
const
bool
Triangle
::
containsPoint
(
Point
const
&
q
,
double
eps
)
const
{
GeoLib
::
Point
const
&
a_tmp
(
*
(
_pnts
[
_pnt_ids
[
0
]]));
GeoLib
::
Point
const
&
b_tmp
(
*
(
_pnts
[
_pnt_ids
[
1
]]));
GeoLib
::
Point
const
&
c_tmp
(
*
(
_pnts
[
_pnt_ids
[
2
]]));
GeoLib
::
Point
s
(
a_tmp
);
for
(
size_t
k
(
0
);
k
<
3
;
k
++
)
{
s
[
k
]
+=
b_tmp
[
k
]
+
c_tmp
[
k
];
s
[
k
]
/=
3.0
;
}
double
eps
(
1e-2
);
GeoLib
::
Point
const
a
(
a_tmp
[
0
]
+
eps
*
(
a_tmp
[
0
]
-
s
[
0
]),
a_tmp
[
1
]
+
eps
*
(
a_tmp
[
1
]
-
s
[
1
]),
a_tmp
[
2
]
+
eps
*
(
a_tmp
[
2
]
-
s
[
2
]));
GeoLib
::
Point
const
b
(
b_tmp
[
0
]
+
eps
*
(
b_tmp
[
0
]
-
s
[
0
]),
b_tmp
[
1
]
+
eps
*
(
b_tmp
[
1
]
-
s
[
1
]),
b_tmp
[
2
]
+
eps
*
(
b_tmp
[
2
]
-
s
[
2
]));
GeoLib
::
Point
const
c
(
c_tmp
[
0
]
+
eps
*
(
c_tmp
[
0
]
-
s
[
0
]),
c_tmp
[
1
]
+
eps
*
(
c_tmp
[
1
]
-
s
[
1
]),
c_tmp
[
2
]
+
eps
*
(
c_tmp
[
2
]
-
s
[
2
]));
const
double
delta
(
std
::
numeric_limits
<
double
>::
epsilon
());
const
double
upper
(
1
+
delta
);
// check special case where points of triangle have the same x-coordinate
if
(
fabs
(
b
[
0
]
-
a
[
0
])
<=
std
::
numeric_limits
<
double
>::
epsilon
()
&&
fabs
(
c
[
0
]
-
a
[
0
])
<=
std
::
numeric_limits
<
double
>::
epsilon
())
{
// all points of triangle have same x-coordinate
if
(
fabs
(
pnt
[
0
]
-
a
[
0
])
/
_longest_edge
<=
1e-3
)
{
// criterion: p-a = u0 * (b-a) + u1 * (c-a); 0 <= u0, u1 <= 1, u0+u1 <= 1
MathLib
::
DenseMatrix
<
double
>
mat
(
2
,
2
);
mat
(
0
,
0
)
=
b
[
1
]
-
a
[
1
];
mat
(
0
,
1
)
=
c
[
1
]
-
a
[
1
];
mat
(
1
,
0
)
=
b
[
2
]
-
a
[
2
];
mat
(
1
,
1
)
=
c
[
2
]
-
a
[
2
];
double
y
[
2
]
=
{
pnt
[
1
]
-
a
[
1
],
pnt
[
2
]
-
a
[
2
]};
MathLib
::
GaussAlgorithm
<
MathLib
::
DenseMatrix
<
double
>
,
double
*>
gauss
(
mat
);
gauss
.
solve
(
y
);
if
(
-
delta
<=
y
[
0
]
&&
y
[
0
]
<=
upper
&&
-
delta
<=
y
[
1
]
&&
y
[
1
]
<=
upper
&&
y
[
0
]
+
y
[
1
]
<=
upper
)
{
return
true
;
}
else
{
return
false
;
}
}
else
{
return
false
;
}
}
// check special case where points of triangle have the same y-coordinate
if
(
fabs
(
b
[
1
]
-
a
[
1
])
<=
std
::
numeric_limits
<
double
>::
epsilon
()
&&
fabs
(
c
[
1
]
-
a
[
1
])
<=
std
::
numeric_limits
<
double
>::
epsilon
())
{
// all points of triangle have same y-coordinate
if
(
fabs
(
pnt
[
1
]
-
a
[
1
])
/
_longest_edge
<=
1e-3
)
{
// criterion: p-a = u0 * (b-a) + u1 * (c-a); 0 <= u0, u1 <= 1, u0+u1 <= 1
MathLib
::
DenseMatrix
<
double
>
mat
(
2
,
2
);
mat
(
0
,
0
)
=
b
[
0
]
-
a
[
0
];
mat
(
0
,
1
)
=
c
[
0
]
-
a
[
0
];
mat
(
1
,
0
)
=
b
[
2
]
-
a
[
2
];
mat
(
1
,
1
)
=
c
[
2
]
-
a
[
2
];
double
y
[
2
]
=
{
pnt
[
0
]
-
a
[
0
],
pnt
[
2
]
-
a
[
2
]};
MathLib
::
GaussAlgorithm
<
MathLib
::
DenseMatrix
<
double
>
,
double
*>
gauss
(
mat
);
gauss
.
solve
(
y
);
if
(
-
delta
<=
y
[
0
]
&&
y
[
0
]
<=
upper
&&
-
delta
<=
y
[
1
]
&&
y
[
1
]
<=
upper
&&
y
[
0
]
+
y
[
1
]
<=
upper
)
{
return
true
;
}
else
{
return
false
;
}
}
else
{
return
false
;
}
}
// criterion: p-a = u0 * (b-a) + u1 * (c-a); 0 <= u0, u1 <= 1, u0+u1 <= 1
MathLib
::
DenseMatrix
<
double
>
mat
(
2
,
2
);
mat
(
0
,
0
)
=
b
[
0
]
-
a
[
0
];
mat
(
0
,
1
)
=
c
[
0
]
-
a
[
0
];
mat
(
1
,
0
)
=
b
[
1
]
-
a
[
1
];
mat
(
1
,
1
)
=
c
[
1
]
-
a
[
1
];
double
y
[
2
]
=
{
pnt
[
0
]
-
a
[
0
],
pnt
[
1
]
-
a
[
1
]};
MathLib
::
GaussAlgorithm
<
MathLib
::
DenseMatrix
<
double
>
,
double
*>
gauss
(
mat
);
gauss
.
solve
(
y
);
// check if the solution fulfills the third equation
if
(
fabs
((
b
[
2
]
-
a
[
2
])
*
y
[
0
]
+
(
c
[
2
]
-
a
[
2
])
*
y
[
1
]
-
(
pnt
[
2
]
-
a
[
2
]))
<
1e-3
)
{
if
(
-
delta
<=
y
[
0
]
&&
y
[
0
]
<=
upper
&&
-
delta
<=
y
[
1
]
&&
y
[
1
]
<=
upper
&&
y
[
0
]
+
y
[
1
]
<=
upper
)
{
return
true
;
}
return
false
;
}
else
{
return
false
;
}
GeoLib
::
Point
const
&
a
(
*
(
_pnts
[
_pnt_ids
[
0
]]));
GeoLib
::
Point
const
&
b
(
*
(
_pnts
[
_pnt_ids
[
1
]]));
GeoLib
::
Point
const
&
c
(
*
(
_pnts
[
_pnt_ids
[
2
]]));
return
GeoLib
::
isPointInTriangle
(
q
,
a
,
b
,
c
,
eps
);
}
bool
Triangle
::
containsPoint2D
(
Point
const
&
pnt
)
const
...
...
This diff is collapsed.
Click to expand it.
GeoLib/Triangle.h
+
4
−
3
View file @
07735c7b
...
...
@@ -71,11 +71,12 @@ public:
}
/**
* checks if point is in triangle
* @param pnt The input point
* 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
(
Point
const
&
pnt
)
const
;
bool
containsPoint
(
Point
const
&
q
,
double
eps
=
std
::
numeric_limits
<
float
>::
epsilon
()
)
const
;
/**
* projects the triangle points to the x-y-plane and
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment