The 3D Figure class

This page describes the class used in Codac for 3D visualization.

Figure3D

The basic class for 3D visualization is Figure3D. It is used to generate a .obj file that can be imported in any 3D visualization software.

For online visualization, the free website 3dviewer can be used.

The constructor takes one arguments: the name of the object file.

fig = Figure3D("my_object") # for the object file my_object.obj

Drawing functions

Below are the detailled available drawing functions. The shapes that can be drawn are:

Geometric shapes
  • Triangle

  • Parallelogram

  • Star-shaped polygon

  • Box

  • Parallelepiped

  • Zonotope

  • Arrow

  • Parametric surface

  • Sphere

Paving
  • PavingOut (Paving with contractors)

  • PavingInOut (Paving with separators)

  • Subpaving

Vehicles
  • Car

  • Plane

In addition, a function draw_axes is available to draw the three axes of the 3D space.

void codac2::Figure3D::draw_axes(double size = 1.0)

Draws the (x,y,z) axes on the figure in red, green and blue.

Parameters:

size – Size of the axes

Note that only the stroke color is used in all of the supported drawing functions.

Geometric shapes

void codac2::Figure3D::draw_triangle(const Vector &c, const Matrix &A, const Vector &p1, const Vector &p2, const Vector &p3, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a triangle.

Parameters:
  • c – translation

  • A – scaling

  • p1 – first point

  • p2 – second point

  • p3 – third point

  • s – style

void codac2::Figure3D::draw_triangle(const Vector &p1, const Vector &p2, const Vector &p3, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a triangle, shorter version.

Parameters:
  • p1 – first point

  • p2 – second point

  • p3 – third point

  • s – style

The draw_polygon can be used to draw a star-shaped polygon when the vectors are coplanar, and more generally a sequence of adjacent triangles sharing a same vertex.

void codac2::Figure3D::draw_polygon(const Vector &c, const Matrix &A, const std::vector<Vector> &l, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a `star-shaped’ polygon as a sequence of adjacent triangles (l[0],l[k],l[k+1]) with k>=1.

Parameters:
  • c – translation

  • A – scaling

  • l – points

  • s – style

void codac2::Figure3D::draw_box(const IntervalVector &x, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a box on the figure.

Parameters:
  • x – Box to draw

  • s – Style of the box (edge color)

void codac2::Figure3D::draw_parallelogram(const Vector &c, const Matrix &A, const Vector &p, const Vector &v1, const Vector &v2, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a parallelogram c + A (p + [-1,1]*v1 + [-1,1]*v2)

Parameters:
  • c – translation

  • A – scaling

  • p – base point

  • v1 – vector

  • v2 – vector

  • s – style

void codac2::Figure3D::draw_parallelepiped(const Vector &z, const Matrix &A, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a parallelepiped z+A*[-1,1]^3 on the figure.

Parameters:
  • z – Coordinates of the center of the parallelepiped

  • A – Matrix of the parallelepiped

  • s – Style of the parallelepiped (edge color)

void codac2::Figure3D::draw_zonotope(const Vector &z, const std::vector<Vector> &A, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a zonotope z+sum_i [-1,1] A_i on the figure.

Parameters:
  • z – Coordinates of the center of the zonotope

  • A – list of vectors

  • s – Style of the zonotope (edge color)

void codac2::Figure3D::draw_arrow(const Vector &c, const Matrix &A, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws an arrow (box c + A * ([0,1],[-0.01,0.01],[-0.01,0.01]) and a tip at the end)

Parameters:
  • c – start

  • A – orientation (first column)

  • s – Style (color)

void codac2::Figure3D::draw_surface(const Vector &c, const Matrix &A, const Interval &Ip1, double dp1, const Interval &Ip2, double dp2, std::function<Vector(double, double)> f, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a parametric surface.

Parameters:
  • c – translation

  • A – scaling

  • Ip1 – bounds of p1

  • dp1 – incrementation for p1

  • Ip2 – bounds of p2

  • dp2 – incrementation for p2

  • f – function computing the values

  • s – Style (color)

void codac2::Figure3D::draw_sphere(const Vector &c, const Matrix &A, const StyleProperties &s = {Color::dark_gray(0.5)})

Draws a sphere (ellipsoid)

Parameters:
  • c – translation

  • A – scaling

  • s – Style (color)

Paving

void codac2::Figure3D::draw_paving(const PavingOut &p, const StyleProperties &bound_s = {Color::yellow(0.5)})

Draws a paving on the figure (Only the boundary is drawn).

Parameters:
  • p – PavingOut to draw (result of a paving with contractors).

  • bound_s – Style of the boundary of the paving

void codac2::Figure3D::draw_paving(const PavingInOut &p, const StyleProperties &bound_s = {Color::yellow(0.3), "paving_bound"}, const StyleProperties &in_s = {Color::green(0.5), "paving_in"})

Draws a paving on the figure (Only the boundary and the inside is drawn).

Parameters:
  • p – PavingInOut to draw (result of a paving with separators).

  • bound_s – Style of the boundary of the paving

  • in_s – Style of the inside of the paving

template<typename P>
inline void codac2::Figure3D::draw_subpaving(const Subpaving<P> &p, const StyleProperties &s = StyleProperties())

Draws a subpaving on the figure.

Parameters:
  • p – Subpaving to draw

  • s – Style of the subpaving

Vehicles

void codac2::Figure3D::draw_car(const Vector &c, const Matrix &A, const StyleProperties &s = {Color::yellow(0.5)})

Draws a car, with blue windscreen.

Parameters:
  • c – `center’ (low) of the car

  • A – orientation

  • s – Style (color)

void codac2::Figure3D::draw_plane(const Vector &c, const Matrix &A, bool yaw_is_up = true, const StyleProperties &s = {Color::dark_gray(0.8)})

Draws a (paper) plane.

Parameters:
  • c – `center’ (low) of the car

  • A – orientation

  • yaw_is_up – yaw axis is up (default true)

  • s – Style (color)