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
e1cac8e3
Commit
e1cac8e3
authored
4 years ago
by
Tom Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[MaL] Reimpl. calcProjPntToLineAndDists using Eigen.
parent
f850166b
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
MathLib/MathTools.cpp
+22
-15
22 additions, 15 deletions
MathLib/MathTools.cpp
MathLib/MathTools.h
+12
-7
12 additions, 7 deletions
MathLib/MathTools.h
with
34 additions
and
22 deletions
MathLib/MathTools.cpp
+
22
−
15
View file @
e1cac8e3
...
@@ -7,32 +7,39 @@
...
@@ -7,32 +7,39 @@
* http://www.opengeosys.org/project/license
* http://www.opengeosys.org/project/license
*/
*/
#include
"MathTools.h"
#include
<Eigen/Dense>
#include
<cmath>
#include
<cmath>
#include
"
MathTools
.h"
#include
"
Point3d
.h"
namespace
MathLib
namespace
MathLib
{
{
double
calcProjPntToLineAndDists
(
const
double
p
[
3
],
const
double
a
[
3
]
,
double
calcProjPntToLineAndDists
(
Point3d
const
&
pp
,
Point3d
const
&
pa
,
const
double
b
[
3
]
,
double
&
lambda
,
double
&
d0
)
Point3d
const
&
pb
,
double
&
lambda
,
double
&
d0
)
{
{
// g (lambda) = a + lambda v, v = b-a
auto
const
a
=
double
v
[
3
]
=
{
b
[
0
]
-
a
[
0
],
b
[
1
]
-
a
[
1
],
b
[
2
]
-
a
[
2
]};
Eigen
::
Map
<
Eigen
::
Vector3d
>
(
const_cast
<
double
*>
(
pa
.
getCoords
()));
// orthogonal projection: (g(lambda)-p) * v = 0 => in order to compute lambda we define a help vector u
auto
const
b
=
double
u
[
3
]
=
{
p
[
0
]
-
a
[
0
],
p
[
1
]
-
a
[
1
],
p
[
2
]
-
a
[
2
]};
Eigen
::
Map
<
Eigen
::
Vector3d
>
(
const_cast
<
double
*>
(
pb
.
getCoords
()));
lambda
=
scalarProduct
<
double
,
3
>
(
u
,
v
)
/
scalarProduct
<
double
,
3
>
(
v
,
v
);
auto
const
p
=
Eigen
::
Map
<
Eigen
::
Vector3d
>
(
const_cast
<
double
*>
(
pp
.
getCoords
()));
// g(lambda) = a + lambda v, v = b-a
Eigen
::
Vector3d
const
v
=
b
-
a
;
// orthogonal projection: (p - g(lambda))^T * v = 0
// <=> (a-p - lambda (b-a))^T * (b-a) = 0
// <=> (a-p)^T * (b-a) = lambda (b-a)^T ) (b-a)
lambda
=
(((
p
-
a
).
transpose
()
*
v
)
/
v
.
squaredNorm
())(
0
,
0
);
// compute projected point
// compute projected point
double
proj_pnt
[
3
];
Eigen
::
Vector3d
const
proj_pnt
=
a
+
lambda
*
v
;
for
(
std
::
size_t
k
(
0
);
k
<
3
;
k
++
)
{
proj_pnt
[
k
]
=
a
[
k
]
+
lambda
*
v
[
k
];
}
d0
=
std
::
sqrt
(
sqrDist
(
proj_pnt
,
a
));
d0
=
(
proj_pnt
-
a
)
.
norm
(
);
return
std
::
sqrt
(
sqrDist
(
p
,
proj_pnt
));
return
(
p
-
proj_pnt
)
.
norm
(
);
}
}
double
getAngle
(
const
double
p0
[
3
],
const
double
p1
[
3
],
const
double
p2
[
3
])
double
getAngle
(
const
double
p0
[
3
],
const
double
p1
[
3
],
const
double
p2
[
3
])
...
...
This diff is collapsed.
Click to expand it.
MathLib/MathTools.h
+
12
−
7
View file @
e1cac8e3
...
@@ -17,6 +17,9 @@
...
@@ -17,6 +17,9 @@
namespace
MathLib
namespace
MathLib
{
{
template
<
typename
T
,
std
::
size_t
DIM
>
class
TemplatePoint
;
using
Point3d
=
MathLib
::
TemplatePoint
<
double
,
3
>
;
/**
/**
* standard inner product in R^N
* standard inner product in R^N
* \param v0 array of type T representing the vector
* \param v0 array of type T representing the vector
...
@@ -65,16 +68,18 @@ inline T scalarProduct(T const* const v0, T const* const v1, int const n)
...
@@ -65,16 +68,18 @@ inline T scalarProduct(T const* const v0, T const* const v1, int const n)
* \f$g(\lambda) = a + \lambda (b - a)\f$,
* \f$g(\lambda) = a + \lambda (b - a)\f$,
* the distance between p and the projected point
* the distance between p and the projected point
* and the distances between the projected point and the end
* and the distances between the projected point and the end
* points a, b of the line
* points
p
a,
p
b of the line
* \param p the (mesh) point
* \param p
p
the (mesh) point
* \param a first point of line
* \param
p
a first point of line
* \param b second point of line
* \param
p
b second point of line
* \param lambda the projected point described by the line equation above
* \param lambda the projected point described by the line equation above
* \param d0 distance to the line point a
* \param d0 distance to the line point a
* \returns the distance between p and the orthogonal projection of p
* \returns the distance between p
p
and the orthogonal projection of p
p
*/
*/
double
calcProjPntToLineAndDists
(
const
double
p
[
3
],
const
double
a
[
3
],
double
calcProjPntToLineAndDists
(
MathLib
::
Point3d
const
&
pp
,
const
double
b
[
3
],
double
&
lambda
,
double
&
d0
);
MathLib
::
Point3d
const
&
pa
,
MathLib
::
Point3d
const
&
pb
,
double
&
lambda
,
double
&
d0
);
/** squared dist between double arrays p0 and p1 (size of arrays is 3) */
/** squared dist between double arrays p0 and p1 (size of arrays is 3) */
inline
inline
...
...
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