summaryrefslogtreecommitdiffstats
path: root/libdimension/geometry.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-08-15 00:18:09 -0600
committerTavian Barnes <tavianator@gmail.com>2010-08-15 00:18:09 -0600
commit8fed0cea862554f1d8316c2244e6d94f691abad6 (patch)
treeb09d21ac41955403b42fc7ddcb3dac46189e2526 /libdimension/geometry.c
parent002f77325f0fb984c7f274350af83de010184195 (diff)
downloaddimension-8fed0cea862554f1d8316c2244e6d94f691abad6.tar.xz
Make dmnsn_vector_axis_angle() handle edge cases.
Diffstat (limited to 'libdimension/geometry.c')
-rw-r--r--libdimension/geometry.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libdimension/geometry.c b/libdimension/geometry.c
index 26ca628..6b1019b 100644
--- a/libdimension/geometry.c
+++ b/libdimension/geometry.c
@@ -87,8 +87,12 @@ 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 projn = dmnsn_vector_norm(proj);
+ if (!projn)
+ return 0.0;
+
double c = dmnsn_vector_dot(dmnsn_vector_normalize(v1),
- dmnsn_vector_normalize(proj));
+ dmnsn_vector_div(proj, projn));
double angle = acos(c);
if (dmnsn_vector_dot(dmnsn_vector_cross(v1, proj), axis) > 0) {