Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: char ascii c++ 
Cpp :: docker.io : Depends: containerd (= 1.2.6-0ubuntu1~) E: Unable to correct problems, you have held broken packages 
Cpp :: double to int c++ 
Cpp :: arduino funktion 
Cpp :: c++ tokenize string 
Cpp :: ubuntu dotnet core install 
Cpp :: c++ reference 
Cpp :: ViewController import 
Cpp :: remove decimal c++ 
Cpp :: OpenGL C++ Version 
Cpp :: size of array 
Cpp :: c++ Sum of all the factors of a number 
Cpp :: how to find the sum of a vector c++ 
Cpp :: 2d array c++ 
Cpp :: c++ output 
Cpp :: sort vector struct c++ 
Cpp :: c++ string to int 
Cpp :: How to write into files in C++ 
Cpp :: c++ if else 
Cpp :: c++ get line 
Cpp :: c++ get the line which call a function 
Cpp :: c++ 14 for sublime windoes build system 
Cpp :: iterate over map c++ 
Cpp :: descending order c++ 
Cpp :: how to use custom array in c++ 
Cpp :: insert in vector 
Cpp :: print hello world c++ 
Cpp :: set size in c++ 
Cpp :: grep xargs sed 
Cpp :: exception handling class c++ 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =