How do I rotate a rectangular surface by a certain angle and center?
Afficher commentaires plus anciens
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:
% Initial values
close all
xl = 8;
L = 1.4;
D = 1.5;
xvec = linspace(-xl,xl);
yvec = linspace(-D,xl);
[xmat,ymat] = meshgrid(xvec,yvec);
x = xmat/10;
y = ymat/10;
k = 300;
%% 2D rectangle surface plot
% Center coordinates
x0 = L/10; x1 = L/10;
y0 = 3*D/10; y1 = D/10;
% Moved center coordinates
% x0 = (L+5)/10; x1 = -(L+2)/10;
% y0 = 5*D/10; y1 = 3*D/10;
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);
axis equal
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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




