We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 85025c2 commit cec6dfaCopy full SHA for cec6dfa
src/InOneWeekend/main.cc
@@ -6,15 +6,15 @@
6
7
double hit_sphere(const point3& center, double radius, const ray& r) {
8
vec3 oc = center - r.origin();
9
- auto a = dot(r.direction(), r.direction());
10
- auto b = -2.0 * dot(r.direction(), oc);
11
- auto c = dot(oc, oc) - radius*radius;
12
- auto discriminant = b*b - 4*a*c;
+ auto a = r.direction().length_squared();
+ auto h = dot(r.direction(), oc);
+ auto c = oc.length_squared() - radius*radius;
+ auto discriminant = h*h - a*c;
13
14
if (discriminant < 0) {
15
return -1.0;
16
} else {
17
- return (-b - sqrt(discriminant) ) / (2.0*a);
+ return (h - sqrt(discriminant)) / a;
18
}
19
20
0 commit comments