Hope to get it right now

This commit is contained in:
Andreas Fabri 2021-02-17 09:53:28 +00:00
parent 42866756b9
commit 59d7b22959
3 changed files with 66 additions and 11 deletions

View File

@ -225,6 +225,7 @@ squared_distance_to_triangle(
const typename K::Point_3 & t0,
const typename K::Point_3 & t1,
const typename K::Point_3 & t2,
bool & inside,
const K& k)
{
typename K::Construct_vector_3 vector;
@ -239,6 +240,7 @@ squared_distance_to_triangle(
&& on_left_of_triangle_edge(pt, normal, t2, t0, k))
{
// the projection of pt is inside the triangle
inside = true;
return squared_distance_to_plane(normal, vector(t0, pt), k);
}
else {
@ -267,10 +269,12 @@ squared_distance(
const K& k)
{
typename K::Construct_vertex_3 vertex;
bool inside = false;
return squared_distance_to_triangle(pt,
vertex(t, 0),
vertex(t, 1),
vertex(t, 2),
inside,
k);
}

View File

@ -34,22 +34,70 @@ squared_distance(const typename K::Tetrahedron_3 & t,
const typename K::Point_3 & pt,
const K& k)
{
bool on_bounded_side = true;
const typename K::Point_3 t0 = t[0];
const typename K::Point_3 t1 = t[1];
const typename K::Point_3 t2 = t[2];
const typename K::Point_3 t3 = t[3];
if (! t.has_on_unbounded_side(pt)){
return K::FT(0);
bool dmin_initialized = false;
typename K::FT dmin;
bool inside = false;
if(orientation(t0,t1,t2, pt) == NEGATIVE){
on_bounded_side = false;
dmin = squared_distance_to_triangle(pt, t0, t1, t2, inside, k);
dmin_initialized = true;
if(inside){
return dmin;
}
}
const typename K::Triangle_3 t0 = {t[0], t[1], t[2]};
const typename K::Triangle_3 t1 = {t[0], t[1], t[3]};
const typename K::Triangle_3 t2 = {t[1], t[2], t[3]};
const typename K::Triangle_3 t3 = {t[0], t[2], t[3]};
if(orientation(t0,t3,t1, pt) == NEGATIVE){
on_bounded_side = false;
const typename K::FT d = squared_distance_to_triangle(pt, t0, t3, t1, inside, k);
if(inside){
return d;
}
if(! dmin_initialized){
dmin = d;
dmin_initialized = true;
}else{
dmin = std::min(d,dmin);
}
}
const typename K::FT d0 = squared_distance(pt, t0, k);
const typename K::FT d1 = squared_distance(pt, t1, k);
const typename K::FT d2 = squared_distance(pt, t2, k);
const typename K::FT d3 = squared_distance(pt, t3, k);
if(orientation(t1,t3,t2, pt) == NEGATIVE){
on_bounded_side = false;
const typename K::FT d = squared_distance_to_triangle(pt, t1, t3, t2, inside, k);
if(inside){
return d;
}
if(! dmin_initialized){
dmin = d;
dmin_initialized = true;
}else{
dmin = std::min(d,dmin);
}
}
return (std::min)({d0, d1, d2, d3});
if(orientation(t2,t3,t0, pt) == NEGATIVE){
on_bounded_side = false;
const typename K::FT d = squared_distance_to_triangle(pt, t2, t3, t0, inside, k);
if(inside){
return d;
}
if(! dmin_initialized){
dmin = d;
dmin_initialized = true;
}else{
dmin = std::min(d,dmin);
}
}
if(on_bounded_side){
return K::FT(0);
}
return dmin;
}
} // namespace internal

View File

@ -118,6 +118,9 @@ struct Test {
{
std::cout << "Point - Tetrahedron\n";
check_squared_distance (p(0, 0, 0), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 0);
check_squared_distance (p(0, 0, 2), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 1);
check_squared_distance (p(0, 0, -1), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 0, 0, 1)), 1);
check_squared_distance (p(5, 0, 0), Tet(p(0, 0, 0), p( 1, 0, 0), p( 0, 1, 0), p( 4, 0, 1)), 2);
}
void S_S()