@@ -10,28 +10,28 @@ As we discussed in class, data points in time can be interpolated by constructin
Recall that a cubic polynomial is a function of the form
<imgsrc=task1_media/0000.pngheight="30">
<imgsrc="task1_media/0000.png"height="30">
where <imgsrc=task1_media/0001.pngheight="20">, and <imgsrc=task1_media/0002.pngheight="20"> are fixed coefficients. However, there are many different ways of specifying a cubic polynomial. In particular, rather than specifying the coefficients directly, we can specify the endpoints and tangents we wish to interpolate. This construction is called the "Hermite form" of the polynomial. In particular, the Hermite form is given by
where <imgsrc="task1_media/0001.png"height="20">, and <imgsrc="task1_media/0002.png"height="20"> are fixed coefficients. However, there are many different ways of specifying a cubic polynomial. In particular, rather than specifying the coefficients directly, we can specify the endpoints and tangents we wish to interpolate. This construction is called the "Hermite form" of the polynomial. In particular, the Hermite form is given by
<imgsrc=task1_media/0003.pngheight="30">
<imgsrc="task1_media/0003.png height"="30">
where <imgsrc=task1_media/0004.pngheight="20"> are the endpoint positions, <imgsrc=task1_media/0005.pngheight="20"> are the endpoint tangents, and <imgsrc=task1_media/0006.pngheight="20"> are the Hermite bases
where <imgsrc="task1_media/0004.png"height="20"> are the endpoint positions, <imgsrc="task1_media/0005.png"height="20"> are the endpoint tangents, and <imgsrc="task1_media/0006.png"height="20"> are the Hermite bases
<imgsrc=task1_media/0007.pngheight="30"><br/>
<imgsrc="task1_media/0007.png"height="30"><br/>
<imgsrc=task1_media/0008.pngheight="30"><br/>
<imgsrc="task1_media/0008.png"height="30"><br/>
<imgsrc=task1_media/0009.pngheight="30"><br/>
<imgsrc="task1_media/0009.png"height="30"><br/>
<imgsrc=task1_media/0010.pngheight="30"><br/>
<imgsrc="task1_media/0010.png"height="30"><br/>
Your first task is to implement the method `Spline::cubic_unit_spline()`, which evaluates a spline defined over the time interval <imgsrc=task1_media/0011.pngheight="20"> given a pair of endpoints and tangents at endpoints. Optionally, the user can also specify that they want one of the time derivatives of the spline (1st or 2nd derivative), which will be needed for our dynamics calculations.
Your first task is to implement the method `Spline::cubic_unit_spline()`, which evaluates a spline defined over the time interval <imgsrc="task1_media/0011.png"height="20"> given a pair of endpoints and tangents at endpoints. Optionally, the user can also specify that they want one of the time derivatives of the spline (1st or 2nd derivative), which will be needed for our dynamics calculations.
Your basic strategy for implementing this routine should be:
* Evaluate the time, its square, and its cube (for readability, you may want to make a local copy).
* Using these values, as well as the position and tangent values, compute the four basis functions <imgsrc=task1_media/0012.pngheight="20"><imgsrc=task1_media/0013.pngheight="20"> of a cubic polynomial in Hermite form. Or, if the user has requested the nth derivative, evaluate the nth derivative of each of the bases.
* Using these values, as well as the position and tangent values, compute the four basis functions <imgsrc="task1_media/0012.png"height="20"><imgsrc="task1_media/0013.png"height="20"> of a cubic polynomial in Hermite form. Or, if the user has requested the nth derivative, evaluate the nth derivative of each of the bases.
* Finally, combine the endpoint and tangent data using the evaluated bases, and return the result.
Notice that this function is templated on a type T. In C++, a templated class can operate on data of a variable type. In the case of a spline, for instance, we want to be able to interpolate all sorts of data: angles, vectors, colors, etc. So it wouldn't make sense to rewrite our spline class once for each of these types; instead, we use templates. In terms of implementation, your code will look no different than if you were operating on a basic type (e.g., doubles). However, the compiler will complain if you try to interpolate a type for which interpolation doesn't make sense! For instance, if you tried to interpolate `Skeleton` objects, the compiler would likely complain that there is no definition for the sum of two skeletons (via a + operator). In general, our spline interpolation will only make sense for data that comes from a vector space, since we need to add T values and take scalar multiples.
...
...
@@ -42,30 +42,30 @@ The routine from part 1A just defines the interpolated spline between two points
The basic idea behind Catmull-Rom is that for a given time t, we first find the four closest knots at times
<imgsrc=task1_media/0014.pngheight="30">
<imgsrc="task1_media/0014.png"height="30">
We then use t1 and t2 as the endpoints of our cubic "piece," and for tangents we use the values
ome to Scotty3D! This 3D graphics software implements interactive mesh editing, realistic path tracing, and dynamic animation. Implementing the functionality of the program constitutes the majority of the coursework for 15-462/662 Computer Graphics at Carnegie Mellon University
<imgsrc=task1_media/0015.pngheight="30"><br/>
<imgsrc="task1_media/0015.png"height="30"><br/>
<imgsrc=task1_media/0016.pngheight="30"><br/>
<imgsrc="task1_media/0016.png"height="30"><br/>
In other words, a reasonable guess for the tangent is given by the difference between neighboring points. (See the Wikipedia and our course slides for more details.)
<imgsrc=task1_media/spline_diagram.jpg><br/>
<imgsrc="task1_media/spline_diagram.jpg"><br/>
This scheme works great if we have two well-defined knots on either side of the query time t. But what happens if we get a query time near the beginning or end of the spline? Or what if the spline contains fewer than four knots? We still have to somehow come up with a reasonable definition for the positions and tangents of the curve at these times. For this assignment, your Catmull-Rom spline interpolation should satisfy the following properties:
* If there are no knots at all in the spline, interpolation should return the default value for the interpolated type. This value can be computed by simply calling the constructor for the type: T(). For instance, if the spline is interpolating Vector3D objects, then the default value will be <imgsrc=task1_media/0017.pngheight="20">.
* If there are no knots at all in the spline, interpolation should return the default value for the interpolated type. This value can be computed by simply calling the constructor for the type: T(). For instance, if the spline is interpolating Vector3D objects, then the default value will be <imgsrc="task1_media/0017.png height"="20">.
* If there is only one knot in the spline, interpolation should always return the value of that knot (independent of the time). In other words, we simply have a constant interpolant. (What, therefore, should we return for the 1st and 2nd derivatives?)
* If the query time is less than or equal to the initial knot, return the initial knot's value. (What do derivatives look like in this region?)
* If the query time is greater than or equal to the final knot, return the final knot's value. (What do derivatives look like in this region?)
Once we have two or more knots, interpolation can be handled using general-purpose code. In particular, we can adopt the following "mirroring" strategy to obtain the four knots used in our computation:
* Any query time between the first and last knot will have at least one knot "to the left" <imgsrc=task1_media/0018.pngheight="20"> and one "to the right" <imgsrc=task1_media/0019.pngheight="20">.
* Suppose we don't have a knot "two to the left" <imgsrc=task1_media/0020.pngheight="20">. Then we will define a "virtual" knot <imgsrc=task1_media/0021.pngheight="20">. In other words, we will "mirror" the difference be observe between <imgsrc=task1_media/0022.pngheight="20"> and <imgsrc=task1_media/0023.pngheight="20"> to the other side of <imgsrc=task1_media/0024.pngheight="20">.
* Likewise, if we don't have a knot "two to the right" <imgsrc=task1_media/0025.pngheight="20">), then we will "mirror" the difference to get a "virtual" knot <imgsrc=task1_media/0026.pngheight="20">.
* Any query time between the first and last knot will have at least one knot "to the left" <imgsrc="task1_media/0018.png"height="20"> and one "to the right" <imgsrc="task1_media/0019.png"height="20">.
* Suppose we don't have a knot "two to the left" <imgsrc="task1_media/0020.png"height="20">. Then we will define a "virtual" knot <imgsrc="task1_media/0021.png"height="20">. In other words, we will "mirror" the difference be observe between <imgsrc="task1_media/0022.png"height="20"> and <imgsrc="task1_media/0023.png"height="20"> to the other side of <imgsrc=task1_media/0024.pngheight="20">.
* Likewise, if we don't have a knot "two to the right" <imgsrc="task1_media/0025.png"height="20">), then we will "mirror" the difference to get a "virtual" knot <imgsrc="task1_media/0026.png"height="20">.
* At this point, we have four valid knot values (whether "real" or "virtual"), and can compute our tangents and positions as usual.
* These values are then handed off to our subroutine that computes cubic interpolation over the unit interval.
...
...
@@ -82,4 +82,4 @@ Once you have implemented the functions in `spline.cpp`, you should be able to m