diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-05-25 23:31:52 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-05-25 23:31:52 -0600 |
commit | 7ca4d094639ffc302cdc7da5cdc291cc32005ecb (patch) | |
tree | 0ab2def626c6faa344d693c4e1ac63f0927989ef | |
parent | 115f58fc6f8abdcd4aaf870a67c62d5ada9d87f2 (diff) | |
download | dimension-7ca4d094639ffc302cdc7da5cdc291cc32005ecb.tar.xz |
Clean up sphere intersection code a bit.
-rw-r--r-- | bench/libdimension/list.c | 2 | ||||
-rw-r--r-- | libdimension/sphere.c | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/bench/libdimension/list.c b/bench/libdimension/list.c index 9af3279..16eb501 100644 --- a/bench/libdimension/list.c +++ b/bench/libdimension/list.c @@ -103,7 +103,7 @@ main() sandglass_bench_noprecache(&sandglass, split = dmnsn_list_split(list)); printf("dmnsn_list_split(): %ld\n", sandglass.grains); - /* dmnsn_list_sort() */ + /* dmnsn_list_sort() */ sandglass_bench(&sandglass, dmnsn_list_sort(list, &dmnsn_comparator)); printf("dmnsn_list_sort(): %ld\n", sandglass.grains); diff --git a/libdimension/sphere.c b/libdimension/sphere.c index 0477c24..a3ecf2d 100644 --- a/libdimension/sphere.c +++ b/libdimension/sphere.c @@ -54,14 +54,14 @@ dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line, /* Solve (x0 + nx*t)^2 + (y0 + ny*t)^2 + (z0 + nz*t)^2 == 1 */ double a, b, c, t; - a = l.n.x*l.n.x + l.n.y*l.n.y + l.n.z*l.n.z; - b = 2.0*(l.n.x*l.x0.x + l.n.y*l.x0.y + l.n.z*l.x0.z); - c = l.x0.x*l.x0.x + l.x0.y*l.x0.y + l.x0.z*l.x0.z - 1.0; + a = dmnsn_vector_dot(l.n, l.n); + b = 2.0*dmnsn_vector_dot(l.n, l.x0); + c = dmnsn_vector_dot(l.x0, l.x0) - 1.0; - if (b*b - 4.0*a*c >= 0) { - t = (-b - sqrt(b*b - 4.0*a*c))/(2*a); + if (b*b - 4.0*a*c >= 0.0) { + t = (-b - sqrt(b*b - 4.0*a*c))/(2.0*a); if (t < 0.0) { - t = (-b + sqrt(b*b - 4.0*a*c))/(2*a); + t = (-b + sqrt(b*b - 4.0*a*c))/(2.0*a); } if (t >= 0.0) { |