Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
typed-geometry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Philip Trettner
typed-geometry
Commits
4c43fcd5
Commit
4c43fcd5
authored
5 years ago
by
Kersten Schuster
Browse files
Options
Downloads
Patches
Plain Diff
Computation of bounding sphere of triangle.
parent
39eb21a1
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!35
Fixed obtuseness tests to return bool.
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/typed-geometry/detail/functions.hh
+1
-0
1 addition, 0 deletions
src/typed-geometry/detail/functions.hh
src/typed-geometry/functions/bounds.hh
+54
-0
54 additions, 0 deletions
src/typed-geometry/functions/bounds.hh
with
55 additions
and
0 deletions
src/typed-geometry/detail/functions.hh
+
1
−
0
View file @
4c43fcd5
...
...
@@ -3,6 +3,7 @@
#include
<typed-geometry/functions/aabb.hh>
#include
<typed-geometry/functions/angle.hh>
#include
<typed-geometry/functions/area.hh>
#include
<typed-geometry/functions/bounds.hh>
#include
<typed-geometry/functions/centroid.hh>
#include
<typed-geometry/functions/closest_points.hh>
#include
<typed-geometry/functions/contains.hh>
...
...
This diff is collapsed.
Click to expand it.
src/typed-geometry/functions/bounds.hh
0 → 100644
+
54
−
0
View file @
4c43fcd5
#pragma once
#include
<typed-geometry/functions/interpolate.hh>
#include
<typed-geometry/tests/triangle_tests.hh>
#include
<typed-geometry/types/objects/sphere.hh>
#include
<typed-geometry/types/objects/triangle.hh>
namespace
tg
{
template
<
int
D
,
class
ScalarT
>
TG_NODISCARD
constexpr
sphere
<
D
,
ScalarT
>
bounding_sphere_of
(
triangle
<
D
,
ScalarT
>
const
&
t
)
{
auto
e0sqr
=
distance_sqr
(
t
.
pos0
,
t
.
pos1
);
auto
e1sqr
=
distance_sqr
(
t
.
pos1
,
t
.
pos2
);
auto
e2sqr
=
distance_sqr
(
t
.
pos2
,
t
.
pos0
);
auto
const
*
a
=
&
t
.
pos2
;
auto
const
*
b
=
&
t
.
pos0
;
auto
const
*
c
=
&
t
.
pos1
;
// "rotate" triangle s.t. e0 is the largest edge and
// lies opposite of point a (equivalently, e1 <-> b, e2 <-> c)
if
(
e2sqr
>
e1sqr
)
{
// make e1 larger than e2
detail
::
swap
(
e1sqr
,
e2sqr
);
detail
::
swap
(
b
,
c
);
}
if
(
e1sqr
>
e0sqr
)
{
// make e0 larger than e1
detail
::
swap
(
e0sqr
,
e1sqr
);
detail
::
swap
(
a
,
b
);
}
if
(
e0sqr
>=
e1sqr
+
e2sqr
)
// triangle is obtuse or right
{
auto
radius
=
tg
::
sqrt
(
e0sqr
)
/
ScalarT
(
2
);
auto
center
=
mix
(
*
b
,
*
c
,
ScalarT
(
0.5
));
return
{
center
,
radius
};
}
// compute barycentric coords
auto
alpha
=
e0sqr
*
(
e1sqr
+
e2sqr
-
e0sqr
);
auto
beta
=
e1sqr
*
(
e2sqr
+
e0sqr
-
e1sqr
);
auto
gamma
=
e2sqr
*
(
e0sqr
+
e1sqr
-
e2sqr
);
auto
bary_sum
=
alpha
+
beta
+
gamma
;
auto
center
=
tg
::
interpolate
(
triangle
<
D
,
ScalarT
>
(
*
a
,
*
b
,
*
c
),
alpha
,
beta
,
gamma
)
/
bary_sum
;
auto
radius
=
tg
::
distance
(
center
,
t
.
pos0
);
return
{
center
,
radius
};
}
}
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