summaryrefslogtreecommitdiff
path: root/vec.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-20 22:12:17 +0800
committerKeuin <[email protected]>2022-04-20 22:12:17 +0800
commited6a7d7e31e3fa3b23078d55e6a88917ee68c66e (patch)
treea71d7db362458e85f49f2cb9c71f9ec6ff6b639c /vec.h
parent699287623d51be688f2af0a01fedcf90d035da13 (diff)
Add vec3::parallel and its test.
Diffstat (limited to 'vec.h')
-rw-r--r--vec.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/vec.h b/vec.h
index 84cbaa3..11b9bd3 100644
--- a/vec.h
+++ b/vec.h
@@ -109,6 +109,15 @@ struct vec3 {
return std::isfinite(x) && std::isfinite(y) && std::isfinite(z);
}
+ // Determine if this vector is parallel with another one.
+ bool parallel(const vec3 &other) const {
+ const auto dt = dot(other);
+ const auto dot2 = dt * dt;
+ const auto sqlp = mod2() * other.mod2(); // squared length product
+ const auto d = dot2 - sqlp;
+ return d > -1e-6 && d < 1e-6;
+ }
+
// Get the reflected vector. Current vector is the normal vector (length should be 1), v is the incoming vector.
vec3 reflect(const vec3 &v) const {
assert(fabs(mod2() - 1.0) < 1e-8);