Hermes
|
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:
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.
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:
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:
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\]
cross product:
\[u \times b = \epsilon_{ijk}u_iv_j\hat{e}_k\]
triple product:
\[u \cdot (v \times w)\]
normalization:
\[||u|| = \sqrt{u \cdot u}\]
projection:
\[\frac{u \cdot v}{||v||^2} v\]
rejection:
\[u - \frac{u \cdot v}{||v||^2} v\]
The following subsections describe special types of vectors.
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:
The arithmetic of points is more restrict. The arithmetic operators will let you only translate or scale a point:
A subtraction of two points p
and q
will give you a distance vector d
:
The distance between two points can be computed as well:
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:
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\]
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} \]