CSCE 4813 – Programming Project 5

Due Date – April 16, 2018 at 11:59pm

1. Problem Statement:

The goal of this programming project is to implement some of the geometric tools needed to create a simple ray tracing program. You will be given partial implementations of four classes (Point3D, Vector3D, Ray3D, Sphere3D). As their names suggest, the Point3D class stores 3D points (px,py,pz). The Vector3D class stores 3D vectors (vx,vy,vz). The Ray3D class defines a 3D ray (line equation) starting at point p, and going in direction d. Finally, the Sphere3D class defines a 3D sphere centered at location (cx,cy,cz) with radius r.

You will be given C++ class definitions of these four classes, and implementations of theircorresponding “set” and “print” methods. Your first task is to complete the implementations of the following methods:

  • Point3D::distance – This method should calculate the Euclidian distance between two 3D points.
  • Vector3D::normalize – This method should calculate the length of the vector V=(vx,vy,vz) and normalize the vector to unit length.
  • Vector3D::dot – This method should calculate the dot product (scalar product) of two vectors. When the vectors are unit length, the dot product is equal to the cosine of the angle between the vectors.
  • Ray3D::get_sample – A ray is defined as the line segment that starts at location P=(px,py,pz) and goes in direction V=(vx,vy,vz), where the direction vector V has been normalized to unit length. This method “samples the ray” by calculating the coordinates of a point at location P(t) = (px,py,pz) + t * (vx,vy,vz).
  • Sphere3D::get_intersection – In general, three things can happen when a line is intersected with a sphere: (1) it can intersect in two places, (2) it can intersect in one place, or (3) it can miss the sphere (see the wikipedia sphere line intersection page for details). This method calculates the closest intersection point of a ray with a sphere (the point with smallest positivedistance to the starting point of the ray). The method also calculates the surface normal of the sphere at this point (a vector from the center of the sphere towards this point). Finally, the method should return a Boolean value true if an intersection point is found, and false if the ray does not intersect the sphere.

The current main program tests the “set” and “print” methods for the four classes. Your second task is to extend this main program to test the three methods above.

  • To test the Point3D::distance, Vector3D::normalizeand Vector3D::dot methods, you should create a collection of points and vectors where you know in advance what the output from these methods should be, and call the methods to verify these results.
  • To test the Ray3D::get_sample method, you should create a ray, and calculate and print N samples on the ray at evenly spaced values of t between [0..1]. What you should see is a sequence of coordinates that start at the point (px,py,pz) and end at (px,py,pz) + (vx,vy,vz).
  • To test the Sphere3D::get_intersection method, you should create a sphere and several rays where you know in advance what the intersection points are. Print the point and surface normal to verify they correct values are returned by your method. Then try several rays that you know do not intersect the sphere.

2. Design:

The formulas for calculating distance, normalizing a vector, computing dot products and getting point samples from a ray are relatively simple. You only have to translate these formulas into C++.

On the other hand, the formula for calculating the intersection of a line with a sphere is pretty tricky and involves solving a quadratic equation. You might want to start by considering the solution in 2D before you go on to 3D. You should look at Wikipedia or other online sources for mathematical details. Your main design task is working out how to translate these formulas into C++ code.

3. Implementation:

This program will not be using OpenGL. Instead you will be starting with “classes.cpp” and your task is to complete the implementation of missing methods and test these methods in the main program. This is a “tool building” project, so we will not be creating any output images. In our next project, we will be using these classes and your Phong shading class to create our ray tracing application.

Remember to use incremental development and good programming style when creating your program. Choose good names for variables and constants, use proper indenting for loops and conditionals, and include clear comments in your code. Also, be sure to save backup copies of your program somewhere safe. Otherwise, you may end up retyping your whole program if something goes wrong.

4. Testing:

Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. Try your program with several input values, and save screen shots of your output in jpeg images for inclusion in your project report.

5. Documentation:

When you have completed your C++ program, write a short report using the project report template describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems? Save this report to be submitted electronically.

6. Project Submission:

In this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic plagiarism analysis of all programs that are submitted.

When you have completed the tasks above go to Blackboard to upload your documentation (a single docx or pdf file), and all of your C++ program files. Do NOT upload an executable version of your program.

The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:

  • 10% off if less than 1 day late,
  • 20% off if less than 2 days late,
  • 30% off if less than 3 days late,
  • no credit if more than 3 days late.

You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended.

7. Academic Honesty Statement:

Students are expected to submit their own work on all programming projects, unless group projects have been explicitly assigned. Students are NOT allowed to distribute code to each other, or copy code from another individual or website. Students ARE allowed to use any materials on the class website, or in the textbook, or ask the instructor and/or GTAs for assistance.

This course will be using highly effective program comparison software to calculate the similarity of all programs to each other, and to homework assignments from previous semesters. Please do not be tempted to plagiarize from another student.

Violations of the policies above will be reported to the Provost's office and may result in a ZERO on the programming project, an F in the class, or suspension from the university, depending on the severity of the violation and any history of prior violations.