29 : _radius(radius), _center(p)
35 : _radius(std::numeric_limits<double>::epsilon()), _center(p)
37 auto const vp = Eigen::Map<Eigen::Vector3d const>(p.getCoords());
38 auto const vq = Eigen::Map<Eigen::Vector3d const>(
q.getCoords());
39 Eigen::Vector3d
const a = vq - vp;
41 Eigen::Vector3d o = a / 2;
42 _radius = o.norm() + std::numeric_limits<double>::epsilon();
51 auto const vp = Eigen::Map<Eigen::Vector3d const>(p.getCoords());
52 auto const vq = Eigen::Map<Eigen::Vector3d const>(
q.getCoords());
53 auto const vr = Eigen::Map<Eigen::Vector3d const>(
r.getCoords());
54 Eigen::Vector3d
const a = vr - vp;
55 Eigen::Vector3d
const b = vq - vp;
56 Eigen::Vector3d
const axb = a.cross(b);
58 if (axb.squaredNorm() > 0)
60 double const denom = 2.0 * axb.dot(axb);
62 (b.dot(b) * axb.cross(a) + a.dot(a) * b.cross(axb)) / denom;
63 _radius = o.norm() + std::numeric_limits<double>::epsilon();
70 if (a.squaredNorm() > b.squaredNorm())
88 auto const vp = Eigen::Map<Eigen::Vector3d const>(p.getCoords());
89 auto const vq = Eigen::Map<Eigen::Vector3d const>(
q.getCoords());
90 auto const vr = Eigen::Map<Eigen::Vector3d const>(
r.getCoords());
91 auto const vs = Eigen::Map<Eigen::Vector3d const>(s.
getCoords());
93 Eigen::Vector3d
const va = vq - vp;
94 Eigen::Vector3d
const vb = vr - vp;
95 Eigen::Vector3d
const vc = vs - vp;
99 double const denom = 2.0 * va.cross(vb).dot(vc);
101 (vc.dot(vc) * va.cross(vb) + vb.dot(vb) * vc.cross(va) +
102 va.dot(va) * vb.cross(vc)) /
105 _radius = o.norm() + std::numeric_limits<double>::epsilon();
136 std::vector<MathLib::Point3d*>
const& points)
137 : _radius(-1), _center({0, 0, 0})
139 const std::vector<MathLib::Point3d*>& sphere_points(points);
141 recurseCalculation(sphere_points, 0, sphere_points.size(), 0);
147 std::vector<MathLib::Point3d*> sphere_points,
148 std::size_t start_idx,
150 std::size_t n_boundary_points)
153 switch (n_boundary_points)
163 *sphere_points[start_idx - 2]);
167 *sphere_points[start_idx - 2],
168 *sphere_points[start_idx - 3]);
172 *sphere_points[start_idx - 1], *sphere_points[start_idx - 2],
173 *sphere_points[start_idx - 3], *sphere_points[start_idx - 4]);
177 for (std::size_t i = 0; i < length; ++i)
185 std::vector<MathLib::Point3d*>::iterator::difference_type;
186 std::vector<MathLib::Point3d*>
const tmp_ps(
187 sphere_points.cbegin() +
static_cast<DiffType
>(start_idx),
188 sphere_points.cbegin() +
189 static_cast<DiffType
>(start_idx + i + 1));
190 std::copy(tmp_ps.cbegin(), --tmp_ps.cend(),
191 sphere_points.begin() +
192 static_cast<DiffType
>(start_idx + 1));
193 sphere_points[start_idx] = tmp_ps.back();
196 n_boundary_points + 1);
Calculation of a minimum bounding sphere for a vector of points.
Definition of the Point3d class.
static MinimalBoundingSphere recurseCalculation(std::vector< MathLib::Point3d * > sphere_points, std::size_t start_idx, std::size_t length, std::size_t n_boundary_points)
MinimalBoundingSphere()
Constructor using no points.
double getRadius() const
Returns the radius of the sphere.
MathLib::Point3d getCenter() const
Returns the center point of the sphere.
double pointDistanceSquared(MathLib::Point3d const &pnt) const
Returns the squared euclidean distance of a point from the sphere (for points within the sphere dista...
const T * getCoords() const
void copy(PETScVector const &x, PETScVector &y)
bool isCoplanar(const MathLib::Point3d &a, const MathLib::Point3d &b, const MathLib::Point3d &c, const MathLib::Point3d &d)
Checks if the four given points are located on a plane.
MathLib::TemplatePoint< double, 3 > Point3d
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)