note: this is a somewhat lighter hw. if you feel like you only sort of understood the last hw, i recommend using this week to fill in any gaps before things blast off again 🚀
We can define linear interpolation as $LERP(t, \mathbf{a}, \mathbf{b}) = (1-t)\mathbf{a} + t\mathbf{b}$. $LERP(0, a, b)$ is $a$. $LERP(1, a, b)$ is $b$. $LERP(.5, a, b)$ is the average of $a$ and $b$. We can define a clamp as $CLAMP(t, a, b) = MIN(MAX(t, a), b)$. This function "clamps $c$ to the inveral $[a, b]$." To do a "clamped lerp" (which does not extrapolate"outside of the interval $[a, b]$) we can use $LERP(CLAMP(t, 0, 1), \mathbf{a}, \mathbf{b})$. To smoothly bounce back and forth between $\mathbf{a}$ and $\mathbf{b}$, we can use $LERP(.5 - .5cos(t\pi), \mathbf{a}, \mathbf{b})$, which we could perhaps call "cosine linear interpolation". The length of a vector is $|\mathbf{v}| = \sqrt{\sum_iv_i^2}$. In 3D, $|\mathbf{v}| = \sqrt{v_x^2 + v_y^2 + v_z^2}$. Exercise: Derive the formula for the distance between two points $distance(\mathbf{p}, \mathbf{q}) = \sqrt{\sum_i(q_i-p_i)^2}$.
HINT
The distance between points $\mathbf{p}$ and $\mathbf{q}$ is the length of the vector pointing from $\mathbf{p}$ to $\mathbf{q}$.HINT
$\mathbf{I} = \mathbf{A}\mathbf{B}\mathbf{B}^{-1}\mathbf{A}^{-1}$a. (20 pts) hello linear system Write the following linear system as a matrix equation, and solve it using the snail function
inverse(mat3 M)
.
Print your answer using using snails pretty printing function pprint(...)
.
$$\begin{cases}3x=z\\x-y=-1\\z-y=1\end{cases}$$If we call the solution to the system point $\mathbf{p}=(x, y, z)^T$, what is distance from $\mathbf{p}$ to $\mathbf{q} = (-0.282550, 3.282550, 5.565100)^T$?
printf("%lf\n", ...);
your answer.
HINT
rewrite the system in the form $$\begin{cases}A_{11}x+A_{12}y+A_{13}z=b_1\\A_{21}x+A_{22}y+A_{23}z=b_2\\A_{31}x+A_{32}y+A_{33}z=b_3\end{cases}$$inside
to indicate whether the test point is inside the circle.
c. (25 pts) points in circle
Extend your solution to the previous problem into a new app, which should do the same thing, but now with 4096 points. All points should still be draggable.
d. (10 pts) contrived problem to make you learn how to use a debugger
Please find the first frame that local variable k
ends in the digits 47 (printf
_not_ allowed), and set variable the_first_frame_that_k_ends_in_47
to match. if you are successful, the screen should turn William's purple (don't be fooled by a slightly darker decoy purple).
premium bonus HINT
debuggers are powerful! you can actually type expressions into the watch window. for example,k % 100 == 47
a
and b
according to time t
. A green dot should use (vanilla, unclamped) linear interpolation; a red dot should use clamped linear interpolation; and a purple dot should use "cosine linear interpolation."
🔺. (+ 1 pt extra credit) Add a white dot that uses triangle wave linear interpolation. Up until time 1, it should behave exactly like vanilla or clamped lerp. Then it will look like the ball is bouncing off the vertical lines, a la hw1. No workarounds allowed (though also no pressure to write a macro).
f. (10 pts) fun with barycentric coordinates
Consider a 2D triangle with vertices $\mathbf{a}$, $\mathbf{b}$, $\mathbf{c}$.
Consider a point $\mathbf{p}$ with barycentric coordinates $(\alpha, \beta, \gamma)^T$.
I.e. $\mathbf{p} = \alpha\mathbf{a} + \beta\mathbf{b} + \gamma\mathbf{c}$, where $\alpha + \beta + \gamma = 1$.
Solve for $\alpha, \beta, \gamma$ using the snail function inverse(mat3 M)
.HINT
$$\begin{cases}a_x\alpha+b_x\beta+c_x\gamma=p_x\\a_y\alpha+b_y\beta+c_y\gamma=p_y\\\alpha+\beta+\gamma=1\end{cases}$$LERP
(or CLAMPED_LERP
, COS_LERP
), make an animation evocative of the topic "Changing Seasons" or "Winter Wonderland" that you find visually pleasing.
You may use basic_draw(...)
and gl_*
.
You are encouraged to interpolate position, color, size...
note: You will get full credit (but no extra credit) for meeting the bare minimum of this spec.