Primitives¶
Primal includes the following primitives:
Point
Segment, Ray, Vector
Plane, Triangle, Polygon
Quadrilateral
Sphere
Tetrahedron
Hexahedron
BoundingBox, OrientedBoundingBox
Polyhedron
Note
Primitives in Axom use a right-handed coordinate system.
Primal also provides the NumericArray class, which implements arithmetic operations on numerical tuples and supports Primal’s Point and Vector classes. Classes in Primal are templated on coordinate type (double, float, etc.) and dimension. The primitives do not inherit from a common base class. This was a design choice in favor of simplicity and performance. Geometric primitives can be tested for equality and can be printed to strings.
Primal also includes functions to merge a pair of BoundingBox or a pair of OrientedBoundingBox objects and to create new OrientedBoundingBox objects from a list of points.
The following includes header files for primal’s primitives
as well as some using
directives and typedef
statements that will be used in
the examples. Header files for operations will be shown next to code examples.
Although the examples #include
separate class header files, it is easier and
less error-prone to write #include axom/primal.hpp
.
// Axom primitives
#include "axom/primal/geometry/BoundingBox.hpp"
#include "axom/primal/geometry/OrientedBoundingBox.hpp"
#include "axom/primal/geometry/Point.hpp"
#include "axom/primal/geometry/Polygon.hpp"
#include "axom/primal/geometry/Ray.hpp"
#include "axom/primal/geometry/Segment.hpp"
#include "axom/primal/geometry/Triangle.hpp"
#include "axom/primal/geometry/Vector.hpp"
// "using" directives to simplify code
namespace primal = axom::primal;
// almost all our examples are in 3D
constexpr int in3D = 3;
// primitives represented by doubles in 3D
using PointType = primal::Point<double, in3D>;
using TriangleType = primal::Triangle<double, in3D>;
using BoundingBoxType = primal::BoundingBox<double, in3D>;
using OrientedBoundingBoxType = primal::OrientedBoundingBox<double, in3D>;
using PolygonType = primal::Polygon<double, in3D>;
using RayType = primal::Ray<double, in3D>;
using SegmentType = primal::Segment<double, in3D>;
using VectorType = primal::Vector<double, in3D>;