version 3.10-dev
circumsphere.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
14#ifndef DUMUX_GEOMETRY_CIRCUMSPHERE_HH
15#define DUMUX_GEOMETRY_CIRCUMSPHERE_HH
16
17#include <type_traits>
18#include <dumux/common/math.hh>
20
21namespace Dumux {
22
28template<class Point>
29static inline Sphere<typename Point::value_type, Point::dimension>
30circumSphereOfTriangle(const Point& a, const Point& b, const Point& c)
31{
32 const auto ac = c - a;
33 const auto ab = b - a;
34 const auto n = crossProduct(ab, ac);
35 const auto distCenterToA = (crossProduct(n, ab)*ac.two_norm2() + crossProduct(ac, n)*ab.two_norm2()) / (2.0*n.two_norm2());
36
37 return { a + distCenterToA, distCenterToA.two_norm() };
38}
39
44template<class Geometry, typename std::enable_if_t<Geometry::mydimension == 2, int> = 0>
45static inline Sphere<typename Geometry::ctype, Geometry::coorddimension>
46circumSphereOfTriangle(const Geometry& triangle)
47{
48 assert(triangle.corners() == 3 && "Geometry is not a triangle.");
49 return circumSphereOfTriangle(triangle.corner(0), triangle.corner(1), triangle.corner(2));
50}
51
52} // end namespace Dumux
53
54#endif
Dune::FieldVector< Scalar, 3 > crossProduct(const Dune::FieldVector< Scalar, 3 > &vec1, const Dune::FieldVector< Scalar, 3 > &vec2)
Cross product of two vectors in three-dimensional Euclidean space.
Definition: math.hh:671
static Sphere< typename Point::value_type, Point::dimension > circumSphereOfTriangle(const Point &a, const Point &b, const Point &c)
Computes the circumsphere of a triangle.
Definition: circumsphere.hh:30
Define some often used mathematical functions.
Definition: adapt.hh:17
A function to compute bounding spheres of points clouds or convex polytopes.