I am trying to draw arrows on a graph to show the normal gradient of a function. By gradient, I mean the arrows should follow the surface of the function, not being perpendicular to it.
For example the function $f(x, y) = 10sin(y - x) => z = 10sin(y - x)$. This is the graph I got
The arrows are coming very flat (on the x-y plane), and not really following the surface of the function.
This is what the function looks like
The problem is its not respecting the z-axis I think.
The way I generated the $(x,y,z)$ coordinates and the $(u,v,w)$ (this is the direction vector for each arrow) coordinates are:
Use the function above to get the gradient vector formula (using partial derivatives) which is
$q(x,y,z) = (-10cos(x - y), 10cos(x - y), -1) = (u,v,w)$
1. get your $x,y,z,u,v,w$
2. normalize $u,v,w$
3. draw the line from $(x,y,z)$ to $(x,y,z)+(u,v,w)*length$
Here I notice (I'm not sure if this is the problem) that the z component is always -1. Which is why the arrows appear to be flat on the x-y plane.
Does anyone see whats wrong here?