![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1579656/image.png)
how to scale the shape which defined by parametric function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
%miniProject
%define a love
t = linspace(0, 2*pi, 1000); %parameter t from 0 to 2pi
x = 16 * sin(t).^3; %parameter function for love (searching from google)
y = 13 * cos(t) - 5 * cos(2*t) - 2 * cos(3*t) - cos(4*t);
figure
plot(x, y, 'r', 'LineWidth', 2);
axis equal;
axis([-200 200 -200 200]);
grid on;
pause(0.1)
% 调用 translateShape 函数进行平移
translatedLove = translateShape(x,y,5);
hold on;
plot(translatedLove, 'b', 'LineWidth', 2);
legend('originalshape', 'translatedLove');
hold off;
function translatedShape = translateShape(x, y, scale)
% t: parameter
% x, y: coordinates of the original shape
% scale: scaling factor
translatedShape = [x * scale, y * scale]
end
0 commentaires
Réponse acceptée
Sonesson
le 31 Déc 2023
Hello Jlayun,
The main issue you have here is that you are putting the x and y row vectors into the same row (making the vector 1x2000), and then plotting that row.
Replace the comma with a semicolon in the translateShape() function:
function translatedShape = translateShape(x, y, scale)
% t: parameter
% x, y: coordinates of the original shape
% scale: scaling factor
translatedShape = [x * scale; y * scale];
end
This will make the vector 2x1000 instead. Then update the plot to reflect this change:
plot(translatedLove(1,:),translatedLove(2,:), 'b', 'LineWidth', 2);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1579656/image.png)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots 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!