Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double intersect(Ray r)
- {
- Vector v = r.origin.sub(pos);
- double b = 2 * r.direction.dot(v);
- double c = v.dot(v) - radius * radius;
- double d = b * b - 4 * c;
- if(d > 0)
- {
- double x1 = (-b - Math.sqrt(d)) / 2;
- double x2 = (-b + Math.sqrt(d)) / 2;
- if (x1 >= 0 && x2 >= 0)
- return x1;
- if (x1 < 0 && x2 >= 0)
- return x2;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement