Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f817d46
Polytope, first version
damien-masse Apr 29, 2025
9826bbd
Merge branch 'codac2_dev' into codac2_polytope
damien-masse May 9, 2025
e6a6966
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse May 13, 2025
ba2130c
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse May 21, 2025
ef7c62f
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Jun 2, 2025
20df663
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Jun 20, 2025
1e6d368
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Jun 30, 2025
189c1e5
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Jul 16, 2025
6079cd9
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Jul 21, 2025
ae394eb
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Aug 25, 2025
5d9a3a6
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Sep 11, 2025
93a76fa
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Sep 25, 2025
fc67e66
partial construction
damien-masse Sep 29, 2025
2058340
Merge branch 'codac2_polytope' of https://github.com/damien-masse/cod…
damien-masse Sep 29, 2025
9fb8b3a
followup
damien-masse Oct 1, 2025
1393057
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Oct 15, 2025
8db0568
temporaire
damien-masse Oct 15, 2025
54e98e1
Merge branch 'codac2_polytope' of https://github.com/damien-masse/cod…
damien-masse Oct 15, 2025
71f1509
tmp
damien-masse Oct 17, 2025
eeb1912
tmp
damien-masse Oct 21, 2025
c2a77e0
better, but not complete
damien-masse Oct 27, 2025
b300c48
example
damien-masse Oct 27, 2025
ae60ce3
Change
damien-masse Nov 4, 2025
dd0ecdf
temporary commit
damien-masse Nov 5, 2025
cdadead
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Nov 7, 2025
f90a827
correction?
damien-masse Nov 10, 2025
5f0dcdc
First tests, hull...
damien-masse Nov 14, 2025
7d3f54f
Intersection of polytopes
damien-masse Nov 18, 2025
4a5d908
Separation between polytope-clp and polytope.
damien-masse Nov 21, 2025
ca54be1
Python bindings (partial), python tests. Manual (preliminary version).
damien-masse Nov 21, 2025
06dfb83
Merge branch 'codac2_dev' into codac2_polytope
damien-masse Nov 21, 2025
cc5aee1
Merge branch 'codac-team:codac2' into codac2_polytope
damien-masse Nov 22, 2025
e9337a1
Modification for readability, new tests.
damien-masse Nov 24, 2025
777df53
Bug fixes, renaming of methods, clp fixes.
damien-masse Nov 25, 2025
c8fa180
Centered form with polytopes. Better separation with CLP. Some bug fi…
damien-masse Nov 26, 2025
ee74c7b
Left- and right- "pseudoinverse" enclosure for non-square matrices.
damien-masse Dec 1, 2025
8686d66
bugfix in python
damien-masse Dec 1, 2025
e37e13f
Polytope contractor and separator
damien-masse Dec 12, 2025
99bd953
Polytope: test contractor and separator + python binding for contract…
damien-masse Dec 15, 2025
a98a2e1
Small improvement to the doc.
damien-masse Dec 15, 2025
4c12b26
Few modifications.
damien-masse Dec 18, 2025
258fa6e
Remove CLP extension.
damien-masse Dec 18, 2025
f974f6c
Remove clp tests
damien-masse Dec 18, 2025
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,4 @@
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CODAC_URL})
# todo: finish deb package

include(CPack)
include(CPack)
33 changes: 33 additions & 0 deletions doc/manual/manual/geometry/facets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. _sec-polytope:

Facet classes
=============

Main author: `Damien Massé <https://labsticc.fr/fr/annuaire/masse-damien>`_

Facets
------

.. doxygentypedef:: codac2::Facet
:project: codac

.. doxygennamespace:: codac2::Facet_
:project: codac
:members:

.. doxygenclass:: codac2::FacetBase
:project: codac
:members:

.. doxygenclass:: codac2::FacetRhs
:project: codac
:members:


Collection of facets
--------------------

.. doxygenclass:: codac2::CollectFacets
:project: codac
:members:

3 changes: 2 additions & 1 deletion doc/manual/manual/geometry/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Geometry
========

Codac provides a set of utility functions for basic 2d geometric calculations.
Codac provides a set of utility functions for basic geometric calculations.

Several basic geometric types are available under the form of classes representing enclosures of these types. For instance, a 2d point if represented by an ``IntervalVector`` enclosing it, a segment between two 2d points is implemented by the ``Segment`` class, the endpoints of which are ``IntervalVector`` objects. Furthermore, ``Polygon`` and ``ConvexPolygon`` are also available. Operations between these structure will reliably meet the uncertainties associated with the enclosure of points (vertices), as well as floating-point calculations.

Expand All @@ -16,6 +16,7 @@ Because computations are based on interval arithmetic, all these functions provi
segment.rst
polygon.rst
zonotope.rst
polytope.rst

Related interval enumerations
-----------------------------
Expand Down
60 changes: 60 additions & 0 deletions doc/manual/manual/geometry/polytope.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.. _sec-polytope:

Polytope
========

Main author: `Damien Massé <https://labsticc.fr/fr/annuaire/masse-damien>`_

The Polytope class represent convex polytopes (or, more generally,
convex polyhedra).
Polytopes are internally represented as intersections of linear constraints
(and a bounding box), in a class name CollectFacets.
A double-description algorithm is used to compute generators for operations
requiring them (union, projections...). Due to the imprecise nature of
floating-point computations, the algorithm is designed such that the
convex hull of the "generators" encloses the polytope. However, no guarantee
is given that each vertice of the polytope is associated to a generator.
As a result,
going back to the hyperplane representation may return a larger polytope.

.. toctree::
:maxdepth: 1

facets.rst
polytope_class.rst


Building a polytope
-------------------
Polytopes can be defined from a set of facets (linear inequalities
or equalities), or a set of vertices.

.. tabs::

.. group-tab:: C++

.. literalinclude:: src_polytope.cpp
:language: c++
:start-after: [polytope-1-beg]
:end-before: [polytope-1-end]
:dedent: 2

Output of a polytope
--------------------
Polytopes are displayed as a set of linear constraints and a bounding box.
To display the set of vertices, one can use the
vertices() method.

.. tabs::

.. group-tab:: C++

.. literalinclude:: src_polytope.cpp
:language: c++
:start-after: [polytope-2-beg]
:end-before: [polytope-2-end]
:dedent: 2

Operations on polytopes
-----------------------

14 changes: 14 additions & 0 deletions doc/manual/manual/geometry/polytope_class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _sec-polytope:

The Polytope class
==================

Main author: `Damien Massé <https://labsticc.fr/fr/annuaire/masse-damien>`_

Polytope
--------

.. doxygenclass:: codac2::Polytope
:project: codac
:members:

83 changes: 83 additions & 0 deletions doc/manual/manual/geometry/src_polytope.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Author : Damien Massé
// Graphical illustration of the polytope test

#include <codac>
#include <vector>
#include <memory>

using namespace std;
using namespace codac2;

void draw_polytope(Figure3D &fig, const Polytope &P, const StyleProperties &st) {
std::vector<std::vector<Vector>> facets3D=P.vertices_3Dfacets();
Vector center = Vector::zero(3);
Matrix transfo = Matrix::Identity(3,3);
for (const std::vector<Vector> &vec : facets3D) {
fig.draw_polygon(center,transfo,vec,st);
}
}

int main(int argc, char *argv[])
{
// std::cout << std::scientific << std::setprecision(20);

Figure3D fig("manual_polytope");

fig.draw_axes();

// [polytope-1-beg]
// definition using vertices
std::vector<Vector> vertices
{ {0,0,0}, {2,1,0}, {-1,1,0}, {0,1.5,2}, {-1.5,0,-1.5}, {0,3,0} };
Polytope p1(vertices); // vertices {0,0,0}, {2,1,0}, etc.
// definition using facets
std::vector<std::pair<Row,double>> facets
{ { {1,1,0.75}, 3 }, // x+y+0.75z <= 3
{ {-1,-0.4,0.6} ,0.6 }, // -x-0.4y+0.6z <= 0.6
{ {-1,0.5,0.375} ,1.5 }, // ...
{ {-1,0.5,0} ,1.5 },
{ {0.5,-1,0.75} ,0 },
{ {-0.75,-1,0.75} ,0 },
{ {0.5,-1,-0.5} ,0 },
{ {1.0/3.0,1.0/3.0,-1} ,1 } };
// the first argument is a bounding box, here the whole space
Polytope p2(IntervalVector(3), facets);
// p1 and p2 are almost the same polytope
// [polytope-1-end]


// [polytope-2-beg]
std::cout << p1 << std::endl;
/* output, each facet is a row (sequences of double) and a right-hand-side
Polytope(bbox [ [-1.5, 2] ; [0, 3] ; [-1.5, 2] ]) :
Collectfacets : 8 facets
1 : 1 1 0.75<=3
2 : -1 -0.399999 0.6<=0.600001
3 : -1 0.5 0.375<=1.5
4 : -1 0.5 1.77636e-16<=1.5
5 : 0.5 -1 0.75<=0
6 : -0.75 -1 0.750001<=5.92119e-16
7 : 0.5 -1 -0.5<=0
8 : 0.333334 0.333334 -1<=1
end Collectfacets
EndPolytope
*/
std::vector<IntervalVector> vp2 = p2.vertices(); /* hull of p2 */
for (auto &v : vp2) std::cout << v << std::endl;
/* output : "vertices" are boxes which enclose the polytope, but each
box may not enclose a "real vertice". E.g. the vertice (0,0,0) is
not inside the second box displayed.
[ [1.99999, 2.00001] ; [0.999999, 1.00001] ; [-2.4743e-14, -1.70641e-15] ]
[ [-7.76463e-15, 1.69539e-14] ; [-3.15401e-14, -2.88916e-15] ; [-2.52802e-14, -2.40763e-15] ]
[ [-1.50001, -1.5] ; [-1.16016e-14, -9.33785e-15] ; [-1.50001, -1.5] ]
[ [-7.11673e-15, 1.609e-14] ; [1.49999, 1.50001] ; [1.99999, 2.00001] ]
[ [-2.47539e-15, 9.90153e-16] ; [2.99999, 3.00001] ; [-2.31036e-15, 3.30051e-15] ]
[ [-1.00001, -0.999999] ; [1, 1.00001] ; [1.83361e-15, 3.20883e-15] ]
*/
// [polytope-2-end]

fig.draw_polytope(p1,StyleProperties(Color::dark_red(0.8),"p1"));
fig.draw_polytope(p2,StyleProperties(Color::dark_blue(0.8),"p2"));

return 0;
}
4 changes: 4 additions & 0 deletions doc/manual/manual/visualization/3d_visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Geometric shapes
- Box
- Parallelepiped
- Zonotope
- Polytope
- Arrow
- Parametric surface
- Sphere
Expand Down Expand Up @@ -85,6 +86,9 @@ generally a sequence of adjacent triangles sharing a same vertex.
.. doxygenfunction:: codac2::Figure3D::draw_zonotope(const Zonotope&, const StyleProperties&)
:project: codac

.. doxygenfunction:: codac2::Figure3D::draw_polytope(const Polytope&, const StyleProperties&)
:project: codac

.. doxygenfunction:: codac2::Figure3D::draw_arrow(const Vector&, const Matrix& A, const StyleProperties&)
:project: codac

Expand Down
4 changes: 4 additions & 0 deletions doc/manual/manual/visualization/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Geometric shapes
- Polygone
- Parallelepiped
- Zonotope
- Polytope
- Pie
- Ellipse
- Ellipsoid
Expand Down Expand Up @@ -122,6 +123,9 @@ Geometric shapes
.. doxygenfunction:: codac2::Figure2D::draw_zonotope(const Zonotope&, const StyleProperties&)
:project: codac

.. doxygenfunction:: codac2::Figure2D::draw_polytope(const Polytope&, const StyleProperties&)
:project: codac

.. doxygenfunction:: codac2::Figure2D::draw_pie(const Vector&, const Interval&, const Interval&, const StyleProperties&)
:project: codac

Expand Down
2 changes: 2 additions & 0 deletions examples/07_centered_2D/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ int main(){

Parallelepiped p = f1.parallelepiped_eval(T);
fig4.draw_parallelepiped(p,{{Color::black(),Color::green(0.1)},"parallelepipeds"});
Polytope p2 = f1.polytope_eval(T);
fig4.draw_polytope(p2,{{Color::black(),Color::red(0.1)},"polytopes"});
}
time = time+dt;
}
Expand Down
26 changes: 25 additions & 1 deletion examples/08_centered_3D/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using namespace std;
using namespace codac2;


