# Why the rotation of a function of 3d using matrix rotation goes in the opposite direction than the rotation of a vector?

When rotating a vector of 3 dimensions with respect to the z-axis, we do $x'=x \cdot \cos{\theta} - y \cdot \sin(\theta)$ and $y'=y \cdot \cos{\theta} + x \cdot \sin(\theta)$.

Using this method, we rotate the vector in counterclockwise. However, if we do this exact method with a 3d function, such as $x^2-y^2$ then the function rotates clockwise.

Why does this differentiation happen?

Perhaps the best way to understand this is to look at horizontal transformations of functions of one variable. If you take a function $f(x)$ and want to, say, shift it to the right by 2 units, you do the opposite inside the formula by writing a new function $g(x)=f(x-2)$.
The reason you do this is simple. Suppose $f(1) = 7$. If you want this $y$-value of $7$ to happen at $x=3$ for the shifted function $g$, you need to use $g(x)=f(x-2)$, that way when you set $x=3$, you get $g(3)=f(3-2)=f(1)=7$. So even though formulaically we shifted $x$-values to the left by subtracting 2, the effect is to move the graph to the right. The moral you can take from this is that what you write on the inside of the function is opposite what you see on the graph.
This reasoning tells you exactly what is going on in your rotation of the 3D function. You put in a counterclockwise rotation on the inside of the function, so the function compensates by rotating its graph clockwise. Formally, let $R$ be the operation of rotating counterclockwise by some angle. Suppose $f(1,3)=7$, and let $g(x,y) = f(R(x,y))$. Where will $g$ take that value of $7$? Well, it'll do so at $R^{-1}(1,3)$, because $$g(R^{-1}(1,3)) = f(R R^{-1}(1,3)) = f(1,3) = 7.$$ That means $g$ takes the value $7$ at a new point $(x,y) = R^{-1}(1,3)$, which is the vector $(1,3)$ rotated clockwise, so $g$ is the graph of $f$ rotated clockwise.