Question: double Sphere::Intersect ( Vector source, Vector d ) { / / Compute the intersection of a ray with a TRANSFORMED sphere / / You can
double Sphere::IntersectVector source, Vector d
Compute the intersection of a ray with a TRANSFORMED sphere
You can assume that for a transformed object the vectors 'scaling' and 'translation" are defined.
where scalingxscaling.yscaling.z are the scale factors in xy and z direction
and translationxtranslation.ytranslation.z is the translation vector
STEP : Transform the ray, compute the transformed ray start point and direction
Vector s source translationScale scaling.x scaling.y scaling.z;
Vector dir dScale scaling.x scaling.y scaling.z;
STEP : Compute intersection of the transformed ray with the sphere
A B and C are the parameters of the quadratic equation for finding the
ray intersection parameter t see "Ray Tracing" lecture notes
float A dir.Dotdir;
float B dir.Dots center;
float C s centerDots center radius radius;
float t ; the parameter t for the closest intersection point or ray with the sphere. If no intersection t
BEGIN SOLUTION RAYSPHERE INTERSECTION
Delete the line t; and insert your solution instead
NOTE : If there is no rayshere intersection set t
NOTE : Use C notation so that the code runs in Coderunner
NOTE : You might want to use the sqrt function
float discriminant B B A C;
if discriminant
t ;
else
float tB sqrtdiscriminant A;
float tB sqrtdiscriminant A;
if t && t
t ;
else if t && t
t fmint t;
else
t fmaxt t;
END SOLUTION RAYSPHERE INTERSECTION
return t;
Vector Sphere::NormalVector p
STEP : Calculate the correct normal for the transformed sphere
replace the existing code below and use the values 'scaling' and 'translation" to compute the normal of the transformed sphere
Vector n p centerScale scaling.x scaling.y scaling.zNormalize;
return n;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
