Hermes
Geometry

Here you will find all the basic geometric objects that are commonly used in computer applications, mainly Computer Graphics related. Most geometry classes inherit from a base class called hermes::MathElement, this way you can easily access information like:

// suppose elem is a from MathElement
// you can retrieve how many components
// (a 3d vector has 3, a 4x4 matrix has 16)
elem.componentCount();
// you can get its underlying type
elem.numeric_data;
// And for debugging, you can also get its memory layout
elem.memoryDumpLayout();

Hermes defines its basic geometric entities - vectors, matrices, etc - based on their geometric definitions and linear algebra. Their arithmetic operators are defined in the same manner. For example, if you sum a vector to a point, you will get a point. If you subtract a point from another point, you will get a vector. Other operations are defined accordingly.

Vectors

The most basic, and commonly used geometric object is the vector. In hermes, you will find vector representations in hermes::Vector* classes. These classes are implementations for the [2,3,4]-dimensional versions of vectors, which you can choose by changing the number in the name. They are all template classes taking the underlying floating-point type as parameter (ex: f32 or f64).

Here are some convenient typedefs:

hermes::vec2; // hermes::Vector2<real_t>
hermes::vec3; // hermes::Vector3<real_t>
hermes::vec4; // hermes::Vector4<real_t>
hermes::vec3d; // hermes::Vector3<f64>
hermes::vec3f; // hermes::Vector3<f32>
hermes::vec2f; // hermes::Vector2<f32>
hermes::vec2i; // hermes::Vector2<Interval<real_t>>
hermes::vec3i; // hermes::Vector3<Interval<real_t>>
Geometric 4-dimensional point (x, y, z, w)
Definition: vector.h:425
Geometric vector classes.

Borrowing some definitions from linear algebra, the hermes::Vector implements a vector space. Consider two scalars \(\alpha\) and \(\beta\), and the vectors \(u\), \(v\), and \(w\), then the following holds:

  • Commutativity

    \(u+v=v+u\)

  • Associativity

    \((u + v) + w = u + (v + w)\) and \((\alpha\beta)v = \alpha(\beta v)\)

  • Null element

    \(v + 0 = 0 + v = v\)

  • Additive Inverse

    \(-v + v = 0\)

  • Distributivity

    \((\alpha + \beta)v = \alpha v + \beta v\) and \(\alpha(u + v) = \alpha u + \alpha v\)

  • Scalar Identity

    \(1 \cdot v = v\)

The following code snippet lists some common methods provided by the vector class:

// suppose you have two vectors (the same should apply fo
// you can access their components in both ways
v.x; // or v[0]
v.y; // or v[1]
v.z; // or v[2]
// you can check its magnitude
u.length();
// you can normalize
// swizzling is also supported
v.xy(); // and any other combination
HERMES_DEVICE_CALLABLE Vector2< T > xy(int i=0, int j=1) const
Gets 2-dimensional swizzle form.
Definition: vector.h:292
T x
0-th component
Definition: vector.h:415
HERMES_DEVICE_CALLABLE T length(typename std::enable_if_t<!std::is_same_v< C, Interval< f32 >> &&!std::is_same_v< C, Interval< f64 >>> *=nullptr) const
Computes vector magnitude.
Definition: vector.h:308
HERMES_DEVICE_CALLABLE void normalize()
Normalizes this vector.
Definition: vector.h:374
T z
2-th component
Definition: vector.h:417
T y
1-th component
Definition: vector.h:416

Consider again a scalars \(\alpha\), and the vectors \(u\), \(v\), and \(w\). The following vector operations are also available (the equations bellow follow index notation):

  • dot product:

    \[u \cdot v = u_i v_i\]

    HERMES_DEVICE_CALLABLE T dot(const Normal3< T > &n, const Vector3< T > &v)
    Computes dot product with vector.
    Definition: normal.h:237
  • cross product:

    \[u \times b = \epsilon_{ijk}u_iv_j\hat{e}_k\]

    HERMES_DEVICE_CALLABLE T cross(const Vector2< T > &a, const Vector2< T > &b)
    Computes the cross product between two vectors.
    Definition: vector.h:550
  • triple product:

    \[u \cdot (v \times w)\]

    HERMES_DEVICE_CALLABLE T triple(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
    Computes the triple product between 3 vectors.
    Definition: vector.h:570
  • normalization:

    \[||u|| = \sqrt{u \cdot u}\]

    HERMES_DEVICE_CALLABLE Normal3< T > normalize(const Normal3< T > &normal)
    Computes normalized copy.
    Definition: normal.h:201
  • projection:

    \[\frac{u \cdot v}{||v||^2} v\]

    HERMES_DEVICE_CALLABLE Vector2< T > project(const Vector2< T > &v, const Normal2< T > &n)
    projects v on the surface with normal n
    Definition: normal.h:193
  • rejection:

    \[u - \frac{u \cdot v}{||v||^2} v\]

    HERMES_DEVICE_CALLABLE Vector3< T > reject(const Vector3< T > &a, const Vector3< T > &b)
    Rejects one vector on another.
    Definition: vector.h:627

The following subsections describe special types of vectors.

Points

Points, also interpreted as position vectors, follow the same name structure of vectors, and you will find their dimensional representations in hermes::Point* classes. These classes are implementations for the [2,3,4]-dimensional versions of points, which you can choose by changing the number in the name. They are also all template classes taking the underlying floating-point type as parameter (ex: f32 or f64).

Here are some convenient typedefs:

hermes::point2; // hermes::Point2<real_t>
hermes::point2f; // hermes::Point2<f32>
hermes::point2d; // hermes::Point2<f64>
hermes::point3; // hermes::Point3<real_t>
hermes::point3f; // hermes::Point3<f32>
hermes::point3d; // hermes::Point3<f64>
hermes::point2i; // hermes::Point2<Interval<real_t>>
hermes::point3i; // hermes::Point3<Interval<real_t>>
Geometric point classes.

The arithmetic of points is more restrict. The arithmetic operators will let you only translate or scale a point:

// translation
p += v;
// scale
p *= s;
float real_t
default floating point type
Definition: defs.h:75

A subtraction of two points p and q will give you a distance vector d:

hermes::vec3 d = p - q;

The distance between two points can be computed as well:

// the squared distance is also available
HERMES_DEVICE_CALLABLE real_t distance2(const Point2< T > &a, const Point2< T > &b)
Computes the squared Euclidean distance between two points.
Definition: point.h:304
HERMES_DEVICE_CALLABLE real_t distance(const Point2< T > &a, const Point2< T > &b)
Computes the Euclidean distance between two points.
Definition: point.h:295

Normals

Normal vectors represent geometric normals, and you will find their dimensional representations in hermes::Normal* classes. These classes are implementations for the [2,3]-dimensional versions of normals, which you can choose by changing the number in the name. They are also all template classes taking the underlying floating-point type as parameter (ex: f32 or f64).

Here are some convenient typedefs:

hermes::normal2; // hermes::Normal2<real_t>
hermes::normal2f; // hermes::Normal2<f32>
hermes::normal2d; // hermes::Normal2<f64>
hermes::normal3; // hermes::Normal3<real_t>
hermes::normal3f; // hermes::Normal3<f32>
hermes::normal3d; // hermes::Normal3<f64>
Geometric normal classes.

Normals are even more restrict regarding their arithmetic operators. Given a vector v and normal n, the main functions are:

  • dot product with vector:

    \[v \cdot n = v_i n_i\]

  • reflection:

    \[v - 2 (v \cdot n)n\]

    HERMES_DEVICE_CALLABLE Vector2< T > reflect(const Vector2< T > &a, const Normal2< T > &n)
    reflects a on n
    Definition: normal.h:185
  • projection on surface:

    \[v - (v \cdot n)n\]

  • face vector forward normal direction:

    \[ \begin{cases} -v, && v \cdot n < 0 \\ v, && v \cdot n >= 0 \\ \end{cases} \]

Transforms

Matrices