Counterclockwise rotation matrix is giving clockwise rotation I would like to rotate a contour surface given by an equation by 45 degrees counterclockwise. I know I need to transform the equation using a 2D rotation matrix. However, a conventional counterclockwise matrix rotation is somehow resulting in clockwise rotations. Am I calculating something wrong?
The original equation is given below. It's contour plot looks like this. 
$E_1 = (0.00125 x^4) - (0.125 x^2) + (0.5 y^2)$
A CCW rotation matrix by 45 degrees should transform x, y as 
$x' = x\cos \theta - y\sin\theta = 1/ \sqrt{2}(x-y)$ 
$y' = x\sin \theta + y\cos\theta = 1/ \sqrt{2}(x+y)$
Plugging $x'$ and $y'$ into the first $E_1$ gives the following equation of the rotated contour surface. As you can see, the rotation is somehow CW and not CCW as expected. 
$E_2 = (0.00124 (x - y)^ 4) / 4) - (0.125 (x - y) ^ 2) / 2) + (0.5 (x + y) ^ 2) / 2$
However, when I switch the signs in the parentheses, I end up getting the desired rotated contour surface:
$E_3 = (0.00124 (x + y)^ 4) / 4) - (0.125 (x + y) ^ 2) / 2) + (0.5 (x - y) ^ 2) / 2$
 A: The equations you got for $x'$ and $y'$ are correct:
$x' = x \cos \theta - y \sin \theta = \dfrac{1}{\sqrt{2}} (x - y) $
$y' = x \sin \theta + y \cos \theta = \dfrac{1}{\sqrt{2}} (x + y) $
Now, before plugging back into the equation of the curve, you have to solve the above two equations for $x$ and $y$ in terms of $x'$ and $y'$.  This can be done by matrix inversion.  You will find that
$x = \dfrac{1}{\sqrt{2}} (x' + y')$
$y = \dfrac{1}{\sqrt{2}} (y' - x')$
Now plug these in the equation (E1), and this will give you:
$0.00124 ((x' + y')^4/4 ) - 0.125 (x' + y')^2/2 + 0.5 (y' - x')^2$
Finally replace $(x', y')$ in this last equation with $(x, y)$ and note that
$(y' - x')^2 = (x' - y')^2$
then, the equation becomes,
$0.00124 ((x + y)^4/4 ) - 0.125 (x + y)^2/2 + 0.5 (x - y)^2$
which is the desired rotated curve by $45^\circ$ CCW, and identical to equation (E3).
A: In your first rotation attempt, you are computing the color value for a point $(x,y)$ by rotating it 45 degrees counterclockwise, to get $(x',y')$, and calculating the color value of original $E_1$ function there.
So, the color of the point $(x',y')$ in the original plot is drawn in your new picture at point $(x,y)$. That is, the whole figure is rotated clockwise.
The picture below illustrates what happens. On the right is the rotated picture. To compute the color at $(x,y)=(0,7)$, you are rotating the point counterclockwise to $(x',y') \approx (-4.95, 4.95)$, and computing the value of the original function at that point (see left panel).

