In this lab, we’re going to construct a couple of cubics that satisfy a set of user supplied constraints.
Please download the lab and go over the code.
For solving a linear system, we are using a C++ library called Eigen. You’ll have to install this in the same way you installed glm in lab 0. You’ll need to create a new environment variable called EIGEN3_INCLUDE_DIR
that points to the Eigen directory. Once you have it installed, you may want to look at this quick tutorial.
Your first task is to draw the two cubics. The coefficients of the two cubics have already been set for you. These two sets of coefficients are stored in coeffs0
and coeffs1
. (In the next task, you will be changing these coefficients.) Given these coefficients, the two cubics are given by:
The coefficient vectors coeffs0
and coeffs1
store the xmid
global variable, which is set to
Compute the coefficient vectors coeffs0
and coeffs1
that satisfy the following
You need to come up with the correct entries for coeffs0
, and the bottom four are coeffs1
. With Eigen, you can use the following to solve a linear system.
VectorXf c = A.colPivHouseholderQr().solve(b);
Once you get the correct coefficients, you’ll see the figure below.
Finally, draw the tangent line of the functions using the x-coord of the mouse. The global variable, mouse
, contains the world coordinates of the mouse cursor. Evaluate the position and the derivative of the function at mouse(0)
) and draw a line that touches the function tangentially. When the mouse moves, this line should move with it. You’ll need to use the derivative,