Update README and add norm calculations to vector
This commit is contained in:
parent
db60954ce4
commit
c9023f2f8b
3 changed files with 213 additions and 124 deletions
|
@ -1,6 +1,7 @@
|
|||
#ifndef VEC3_H
|
||||
#define VEC3_H
|
||||
|
||||
#include <cmath>
|
||||
template <typename T> struct Vec3 {
|
||||
T x;
|
||||
T y;
|
||||
|
@ -20,14 +21,18 @@ template <typename T> struct Vec3 {
|
|||
z *= scalar;
|
||||
};
|
||||
|
||||
inline T dot(Vec3<T> other) {
|
||||
inline T dot(Vec3<T> other) const {
|
||||
return x * other.x + y * other.y + z * other.z;
|
||||
}
|
||||
|
||||
inline Vec3<T> cross(Vec3<T> other) {
|
||||
inline Vec3<T> cross(Vec3<T> other) const {
|
||||
return {y * other.z - z * other.y, z * other.x - x * other.z,
|
||||
x * other.y - y * other.x};
|
||||
}
|
||||
|
||||
inline double squared_norm2() const { return x * x + y * y + z * z; }
|
||||
|
||||
inline double norm2() const { return std::sqrt(squared_norm2()); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue