Horje
ray sphere intersection equation Code Example
ray sphere intersection equation
bool hit_sphere(const vec3& center, float radius, const ray& r){
    vec3 oc = r.origin() - center;
    float a = dot(r.direction(), r.direction());
    float b = 2.0 * dot(oc, r.direction());
    float c = dot(oc,oc) - radius*radius;
    float discriminant = b*b - 4*a*c;
    return (discriminant>0);
}




Cpp

Related
hello world in c++ Code Example hello world in c++ Code Example
draw rectangle opencv c++ Code Example draw rectangle opencv c++ Code Example
Header for INT_MIN Code Example Header for INT_MIN Code Example
how to compare two char* in c++ Code Example how to compare two char* in c++ Code Example
c++ vector extend vector Code Example c++ vector extend vector Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12