a = 150;
b = 75;

theta1 = linspace(-atan(b/a), atan(b/a), 100); 
theta2 = linspace(atan(b/a), pi - atan(b/a), 100); 
theta3 = linspace(pi - atan(b/a), pi + atan(b/a), 100);
theta4 = linspace(pi + atan(b/a), 2*pi - atan(b/a), 100);

r1 = a ./ abs(cos(theta1));
r2 = b ./ abs(sin(theta2));
r3 = a ./ abs(cos(theta3));
r4 = b ./ abs(sin(theta4));

theta = [theta1, theta2, theta3, theta4];
r = [r1, r2, r3, r4];

x = r .* cos(theta);
y = r .* sin(theta);

figure;
plot(x, y, 'b-', 'LineWidth', 2);
axis equal;
%grid on;
xlabel('x');
ylabel('y');
title('Rectangle in Polar Coordinates');

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: