2D drawing functions
Main author: Maël Godard
This page lists all the 2D drawing functions available in Codac. Note that the functions described here on a Figure2D object also work on the DefaultFigure.
For example :
# On a figure
fig.draw_box([[2.2,2.5],[2.2,2.5]])
# On the DefaultFigure
DefaultFigure.draw_box([[2.2,2.5],[2.2,2.5]])
// On a figure
fig.draw_box({{2.2,2.5},{2.2,2.5}});
// On the DefaultFigure
DefaultFigure::draw_box({{2.2,2.5},{2.2,2.5}});
In addition to the arguments described here for every function, an optionnal argument of type StyleProperties can be added to choose the edge and fill color (by default black edge no fill). This object can be deduced from one or two Color objects, see this page for more information.
fig.draw_box([[2.2,2.5],[2.2,2.5]],Color.red()) # Red edge
fig.draw_box([[2.2,2.5],[2.2,2.5]],[Color.red()]) # Red edge
fig.draw_box([[2.2,2.5],[2.2,2.5]],[Color.red(),Color.blue()]) # Red edge and blue fill
fig.draw_box({{2.2,2.5},{2.2,2.5}},Color.red()); // Red edge
fig.draw_box({{2.2,2.5},{2.2,2.5}},{Color.red()}); // Red edge
fig.draw_box({{2.2,2.5},{2.2,2.5}},{Color.red(),Color.blue()}); // Red edge and blue fill
A line style and a layer can be added to the StyleProperties object, see the dedicated page for more information.
Overview of the functions
Below are the detailled available drawing functions. The shapes that can be drawn are:
- Geometric shapes
Point
Box
Circle
Ring
Line
Arrow
Polyline
Polygone
Parallelepiped
Zonotope
Pie
Ellipse
Ellipsoid
- Trajectories
Sampled Trajectory
Analytic Trajectory
- Vehicles
Tank
AUV
Motor Boat
- Paving
PavingOut (Paving with contractors)
PavingInOut (Paving with separators)
Subpaving
Geometric shapes
-
void codac2::Figure2D::draw_point(const Vector &c, const StyleProperties &style = StyleProperties())
Draws a point on the figure.
- Parameters:
c – Coordinates of the point
style – Style of the point (edge color and fill color)
-
void codac2::Figure2D::draw_box(const IntervalVector &x, const StyleProperties &style = StyleProperties())
Draws a box on the figure.
- Parameters:
x – Box to draw
style – Style of the box (edge color and fill color)
-
void codac2::Figure2D::draw_circle(const Vector &c, double r, const StyleProperties &style = StyleProperties())
Draws a circle on the figure.
- Parameters:
c – Center of the circle
r – Radius of the circle
style – Style of the circle (edge color and fill color)
-
void codac2::Figure2D::draw_ring(const Vector &c, const Interval &r, const StyleProperties &style = StyleProperties())
Draws a ring on the figure.
- Parameters:
c – Center of the ring
r – Inner and outer radius of the ring
style – Style of the ring (edge color and fill color)
-
void codac2::Figure2D::draw_line(const Vector &p1, const Vector &p2, const StyleProperties &style = StyleProperties())
Draws a line on the figure.
- Parameters:
p1 – First point of the line
p2 – Second point of the line
style – Style of the line (edge color)
-
void codac2::Figure2D::draw_line(const Segment &e, const StyleProperties &style = StyleProperties())
Draws a line on the figure.
- Parameters:
e – segment to be drawn
style – Style of the line (edge color)
-
void codac2::Figure2D::draw_arrow(const Vector &p1, const Vector &p2, float tip_length, const StyleProperties &style = StyleProperties())
Draws an arrow on the figure.
- Parameters:
p1 – First point of the arrow
p2 – Second point of the arrow
tip_length – Length of the tip of the arrow
style – Style of the arrow (edge color and fill color)
-
void codac2::Figure2D::draw_polyline(const std::vector<Vector> &x, const StyleProperties &style = StyleProperties())
Draws a polyline on the figure.
- Parameters:
x – Vector of the points of the polyline
style – Style of the polyline (edge color)
-
void codac2::Figure2D::draw_polyline(const std::vector<Vector> &x, float tip_length, const StyleProperties &style = StyleProperties())
Draws a polyline on the figure.
- Parameters:
x – Vector of the points of the polyline
tip_length – Length of the tip of the arrow
style – Style of the polyline (edge color and fill color)
-
void codac2::Figure2D::draw_polygon(const Polygon &x, const StyleProperties &style = StyleProperties())
Draws a
Polygonobject on the figure.- Parameters:
x – the
Polygonobject to be displayedstyle – Style of the polygone (edge color and fill color)
-
void codac2::Figure2D::draw_parallelepiped(const Parallelepiped &p, const StyleProperties &style = StyleProperties())
Draws a parallelepiped z+A*[-1,1]^2 on the figure.
- Parameters:
p – Parallelepiped to draw (center and shape matrix)
style – Style of the parallelepiped (edge color and fill color)
-
void codac2::Figure2D::draw_zonotope(const Zonotope &z, const StyleProperties &style = StyleProperties())
Draws a zonotope z+sum_i [-1,1] A_i on the figure.
- Parameters:
z – Zonotope to draw (center and shape matrix)
style – Style of the zonotope (edge color and fill color)
-
void codac2::Figure2D::draw_pie(const Vector &c, const Interval &r, const Interval &theta, const StyleProperties &style = StyleProperties())
Draws a pie on the figure.
- Parameters:
c – Center of the pie
r – Inner and outer radius of the pie
theta – Start and end angle of the pie (in radians)
style – Style of the pie (edge color and fill color)
-
void codac2::Figure2D::draw_ellipse(const Vector &c, const Vector &ab, double theta, const StyleProperties &style = StyleProperties())
Draws an ellipse on the figure.
- Parameters:
c – Center of the ellipse
ab – Half-lengths of the ellipse
theta – Rotation angle of the ellipse (in radians)
style – Style of the ellipse (edge color and fill color)
-
void codac2::Figure2D::draw_ellipsoid(const Ellipsoid &e, const StyleProperties &style = StyleProperties())
Draws an ellipsoid on the figure.
- Parameters:
e – Ellipsoid to draw
style – Style of the ellipsoid (edge color and fill color)
Trajectories and tubes
-
void codac2::Figure2D::draw_trajectory(const SampledTraj<Vector> &x, const StyleProperties &style = StyleProperties())
Draws a trajectory on the figure.
- Parameters:
x – SampledTraj to draw
style – Style of the trajectory (edge color)
-
void codac2::Figure2D::draw_trajectory(const AnalyticTraj<VectorType> &x, const StyleProperties &style = StyleProperties())
Draws a trajectory on the figure.
- Parameters:
x – AnalyticTraj to draw
style – Style of the trajectory (edge color)
Trajectories can be drawn with a ColorMap instead of the classic StyleProperties. This can be done by passing a ColorMap object as the second argument.
-
void codac2::Figure2D::draw_trajectory(const SampledTraj<Vector> &x, const StyleGradientProperties &style)
Draws a trajectory on the figure with a colormap.
- Parameters:
x – SampledTraj to plot
style – StyleGradientProperties to use
-
void codac2::Figure2D::draw_trajectory(const AnalyticTraj<VectorType> &x, const StyleGradientProperties &style)
Draws a trajectory on the figure with a colormap.
- Parameters:
x – AnalyticTraj to plot
style – StyleGradientProperties to use
-
void codac2::Figure2D::draw_tube(const SlicedTube<IntervalVector> &x, const StyleProperties &style, int max_nb_slices_to_display = 5000)
Draws a tube of
IntervalVectoron the figure with someStyleProperties.This function renders the slices (boxes) that compose a
SlicedTube.
If the number of slices exceeds
max_nb_slices_to_display, consecutive rectangular slices are merged by groups into convex polygons.
This reduces visual clutter and improves rendering efficiency while preserving the overall shape of the tube.
- Parameters:
x – SlicedTube to draw.
style – Style properties used for drawing the tube.
max_nb_slices_to_display – Maximum number of slices to display before merging them into convex polygons.
-
void codac2::Figure2D::draw_tube(const SlicedTube<IntervalVector> &x, const StyleGradientProperties &style = StyleGradientProperties(ColorMap::blue_tube()), int max_nb_slices_to_display = 5000)
Draws a tube of
IntervalVectoron the figure with a colormap.This function renders the slices (boxes) that compose a
SlicedTube.
If the number of slices exceeds
max_nb_slices_to_display, consecutive rectangular slices are merged by groups into convex polygons.
This reduces visual clutter and improves rendering efficiency while preserving the overall shape of the tube.
- Parameters:
x – SlicedTube to draw.
style – StyleGradientProperties to use
max_nb_slices_to_display – Maximum number of slices to display before merging them into convex polygons.
-
void codac2::Figure2D::plot_tube(const SlicedTube<Interval> &x, const StyleProperties &style = StyleProperties())
Plots a tube on the figure (x-axis is the time)
- Parameters:
x – SlicedTube to plot
style – Style of the tube (edge color)
-
void codac2::Figure2D::plot_tube(const SlicedTube<Interval> &x, const SlicedTube<Interval> &v, const StyleProperties &style = StyleProperties())
Plots a tube on the figure (x-axis is the time), with derivative information: slices are displayed as polygons.
- Parameters:
x – SlicedTube to plot
v – derivative tube of the SlicedTube to plot
style – Style of the tube (edge color)
Vehicles
-
void codac2::Figure2D::draw_tank(const Vector &x, float size, const StyleProperties &style = StyleProperties())
Draws a tank on the figure.
- Parameters:
x – Coordinates of the tank
size – Size of the tank
style – Style of the tank (edge color and fill color)
-
void codac2::Figure2D::draw_AUV(const Vector &x, float size, const StyleProperties &style = StyleProperties())
Draws an AUV on the figure.
- Parameters:
x – Coordinates of the AUV
size – Size of the AUV
style – Style of the AUV (edge color and fill color)
-
void codac2::Figure2D::draw_motor_boat(const Vector &x, float size, const StyleProperties &style = StyleProperties())
Draws a motor boat on the figure.
- Parameters:
x – Coordinates of the motor boat
size – Size of the motor boat
style – Style of the motor boat (edge color and fill color)
Miscellaneous
-
void codac2::Figure2D::draw_text(const std::string &text, const Vector &ul, double scale, const StyleProperties &style = StyleProperties())
Draws text on the figure.
- Parameters:
text – Text to display
ul – Position of the top-left corner of the text
scale – Scaling of the text (VIBes only)
style – Style of the text (color, layer)
-
void codac2::Figure2D::draw_raster(const std::string &filename, const IntervalVector &bbox, const StyleProperties &style = StyleProperties())
Draws a raster on the figure in VIBes only, only the bounding box is drawn in IPE.
- Parameters:
filename – The name of the file, the path is relative to the VIBes’ server folder
bbox – The bounding box of the raster
style – Style of the raster (only the layer is used)
Paving
-
void codac2::Figure2D::draw_paving(const PavingOut &p, const PavingStyle &style = PavingStyle::default_style())
Draws a previously computed paving (outer approximation) on the figure.
- Parameters:
p – PavingOut to draw (result of a paving with contractors)
style –
PavingStylefor the drawing
-
void codac2::Figure2D::draw_paving(const PavingOut &p, const std::function<void(Figure2D&, const IntervalVector&, const StyleProperties&)> &draw_box, const PavingStyle &style = PavingStyle::default_style())
Draws a previously computed paving (outer approximation) on the figure.
- Parameters:
p – PavingOut to draw (result of a paving with contractors)
draw_box – Custom drawing function (for instance, if one wants to draw in polar coordinates)
style –
PavingStylefor the drawing
-
void codac2::Figure2D::draw_paving(const PavingInOut &p, const PavingStyle &style = PavingStyle::default_style())
Draws a previously computed paving (inner/outer approximation) on the figure.
- Parameters:
p – PavingInOut to draw (result of a paving with separators)
style –
PavingStylefor the drawing
-
void codac2::Figure2D::draw_paving(const PavingInOut &p, const std::function<void(Figure2D&, const IntervalVector&, const StyleProperties&)> &draw_box, const PavingStyle &style = PavingStyle::default_style())
Draws a previously computed paving (inner/outer approximation) on the figure.
- Parameters:
p – PavingInOut to draw (result of a paving with separators)
draw_box – Custom drawing function (for instance, if one wants to draw in polar coordinates)
style –
PavingStylefor the drawing