diff options
author | David Thompson <dthompson2@worcester.edu> | 2019-10-11 18:43:18 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2019-10-11 18:43:18 -0400 |
commit | 5ba55d8a11ceea31dad6ec9304b657bb5e942e65 (patch) | |
tree | f98024b8f45871f02f4c0a901ac355ed2fe3f645 | |
parent | 0f9508b40f5a187fc23f177e3448ac7b668c6f52 (diff) |
math: vector: Add vec3 cross product procedures.
-rw-r--r-- | chickadee/math/vector.scm | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/chickadee/math/vector.scm b/chickadee/math/vector.scm index 41c7659..31aff07 100644 --- a/chickadee/math/vector.scm +++ b/chickadee/math/vector.scm @@ -53,6 +53,8 @@ vec3-z vec3-magnitude vec3-dot-product + vec3-cross + vec3-cross! vec3-normalize set-vec3-x! set-vec3-y! @@ -229,6 +231,20 @@ polar coordinate (R, THETA)." (* (vec3-y v1) (vec3-y v2)) (* (vec3-z v1) (vec3-z v2)))) +(define-inlinable (vec3-cross! dest v1 v2) + (set-vec3! dest + (- (* (vec3-y v1) (vec3-z v2)) + (* (vec3-z v1) (vec3-y v2))) + (- (* (vec3-z v1) (vec3-x v2)) + (* (vec3-x v1) (vec3-z v2))) + (- (* (vec3-x v1) (vec3-y v2)) + (* (vec3-y v1) (vec3-x v2))))) + +(define-inlinable (vec3-cross v1 v2) + (let ((vout (vec3 0.0 0.0 0.0))) + (vec3-cross! vout v1 v2) + vout)) + (define-inlinable (vec2-normalize! v) "Normalize the vec2 V in-place." (unless (and (zero? (vec2-x v)) (zero? (vec2-y v))) |