I have a 2D reward function for a reinforcement learning project which is a rectangular surface created by the multiplication of two rectangular pulses, each one built with the substraction with a pair of heaviside functions.
Although I know there's already a "heaviside" function in MATLAB, I needed to approximate it using a mathematical expression from scratch (due to certain functions incompatibilty in Simulink). The approximation is as follows:
The corresponding code is:
[xmat,ymat] = meshgrid(xvec,yvec);
rect2D = ((1+exp(-2*k*(x+x0))).^-1-(1+exp(-2*k*(x-x1))).^-1).*...
((1+exp(-2*k*(y-y0))).^-1-(1+exp(-2*k*(y-y1))).^-1);
contourf(xvec,yvec,rect2D);
The objective is to rotate this 2D rectangle by its center (whatever the coordinates of its center are and knowing the four corners) using mathematical transformations (i.e not using default rotation functions as "rotate" or "imrotate"), because in the end I wish to have a single mathematical expression with the variables "x" and "y" to be able to compute the value at any point.
I tried to do the job with rotation matrices, but I'm struggling with the matrix dimensions, since the surface is a 100x100 matrix and the 2D or 3D rotations matrices dimensions don't match and the product can't be done.