9#ifndef IMPALGEBRA_UNIT_SIMPLEX_D_H
10#define IMPALGEBRA_UNIT_SIMPLEX_D_H
12#include <IMP/algebra/algebra_config.h>
17#include <boost/math/special_functions/gamma.hpp>
18#include <cereal/access.hpp>
24IMPALGEBRA_BEGIN_NAMESPACE
49 double atol = std::numeric_limits<double>::epsilon())
const {
50 int d = p.get_dimension();
53 for (
int i = 0; i < d; ++i) {
54 if (p[i] < 0)
return false;
57 if (std::abs(nrm - 1) > d * atol)
return false;
71 friend class cereal::access;
73 template<
class Archive>
void serialize(Archive &ar) {}
76 UnitSimplexD() {
IMP_USAGE_CHECK(D > 0,
"Dimension must be positive."); }
90 friend class cereal::access;
92 template<
class Archive>
void serialize(Archive &ar) {
107 { out <<
"UnitSimplexKD(" << d_ <<
")"; });
113typedef UnitSimplexD<1> UnitSimplex1D;
132 int d = s.get_dimension();
133 for (
int i = 0; i < d; ++i)
140 return Triangle3D(ps[0], ps[1], ps[2]);
150 int d = s.get_dimension();
152 "Dimension of point must match dimension of simplex.");
155 std::partial_sum(p.begin(), p.end(), q.begin());
164 int d = s.get_dimension();
166 "Dimension of point must match dimension of simplex.");
168 std::adjacent_difference(p.begin(), p.end(), q.begin());
182 int d = s.get_dimension();
184 "Dimension of point must match dimension of simplex.");
186 if (s.get_contains(p))
return p;
189 std::sort(u.begin(), u.end(), std::greater<double>());
192 std::partial_sum(u.begin(), u.end(), u_cumsum.begin());
196 if (u[rho] + (1 - u_cumsum[rho]) / (rho + 1) < 0)
break;
199 double lam = (1 - u_cumsum[rho - 1]) / rho;
201 for (
int i = 0; i < d; ++i) {
202 double ui = p[i] + lam;
203 u[i] = ui > 0 ? ui : 0.0;
209IMPALGEBRA_END_NAMESPACE
Base class for geometric types.
Represent a triangle in 3D.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
A Cartesian vector in D-dimensions.
A more IMP-like version of the std::vector.
Represent a triangle in 3D.
Base class for a unit simplex embedded in D-dimensional real space.
VectorD< D > get_barycenter() const
Get center of mass on simplex in embedded coordinates.
virtual int get_dimension() const =0
Get dimension D of embedded real space.
bool get_contains(const VectorD< D > &p, double atol=std::numeric_limits< double >::epsilon()) const
Get whether the point is on the unit simplex.
int get_dimension() const override
Get dimension of embedded real space.
UnitSimplexD(int d=1)
Construct from dimension d of embedded real space.
Represent a unit simplex embedded in D-dimensional real space.
int get_dimension() const override
Get dimension D of embedded real space.
IMP::Vector< UnitSimplexKD > UnitSimplexKDs
IMP::Vector< UnitSimplex6D > UnitSimplex6Ds
VectorD< D > get_zero_vector_kd(int Di)
Return a dynamically sized vector of zeros.
IMP::Vector< UnitSimplex2D > UnitSimplex2Ds
VectorD< D > get_increasing_from_embedded(const UnitSimplexD< D > &s, const VectorD< D > &p)
Convert point on simplex from embedded to increasing coordinates.
VectorD< D > get_ones_vector_kd(unsigned int Di, double v=1)
Return a vector of ones (or another constant).
IMP::Vector< UnitSimplex5D > UnitSimplex5Ds
IMP::Vector< UnitSimplex1D > UnitSimplex1Ds
Vector3D get_projected(const Line3D &l, const Vector3D &p)
Project a point onto the line.
VectorD< D > get_embedded_from_increasing(const UnitSimplexD< D > &s, const VectorD< D > &p)
Convert point on simplex from increasing to embedded coordinates.
IMP::Vector< UnitSimplex3D > UnitSimplex3Ds
VectorD< D > get_basis_vector_kd(int Di, unsigned int coordinate)
Return the basis vector for the given coordinate.
IMP::Vector< UnitSimplex4D > UnitSimplex4Ds
Vector< VectorD< D > > get_vertices(const BoundingBoxD< D > &bb)
Return a list of the 2^D bounding points for the bounding box.
Vector< VectorD< 3 > > Vector3Ds
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Macros to help with objects that can be printed to a stream.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.