How do I plot a square given the length of the sides and the center of x and y?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Fausto Pachecco Martínez
le 11 Nov 2021
Commenté : Matt J
le 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: ");
%SQUARE
figure(1),clf;
x = linspace(0,1,5);
y = zeros(1,5);
hold on
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;
plot(x,y)
plot(x2,y2)
plot(x3,y3)
plot(x4,y4)
hold off
axis equal
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Install Products dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
