How do I plot a square given the length of the sides and the center of x and y?
16 views (last 30 days)
Show older comments
Fausto Pachecco Martínez on 11 Nov 2021
Commented: Matt J on 11 Nov 2021
I have this code to graph a square based on the input data that the user enters, which is L (length of the sides) and x0, y0 (the center of X and Y). When my square is graphed it comes out with these lines and I don't know how to remove or limit them.
r = input("Enter the radius of the circle: ");
l = input("Enter the length of the sides of the square: ");
x0 = input("Enter the center of x: ");
y0 = input("Enter the center of y: ");
x = linspace(0,1,5);
y = zeros(1,5);
x = cosd(0) * l * x - sind(0) * l * y;
y = sind(0) * l * x + cosd(0) * l * y;
x2 = cosd(0) * l * x - sind(0) * l * y;
y2 = l + sind(0) * l * x + cosd(0) * l * y;
x3 = cosd(90) * l * x - sind(90) * l * y;
y3 = sind(90) * l * x + cosd(90) * l * y;
x4 = l + cosd(90) * l * x - sind(90) * l * y;
y4 = sind(90) * l * x + cosd(90) * l * y;
[x0,y0,L]=deal(2,1,4); %example input parameters
p=polyshape( [x0,y0]+[-1 -1; -1 1; 1 1; 1 -1]*L/2 );
You're welcome, but please Accept-click the answer to indicate that it provided a solution.
More Answers (0)
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!