summaryrefslogtreecommitdiffstats
path: root/libdimension/geometry.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-11-27 01:43:36 -0500
committerTavian Barnes <tavianator@gmail.com>2009-11-27 11:49:54 -0500
commitda0b16d79c05a83d14195eaf509352effbe5a215 (patch)
treef79ede58876098464dac39a4483f8d2c4ad269d0 /libdimension/geometry.c
parentb437554ae933f99a59054e6589177ca8380a3a97 (diff)
downloaddimension-da0b16d79c05a83d14195eaf509352effbe5a215.tar.xz
Fake camera semantics until I figure out the real ones.
Diffstat (limited to 'libdimension/geometry.c')
-rw-r--r--libdimension/geometry.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/libdimension/geometry.c b/libdimension/geometry.c
index cbcc2c1..4aa46ec 100644
--- a/libdimension/geometry.c
+++ b/libdimension/geometry.c
@@ -80,6 +80,23 @@ dmnsn_rotation_matrix(dmnsn_vector theta)
);
}
+/* Find the angle between two vectors with respect to an axis */
+double
+dmnsn_vector_axis_angle(dmnsn_vector v1, dmnsn_vector v2, dmnsn_vector axis)
+{
+ dmnsn_vector d = dmnsn_vector_sub(v1, v2);
+ dmnsn_vector proj = dmnsn_vector_add(dmnsn_vector_proj(d, axis), v2);
+
+ double c = dmnsn_vector_dot(dmnsn_vector_normalize(v1),
+ dmnsn_vector_normalize(proj));
+ double angle = acos(c);
+
+ if (dmnsn_vector_dot(dmnsn_vector_cross(v1, proj), axis) > 0)
+ return angle;
+ else
+ return -angle;
+}
+
/* Matrix inversion helper functions */
typedef struct { double n[2][2]; } dmnsn_matrix2;