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
Dmitri Naumov
ogs
Commits
b359e305
Commit
b359e305
authored
4 years ago
by
Tom Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[GL] Substitute MaL::Vector3 by Eigen::Vector3d.
parent
cabff25b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MathLib/GeometricBasics.cpp
+48
-34
48 additions, 34 deletions
MathLib/GeometricBasics.cpp
with
48 additions
and
34 deletions
MathLib/GeometricBasics.cpp
+
48
−
34
View file @
b359e305
...
@@ -12,7 +12,6 @@
...
@@ -12,7 +12,6 @@
#include
<Eigen/Dense>
#include
<Eigen/Dense>
#include
"Point3d.h"
#include
"Point3d.h"
#include
"Vector3.h"
#include
"GeometricBasics.h"
#include
"GeometricBasics.h"
...
@@ -28,10 +27,10 @@ double orientation3d(MathLib::Point3d const& p,
...
@@ -28,10 +27,10 @@ double orientation3d(MathLib::Point3d const& p,
auto
const
pb
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
b
.
getCoords
());
auto
const
pb
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
b
.
getCoords
());
auto
const
pc
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
c
.
getCoords
());
auto
const
pc
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
c
.
getCoords
());
Eigen
::
Vector3d
const
ap
=
pp
-
pa
;
Eigen
::
Vector3d
const
u
=
pp
-
pa
;
Eigen
::
Vector3d
const
bp
=
pp
-
pb
;
Eigen
::
Vector3d
const
v
=
pp
-
pb
;
Eigen
::
Vector3d
const
cp
=
pp
-
pc
;
Eigen
::
Vector3d
const
w
=
pp
-
pc
;
return
MathLib
::
scalarTriple
(
bp
,
cp
,
ap
);
return
u
.
cross
(
v
).
dot
(
w
);
}
}
double
calcTetrahedronVolume
(
MathLib
::
Point3d
const
&
a
,
double
calcTetrahedronVolume
(
MathLib
::
Point3d
const
&
a
,
...
@@ -43,19 +42,22 @@ double calcTetrahedronVolume(MathLib::Point3d const& a,
...
@@ -43,19 +42,22 @@ double calcTetrahedronVolume(MathLib::Point3d const& a,
auto
const
vb
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
b
.
getCoords
());
auto
const
vb
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
b
.
getCoords
());
auto
const
vc
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
c
.
getCoords
());
auto
const
vc
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
c
.
getCoords
());
auto
const
vd
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
d
.
getCoords
());
auto
const
vd
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
d
.
getCoords
());
Eigen
::
Vector3d
const
ab
=
vb
-
va
;
Eigen
::
Vector3d
const
w
=
vb
-
va
;
Eigen
::
Vector3d
const
ac
=
vc
-
va
;
Eigen
::
Vector3d
const
u
=
vc
-
va
;
Eigen
::
Vector3d
const
ad
=
vd
-
va
;
Eigen
::
Vector3d
const
v
=
vd
-
va
;
return
std
::
abs
(
MathLib
::
scalarTriple
(
ac
,
ad
,
ab
))
/
6.0
;
return
std
::
abs
(
u
.
cross
(
v
).
dot
(
w
))
/
6.0
;
}
}
double
calcTriangleArea
(
MathLib
::
Point3d
const
&
a
,
MathLib
::
Point3d
const
&
b
,
double
calcTriangleArea
(
MathLib
::
Point3d
const
&
a
,
MathLib
::
Point3d
const
&
b
,
MathLib
::
Point3d
const
&
c
)
MathLib
::
Point3d
const
&
c
)
{
{
MathLib
::
Vector3
const
u
(
a
,
c
);
auto
const
va
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
a
.
getCoords
());
MathLib
::
Vector3
const
v
(
a
,
b
);
auto
const
vb
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
b
.
getCoords
());
MathLib
::
Vector3
const
w
(
MathLib
::
crossProduct
(
u
,
v
));
auto
const
vc
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
c
.
getCoords
());
return
0.5
*
w
.
getLength
();
Eigen
::
Vector3d
const
u
=
vc
-
va
;
Eigen
::
Vector3d
const
v
=
vb
-
va
;
Eigen
::
Vector3d
const
w
=
u
.
cross
(
v
);
return
0.5
*
w
.
norm
();
}
}
bool
isPointInTetrahedron
(
MathLib
::
Point3d
const
&
p
,
MathLib
::
Point3d
const
&
a
,
bool
isPointInTetrahedron
(
MathLib
::
Point3d
const
&
p
,
MathLib
::
Point3d
const
&
a
,
...
@@ -123,17 +125,20 @@ bool gaussPointInTriangle(MathLib::Point3d const& q,
...
@@ -123,17 +125,20 @@ bool gaussPointInTriangle(MathLib::Point3d const& q,
double
eps_pnt_out_of_plane
,
double
eps_pnt_out_of_plane
,
double
eps_pnt_out_of_tri
)
double
eps_pnt_out_of_tri
)
{
{
MathLib
::
Vector3
const
v
(
a
,
b
);
auto
const
pa
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
a
.
getCoords
());
MathLib
::
Vector3
const
w
(
a
,
c
);
auto
const
pb
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
b
.
getCoords
());
auto
const
pc
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
c
.
getCoords
());
Eigen
::
Vector3d
const
v
=
pb
-
pa
;
Eigen
::
Vector3d
const
w
=
pc
-
pa
;
Eigen
::
Matrix2d
mat
;
Eigen
::
Matrix2d
mat
;
mat
(
0
,
0
)
=
v
.
getSqrLength
();
mat
(
0
,
0
)
=
v
.
squaredNorm
();
mat
(
0
,
1
)
=
v
[
0
]
*
w
[
0
]
+
v
[
1
]
*
w
[
1
]
+
v
[
2
]
*
w
[
2
];
mat
(
0
,
1
)
=
v
[
0
]
*
w
[
0
]
+
v
[
1
]
*
w
[
1
]
+
v
[
2
]
*
w
[
2
];
mat
(
1
,
0
)
=
mat
(
0
,
1
);
mat
(
1
,
0
)
=
mat
(
0
,
1
);
mat
(
1
,
1
)
=
w
.
getSqrLength
();
mat
(
1
,
1
)
=
w
.
squaredNorm
();
Eigen
::
Vector2d
y
;
Eigen
::
Vector2d
y
(
y
<<
v
[
0
]
*
(
q
[
0
]
-
a
[
0
])
+
v
[
1
]
*
(
q
[
1
]
-
a
[
1
])
+
v
[
2
]
*
(
q
[
2
]
-
a
[
2
]),
v
[
0
]
*
(
q
[
0
]
-
a
[
0
])
+
v
[
1
]
*
(
q
[
1
]
-
a
[
1
])
+
v
[
2
]
*
(
q
[
2
]
-
a
[
2
]),
w
[
0
]
*
(
q
[
0
]
-
a
[
0
])
+
w
[
1
]
*
(
q
[
1
]
-
a
[
1
])
+
w
[
2
]
*
(
q
[
2
]
-
a
[
2
]);
w
[
0
]
*
(
q
[
0
]
-
a
[
0
])
+
w
[
1
]
*
(
q
[
1
]
-
a
[
1
])
+
w
[
2
]
*
(
q
[
2
]
-
a
[
2
])
)
;
y
=
mat
.
partialPivLu
().
solve
(
y
);
y
=
mat
.
partialPivLu
().
solve
(
y
);
...
@@ -167,17 +172,21 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p,
...
@@ -167,17 +172,21 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p,
return
false
;
return
false
;
}
}
MathLib
::
Vector3
const
pa
(
p
,
a
);
auto
const
vp
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
p
.
getCoords
());
MathLib
::
Vector3
const
pb
(
p
,
b
);
auto
const
va
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
a
.
getCoords
());
MathLib
::
Vector3
const
pc
(
p
,
c
);
auto
const
vb
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
b
.
getCoords
());
auto
const
vc
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
c
.
getCoords
());
Eigen
::
Vector3d
const
pa
=
va
-
vp
;
Eigen
::
Vector3d
const
pb
=
vb
-
vp
;
Eigen
::
Vector3d
const
pc
=
vc
-
vp
;
double
const
area_x_2
(
calcTriangleArea
(
a
,
b
,
c
)
*
2
);
double
const
area_x_2
(
calcTriangleArea
(
a
,
b
,
c
)
*
2
);
double
const
alpha
((
MathLib
::
crossProduct
(
pb
,
pc
).
getLength
())
/
area_x_2
);
double
const
alpha
((
pb
.
cross
(
pc
).
norm
())
/
area_x_2
);
if
(
alpha
<
-
eps_pnt_out_of_tri
||
alpha
>
1
+
eps_pnt_out_of_tri
)
if
(
alpha
<
-
eps_pnt_out_of_tri
||
alpha
>
1
+
eps_pnt_out_of_tri
)
{
{
return
false
;
return
false
;
}
}
double
const
beta
((
MathLib
::
crossProduct
(
pc
,
pa
).
getLength
())
/
area_x_2
);
double
const
beta
((
pc
.
cross
(
pa
).
norm
())
/
area_x_2
);
if
(
beta
<
-
eps_pnt_out_of_tri
||
beta
>
1
+
eps_pnt_out_of_tri
)
if
(
beta
<
-
eps_pnt_out_of_tri
||
beta
>
1
+
eps_pnt_out_of_tri
)
{
{
return
false
;
return
false
;
...
@@ -228,25 +237,30 @@ bool dividedByPlane(const MathLib::Point3d& a, const MathLib::Point3d& b,
...
@@ -228,25 +237,30 @@ bool dividedByPlane(const MathLib::Point3d& a, const MathLib::Point3d& b,
bool
isCoplanar
(
const
MathLib
::
Point3d
&
a
,
const
MathLib
::
Point3d
&
b
,
bool
isCoplanar
(
const
MathLib
::
Point3d
&
a
,
const
MathLib
::
Point3d
&
b
,
const
MathLib
::
Point3d
&
c
,
const
MathLib
::
Point3d
&
d
)
const
MathLib
::
Point3d
&
c
,
const
MathLib
::
Point3d
&
d
)
{
{
const
MathLib
::
Vector3
ab
(
a
,
b
);
auto
const
pa
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
a
.
getCoords
());
const
MathLib
::
Vector3
ac
(
a
,
c
);
auto
const
pb
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
b
.
getCoords
());
const
MathLib
::
Vector3
ad
(
a
,
d
);
auto
const
pc
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
c
.
getCoords
());
auto
const
pd
=
Eigen
::
Map
<
Eigen
::
Vector3d
const
>
(
d
.
getCoords
());
Eigen
::
Vector3d
const
ab
=
pb
-
pa
;
Eigen
::
Vector3d
const
ac
=
pc
-
pa
;
Eigen
::
Vector3d
const
ad
=
pd
-
pa
;
if
(
ab
.
getSqrLength
()
<
pow
(
std
::
numeric_limits
<
double
>::
epsilon
(),
2
)
||
auto
const
eps_squared
=
ac
.
getSqrLength
()
<
pow
(
std
::
numeric_limits
<
double
>::
epsilon
(),
2
)
||
std
::
pow
(
std
::
numeric_limits
<
double
>::
epsilon
(),
2
);
ad
.
getSqrLength
()
<
pow
(
std
::
numeric_limits
<
double
>::
epsilon
(),
2
))
if
(
ab
.
squaredNorm
()
<
eps_squared
||
ac
.
squaredNorm
()
<
eps_squared
||
ad
.
squaredNorm
()
<
eps_squared
)
{
{
return
true
;
return
true
;
}
}
// In exact arithmetic <ac*ad^T, ab> should be zero
// In exact arithmetic <ac*ad^T, ab> should be zero
// if all four points are coplanar.
// if all four points are coplanar.
const
double
sqr_scalar_triple
(
const
double
sqr_scalar_triple
(
std
::
pow
(
ac
.
cross
(
ad
).
dot
(
ab
),
2
));
pow
(
MathLib
::
scalarProduct
(
MathLib
::
crossProduct
(
ac
,
ad
),
ab
),
2
));
// Due to evaluating the above numerically some cancellation or rounding
// Due to evaluating the above numerically some cancellation or rounding
// can occur. For this reason a normalisation factor is introduced.
// can occur. For this reason a normalisation factor is introduced.
const
double
normalisation_factor
=
const
double
normalisation_factor
=
(
ab
.
getSqrLength
()
*
ac
.
getSqrLength
()
*
ad
.
getSqrLength
());
(
ab
.
squaredNorm
()
*
ac
.
squaredNorm
()
*
ad
.
squaredNorm
());
// tolerance 1e-11 is choosen such that
// tolerance 1e-11 is choosen such that
// a = (0,0,0), b=(1,0,0), c=(0,1,0) and d=(1,1,1e-6) are considered as
// a = (0,0,0), b=(1,0,0), c=(0,1,0) and d=(1,1,1e-6) are considered as
...
...
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