Commit 7144d5eb authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[isect] add overload for polygon-disk

parent 0f9024ec
......@@ -11,6 +11,7 @@ algo_planargeom_line.hh
algo_planargeom_planargeom.hh
algo_plane_line.hh
algo_plane_plane.hh
algo_polygon_disk.hh
algo_polygon_polygon.hh
algo_quadrilateral_disk.hh
algo_quadrilateral_line.hh
......
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
/*!
* \file
* \brief Contains the intersection algorithm
* between a polygon and a disk.
*/
#ifndef FRACKIT_POLYGON_DISK_INTERSECTION_HH
#define FRACKIT_POLYGON_DISK_INTERSECTION_HH
#include <cmath>
#include <frackit/precision/precision.hh>
#include <frackit/geometry/polygon.hh>
#include <frackit/geometry/disk.hh>
#include <frackit/geometry/segment.hh>
#include <frackit/intersection/intersectiontraits.hh>
#include "algo_planargeom_planargeom.hh"
namespace Frackit {
namespace IntersectionAlgorithms {
//! Intersect a polygon and a disk
//! The result can be:
//! - a surface bounded by segments and/or elliptical arcs
//! - a segment
//! - a point
//! - no intersection
template<class ctype>
Intersection< Polygon<ctype, 3>, Disk<ctype> >
intersect_polygon_disk(const Polygon<ctype, 3>& polygon,
const Disk<ctype>& disk,
ctype eps)
{
using Segment = Segment<ctype, 3>;
ctype charLength = 0.0;
using std::max;
for (unsigned int i = 0; i < polygon.numCorners(); ++i)
charLength = max(charLength, Segment(polygon.center(), polygon.corner(i)).squaredLength());
using std::sqrt;
return intersect_planarGeometry_planarGeometry(polygon, disk,
sqrt(charLength),
eps, eps, eps);
}
} // end namespace IntersectionAlgorithms
} // end namespace Frackit
#endif // FRACKIT_POLYGON_DISK_INTERSECTION_HH
......@@ -56,6 +56,7 @@
#include "algorithms/algo_quadrilateral_line.hh"
#include "algorithms/algo_quadrilateral_quadrilateral.hh"
#include "algorithms/algo_quadrilateral_disk.hh"
#include "algorithms/algo_polygon_disk.hh"
#include "algorithms/algo_polygon_polygon.hh"
#include "algorithms/algo_disk_disk.hh"
#include "algorithms/algo_cylsurface_disk.hh"
......@@ -267,6 +268,34 @@ Intersection< Disk<ctype>, Quadrilateral<ctype, 3> >
intersect(const Disk<ctype>& disk, const Quadrilateral<ctype, 3>& quad, ctype eps)
{ return intersect(quad, disk, eps); }
/*!
* \ingroup Intersection
* \brief Intersect a polygon and a disk in 3d space.
* \param polygon The polygon
* \param disk The disk
* \param eps Tolerance to be used for floating point comparisons
*/
template<class ctype>
Intersection< Polygon<ctype, 3>, Disk<ctype> >
intersect(const Polygon<ctype, 3>& polygon, const Disk<ctype>& disk, ctype eps)
{
if (!doIntersect(getBoundingBox(polygon), getBoundingBox(disk), eps))
return {EmptyIntersection<3, ctype>()};
return IntersectionAlgorithms::intersect_polygon_disk(polygon, disk, eps);
}
/*!
* \ingroup Intersection
* \brief Intersect a disk and a polygon in 3d space.
* \param polygon The polygon
* \param quad The quadrilateral
* \param eps Tolerance to be used for floating point comparisons
*/
template<class ctype>
Intersection< Disk<ctype>, Polygon<ctype, 3> >
intersect(const Disk<ctype>& disk, const Polygon<ctype, 3>& polygon, ctype eps)
{ return intersect(polygon, disk, eps); }
/*!
* \ingroup Intersection
* \brief Intersect a lateral cylinder surface and a disk.
......
......@@ -195,6 +195,22 @@ struct IntersectionTraits< Disk<ctype>, Quadrilateral<ctype, 3> >
: public IntersectionTraits< Quadrilateral<ctype, 3>, Disk<ctype> >
{};
//! Result type of the intersection of a polygon and a disk in 3d space
template<class ctype>
struct IntersectionTraits< Polygon<ctype, 3>, Disk<ctype> >
{
using type = std::variant< Point<ctype, 3>,
Segment<ctype, 3>,
TopoDS_Face,
EmptyIntersection<3> >;
};
//! Result type of the intersection of a disk and a polygon in 3d space
template<class ctype>
struct IntersectionTraits< Disk<ctype>, Polygon<ctype, 3> >
: public IntersectionTraits< Polygon<ctype, 3>, Disk<ctype> >
{};
//! Result type of the intersection of a cylinder surface and a disk
template<class ctype>
struct IntersectionTraits< CylinderSurface<ctype>, Disk<ctype> >
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment