Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/manual/development/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Changelog
=========

Upcoming version
****************

Pull Request #379 from godardma (27/04)
---------------------------------------

``Zonotope`` and ``Parallelepiped`` center is now ``c`` instead of ``z`` to avoid ambiguity.

Version 2.0.2
*************

Expand Down
Binary file modified doc/manual/manual/geometry/zonotope.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions doc/manual/manual/geometry/zonotope.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ A zonotope is a convex and symmetric polytope.
It can be represented as the Minkowski sum of a finite number of line segments, which are called its generators.

In Codac, zonotopes are represented by the class :class:`Zonotope`. A zonotope is defined by its center and its generators.
The center is a :class:`Vector`, noted :math:`z`, and the generators are stored in a :class:`Matrix`, noted :math:`A`.
The center is a :class:`Vector`, noted :math:`\mathbf{c}`, and the generators are stored in a :class:`Matrix`, noted :math:`\mathbf{A}`.
Each column of the matrix corresponds to a generator.

The resulting zonotope is:

.. math::
Z = z + A \cdot [-1,1]^m
Z = \mathbf{c} + \mathbf{A} \cdot [-1,1]^m

Where :math:`m` is the number of generators (i.e., the number of columns of the matrix :math:`A`).

Expand All @@ -37,24 +37,24 @@ It can be constructed in Codac as follows:

.. code-tab:: py

z = Vector([1,2])
c = Vector([1,2])
A = Matrix([[1,0,2],[0,1,1]])

Z = Zonotope(z, A)
Z = Zonotope(c, A)

.. code-tab:: c++

Vector z({1,2});
Vector c({1,2});
Matrix A({{1,0,2},{0,1,1}});

Zonotope Z(z, A);
Zonotope Z(c, A);

.. code-tab:: matlab

z = Vector({1,2});
c = Vector({1,2});
A = Matrix({{1,0,2},{0,1,1}});

Z = Zonotope(z,A);
Z = Zonotope(c,A);

The resulting zonotope is represented in the figure below:

Expand Down
8 changes: 6 additions & 2 deletions python/src/core/domains/zonotope/codac2_py_Zonotope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ void export_Zonotope(py::module& m)
ZONOTOPE_ZONOTOPE_PROJ_CONST_VECTOR_INDEX_REF_CONST,
"indices"_a)

.def_readwrite("z", &Zonotope::z,
VECTOR_ZONOTOPE_Z)
.def("__add__", &Zonotope::operator+,
ZONOTOPE_ZONOTOPE_OPERATORPLUS_CONST_ZONOTOPE_REF,
py::is_operator())

.def_readwrite("c", &Zonotope::c,
VECTOR_ZONOTOPE_C)

.def_readwrite("A", &Zonotope::A,
MATRIX_ZONOTOPE_A)
Expand Down
4 changes: 2 additions & 2 deletions python/src/graphics/figures/codac2_py_Figure3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void export_Figure3D(py::module& m)
CONST_STRING_REF_FIGURE3D_NAME_CONST)

.def("draw_axes", &Figure3D::draw_axes,
VOID_FIGURE3D_DRAW_AXES_DOUBLE,
"size"_a=1.0)
VOID_FIGURE3D_DRAW_AXES_DOUBLE_CONST_VECTOR_REF,
"size"_a=1.0, "origin"_a=Vector::Zero(3))

// Geometric shapes
.def("draw_triangle", (void(Figure3D::*)(const Vector &c, const Matrix &A, const Vector &p1, const Vector &p2, const Vector &p3, const StyleProperties &s))&Figure3D::draw_triangle,
Expand Down
20 changes: 10 additions & 10 deletions src/core/domains/zonotope/codac2_Parallelepiped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@

using namespace codac2;

Parallelepiped::Parallelepiped(const Vector& z_, const Matrix& A_)
: Zonotope(z_, A_)
Parallelepiped::Parallelepiped(const Vector& c_, const Matrix& A_)
: Zonotope(c_, A_)
{
assert_release(A.cols() <= z.size() && "too many vectors, you are describing a zonotope");
assert_release(A.cols() <= c.size() && "too many vectors, you are describing a zonotope");
}

void generate_vertices(Index i, Index n, const Vector& z, const Matrix& A, std::vector<Vector>& L_v)
void generate_vertices(Index i, Index n, const Vector& c, const Matrix& A, std::vector<Vector>& L_v)
{
if (i == n)
{
L_v.push_back(z);
L_v.push_back(c);
}
else if (i<n)
{
generate_vertices(i+1, n, z + A.col(i), A, L_v);
generate_vertices(i+1, n, z - A.col(i), A, L_v);
generate_vertices(i+1, n, c + A.col(i), A, L_v);
generate_vertices(i+1, n, c - A.col(i), A, L_v);
}
}

std::vector<Vector> Parallelepiped::vertices() const
{
std::vector<Vector> L_v;
generate_vertices(0, z.size(),z,A,L_v);
generate_vertices(0, c.size(),c,A,L_v);
return L_v;
}

Expand All @@ -46,9 +46,9 @@ BoolInterval Parallelepiped::contains(const Vector& v) const
BoolInterval Parallelepiped::is_superset(const IntervalVector& x) const
{
assert_release(A.rows() == A.cols() && "Matrix A must be square to check containment.");
assert_release(x.size() == z.size() && "Point dimension must match parallelepiped dimension.");
assert_release(x.size() == c.size() && "Point dimension must match parallelepiped dimension.");

IntervalVector B = inverse_enclosure(A)*(x - z);
IntervalVector B = inverse_enclosure(A)*(x - c);
IntervalVector IV = IntervalVector::constant(A.cols(),{-1,1});

if (!(B.intersects(IV)))
Expand Down
8 changes: 4 additions & 4 deletions src/core/domains/zonotope/codac2_Parallelepiped.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace codac2
/**
* \class Parallelepiped
*
* \brief Class representing a parallelepiped \f$\mathbf{z} + \mathbf{A}\cdot[-1,1]^m\f$
* \brief Class representing a parallelepiped \f$\mathbf{c} + \mathbf{A}\cdot[-1,1]^m\f$
*
* This class represents a parallelepiped in n-dimensional space, defined by a center point \f$\mathbf{z}\f$ and a shape matrix \f$\mathbf{A}\f$.
* This class represents a parallelepiped in n-dimensional space, defined by a center point \f$\mathbf{c}\f$ and a shape matrix \f$\mathbf{A}\f$.
*
* A parallelepiped is a special case of a zonotope where the shape matrix \f$\mathbf{A}\f$ has \f$m\f$ columns with \f$m \leqslant n\f$.
*/
Expand All @@ -34,10 +34,10 @@ namespace codac2
/**
* \brief Constructs a n-parallelepiped object with a given center and shape matrix
*
* \param z Center of the parallelepiped (n-dimensional vector)
* \param c Center of the parallelepiped (n-dimensional vector)
* \param A Shape matrix of the parallelepiped (\f$n\times m\f$ matrix with \f$m \leqslant n\f$)
*/
Parallelepiped(const Vector& z, const Matrix& A);
Parallelepiped(const Vector& c, const Matrix& A);

/**
* \brief Computes the vertices of the parallelepiped
Expand Down
27 changes: 19 additions & 8 deletions src/core/domains/zonotope/codac2_Zonotope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,42 @@

using namespace codac2;

Zonotope::Zonotope(const Vector& z_, const Matrix& A_)
: z(z_), A(A_)
Zonotope::Zonotope(const Vector& c_, const Matrix& A_)
: c(c_), A(A_)
{
assert_release(z.size() == A.rows());
assert_release(c.size() == A.rows());
}

IntervalVector Zonotope::box() const
{
return z + (A.template cast<Interval>())*IntervalVector::constant(A.cols(),{-1,1});
return c + (A.template cast<Interval>())*IntervalVector::constant(A.cols(),{-1,1});
}

Zonotope Zonotope::proj(const std::vector<Index>& indices) const
{
assert_release(*std::min_element(indices.begin(), indices.end()) >= 0 && "indices out of range");
assert_release(*std::max_element(indices.begin(), indices.end()) <= z.size() && "indices out of range");
assert_release(*std::max_element(indices.begin(), indices.end()) <= c.size() && "indices out of range");

Matrix A_cropped (indices.size(), A.cols());
Vector z_cropped (indices.size());
Vector c_cropped (indices.size());

for (size_t i = 0; i < indices.size(); ++i)
{
A_cropped.row(i) = A.row(indices[i]);
z_cropped[i] = z[indices[i]];
c_cropped[i] = c[indices[i]];
}

return Zonotope(z_cropped, A_cropped);
return Zonotope(c_cropped, A_cropped);
}

Zonotope Zonotope::operator+(const Zonotope& zonotope)
{
assert_release(c.size() == zonotope.c.size() && "Zonotopes must have the same dimension");

Vector c_sum = c + zonotope.c;
Matrix A_sum (A.rows(), A.cols() + zonotope.A.cols());

A_sum << A, zonotope.A;

return Zonotope(c_sum, A_sum);
}
21 changes: 15 additions & 6 deletions src/core/domains/zonotope/codac2_Zonotope.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace codac2
{
/**
* \class Zonotope
* \brief Class representing a zonotope \f$\mathbf{z} + \mathbf{A}\cdot[-1,1]^m\f$
* \brief Class representing a zonotope \f$\mathbf{c} + \mathbf{A}\cdot[-1,1]^m\f$
*
* This class represents a zonotope in n-dimensional space, defined by a center point \f$\mathbf{z}\f$ and a shape matrix \f$\mathbf{A}\f$.
* This class represents a zonotope in n-dimensional space, defined by a center point \f$\mathbf{c}\f$ and a shape matrix \f$\mathbf{A}\f$.
*
* The vector \f$\mathbf{z}\f$ and each column of the matrix \f$\mathbf{A}\f$ must have the same dimension \f$n\f$, but the matrix \f$\mathbf{A}\f$ can have any number of columns \f$m\f$.
* The vector \f$\mathbf{c}\f$ and each column of the matrix \f$\mathbf{A}\f$ must have the same dimension \f$n\f$, but the matrix \f$\mathbf{A}\f$ can have any number of columns \f$m\f$.
*/
class Zonotope
{
Expand All @@ -31,10 +31,10 @@ namespace codac2
/**
* \brief Constructs a n-zonotope object with a given center and shape matrix
*
* \param z Center of the zonotope (n-dimensional vector)
* \param c Center of the zonotope (n-dimensional vector)
* \param A Shape matrix of the zonotope (\f$n\times m\f$ matrix)
*/
Zonotope(const Vector& z, const Matrix& A);
Zonotope(const Vector& c, const Matrix& A);

/**
* \brief Computes the axis-aligned bounding box of the zonotope
Expand All @@ -52,10 +52,19 @@ namespace codac2
*/
Zonotope proj(const std::vector<Index>& indices) const;

/**
* \brief Computes the Minkowski sum of this Zonotope with another Zonotope
*
* \param zonotope The other Zonotope to add to this one
*
* \return A new Zonotope object representing the Minkowski sum of the two Zonotopes
*/
Zonotope operator+(const Zonotope& zonotope);

/**
* \brief Center of the zonotope
*/
Vector z;
Vector c;

/**
* \brief Shape matrix of the zonotope
Expand Down
6 changes: 3 additions & 3 deletions src/core/functions/analytic/codac2_AnalyticFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,17 @@ namespace codac2
"Parallelepiped evaluation requires at least one input.");

IntervalVector Y = this->eval(((typename Wrapper<Args>::Domain)(x)).mid()...);
Vector z = Y.mid();
Vector c = Y.mid();

Matrix A = this->diff(((typename Wrapper<Args>::Domain)(x)).mid()...).mid();

// Maximum error computation
double rho = error_peibos(Y, z, this->diff(x...), A, cart_prod(x...));
double rho = error_peibos(Y, c, this->diff(x...), A, cart_prod(x...));

// Inflation of the parallelepiped
Matrix A_inf = inflate_flat_parallelepiped(A, (cart_prod(x...).template cast<Interval>()).rad(), rho);

return Parallelepiped(z, A_inf);
return Parallelepiped(c, A_inf);
}

Index output_size() const
Expand Down
12 changes: 6 additions & 6 deletions src/graphics/figures/codac2_Figure2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void Figure2D::draw_zonotope(const Zonotope& z, const StyleProperties& style)
}
}
vector<Vector> vertices;
Vector point=z.z;
Vector point=z.c;
// Start from v[1] maximum (and v[0] min for horizontal side)
for (const auto& a : sides) {
point+=a.second;
Expand All @@ -277,17 +277,17 @@ void Figure2D::draw_zonotope(const Zonotope& z, const StyleProperties& style)

void Figure2D::draw_parallelepiped(const Parallelepiped& p, const StyleProperties& style)
{
assert_release(p.A.is_squared() && p.A.rows() == p.z.size());
assert_release(p.z.size() == 2);
assert_release(p.A.is_squared() && p.A.rows() == p.c.size());
assert_release(p.c.size() == 2);

auto a1 = p.A.col(0), a2 = p.A.col(1);

if (a1.isZero() || a2.isZero())
draw_polyline({p.z-a1-a2,p.z+a1+a2}, style);
draw_polyline({p.c-a1-a2,p.c+a1+a2}, style);
else
draw_polygon({
p.z+a1+a2, p.z-a1+a2,
p.z-a1-a2, p.z+a1-a2
p.c+a1+a2, p.c-a1+a2,
p.c-a1-a2, p.c+a1-a2
}, style);
}

Expand Down
10 changes: 5 additions & 5 deletions src/graphics/figures/codac2_Figure2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ namespace codac2
void draw_parallelepiped(const Parallelepiped& p, const StyleProperties& style = StyleProperties());

/**
* \brief Draws a zonotope z+sum_i [-1,1] A_i on the figure
* \brief Draws a zonotope c+sum_i [-1,1] A_i on the figure
*
* \param z Zonotope to draw (center and shape matrix)
* \param style Style of the zonotope (edge color and fill color)
Expand Down Expand Up @@ -856,15 +856,15 @@ namespace codac2
}

/**
* \brief Draws a zonotope z+sum_i [-1,1] A_i on the figure
* \brief Draws a zonotope c+sum_i [-1,1] A_i on the figure
*
* \param z Zonotope to draw (center and shape matrix)
* \param c Zonotope to draw (center and shape matrix)
* \param style Style of the zonotope (edge color and fill color)
*/
static void draw_zonotope(const Zonotope& z, const StyleProperties& style = StyleProperties())
static void draw_zonotope(const Zonotope& c, const StyleProperties& style = StyleProperties())
{
auto_init();
selected_fig()->draw_zonotope(z,style);
selected_fig()->draw_zonotope(c,style);
}

/**
Expand Down
Loading
Loading