diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-08-15 00:18:09 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-08-15 00:18:09 -0600 |
commit | 8fed0cea862554f1d8316c2244e6d94f691abad6 (patch) | |
tree | b09d21ac41955403b42fc7ddcb3dac46189e2526 /libdimension/geometry.c | |
parent | 002f77325f0fb984c7f274350af83de010184195 (diff) | |
download | dimension-8fed0cea862554f1d8316c2244e6d94f691abad6.tar.xz |
Make dmnsn_vector_axis_angle() handle edge cases.
Diffstat (limited to 'libdimension/geometry.c')
-rw-r--r-- | libdimension/geometry.c | 6 |
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) { |