int main()
{
VectorVar x(2);
Expand Down Expand Up @@ -47,6 +48,29 @@ int main()
}
phi=phi+dphi;
}
phi=0.0;
while (phi<2*PI) {
psi=0.0;
while (psi<2*PI) {
IntervalVector T { {phi,phi+dphi}, {psi,psi+dpsi} };
Polytope P = f.polytope_eval(T);
fig_zon.draw_polytope(P, { Color::blue(0.5), "polytope" });
psi=psi+dpsi;
}
phi=phi+dphi;
}

phi=0.0;
while (phi<2*PI) {
psi=0.0;
while (psi<2*PI) {
IntervalVector T { {phi,phi+dphi}, {psi,psi+dpsi} };
IntervalVector Q = f.eval(T);
fig_zon.draw_box(Q, { Color::purple(0.5), "box" });
psi=psi+dpsi;
}
phi=phi+dphi;
}

fig_zon.draw_surface({0,0,0}, Matrix::Identity(3,3),
Interval(0,2*PI),
Expand All @@ -58,6 +82,6 @@ int main()
2.0*sin(phi)*cos(phi)/(1+(sin(phi)*sin(phi)))
};
} ,
{ Color::green(0.6), "surface" });
{ Color::green(0.8), "surface" });

}
44 changes: 44 additions & 0 deletions examples/polytope_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ==================================================================
# codac / basics example - cmake configuration file
# ==================================================================

cmake_minimum_required(VERSION 3.5)
project(codac_example LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Adding IBEX

# In case you installed IBEX in a local directory, you need
# to specify its path with the CMAKE_PREFIX_PATH option.
# set(CMAKE_PREFIX_PATH "~/ibex-lib/build_install")

find_package(IBEX REQUIRED)
ibex_init_common() # IBEX should have installed this function
message(STATUS "Found IBEX version ${IBEX_VERSION}")

# Adding Codac

# In case you installed Codac in a local directory, you need
# to specify its path with the CMAKE_PREFIX_PATH option.
# set(CMAKE_PREFIX_PATH "~/codac/build_install")

find_package(CODAC REQUIRED)
message(STATUS "Found Codac version ${CODAC_VERSION}")

# Compilation

if(FAST_RELEASE)
add_compile_definitions(FAST_RELEASE)
message(STATUS "You are running Codac in fast release mode. (option -DCMAKE_BUILD_TYPE=Release is required)")
endif()

set(PROGS main-F2V main-3Dgraphics main-V2F main-3Dhull main-3Dtest main-manual main-contractor)

foreach(PROG ${PROGS})
add_executable(${PROG} ${PROG}.cpp)
target_compile_options(${PROG} PUBLIC ${CODAC_CXX_FLAGS})
target_include_directories(${PROG} SYSTEM PUBLIC ${CODAC_INCLUDE_DIRS})
target_link_libraries(${PROG} PUBLIC ${CODAC_LIBRARIES} Ibex::ibex)
endforeach()
17 changes: 17 additions & 0 deletions examples/polytope_examples/bla.ine
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
H-representation
begin
12 7 real
0 0 1 1 0 0 -1
0 1 0 1 0 -1 0
0 1 1 0 -1 0 0
0 1 0 -1 0 1 0
0 1 -1 0 1 0 0
0 0 0 0 1 1 -1
0 0 1 -1 0 0 1
0 0 0 0 1 -1 1
0 -1 1 0 1 0 0
0 0 0 0 -1 1 1
0 0 -1 1 0 0 1
0 -1 0 1 0 1 0
end

14 changes: 14 additions & 0 deletions examples/polytope_examples/bug45.ine
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
* This is to check whether issue #45 is fixed.
* Only the origin satisfies all equations/inequalities.
* The correct output of "cddexec --redcheck <examples/bug45.ine"
* is in bug45res.ine.
H-representation
linearity 2 1 2
begin
5 4 real
0.0 0.0 1.0 1.0
-1.0 0.0 1.0 1.0
-1.0 2.0 -1.0 0.0
-1.0 4.0 -2.0 0.0
1 0 0 0
end
Loading
Loading