How to Draw an Ellipse Flower like this?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to draw 8 ellipses on the same grid and the angle of deviation between each of them must be pi/8. I have attached a flower with 18 leaves and I need to make one with 8 leaves. Each 'leave' is an ellipse.
Thanks in advance and greetings
0 commentaires
Réponse acceptée
Image Analyst
le 8 Jan 2017
My attached demo does exactly that. Just adapt it to change the angle increment and center point.
4 commentaires
Image Analyst
le 8 Jan 2017
I adapted it for you.
% Demo to rotate an ellipse over an image.
% By ImageAnalyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
hEllipse = imellipse(gca, [-5, -2, 5*2, 2*2]); % Second argument defines ellipse shape and position.
% Create a binary image ("mask") from the ROI object.
disp(hEllipse);
xy = hEllipse.getVertices();
x = xy(:,1);
y = xy(:,2);
xCenter = mean(x)
yCenter = mean(y)
plot(x, y);
axis equal;
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
x = x - xCenter;
y = y - yCenter;
xy = [x y];
n = 8;
for theta = 0 : 180/n : 180 - 180/n
fprintf('Theta = %f\n', theta);
rotationArray = [cosd(theta) sind(theta); -sind(theta) cosd(theta)];
rotated_xy = xy * rotationArray;
x = rotated_xy(:,1);
y = rotated_xy(:,2);
plot(x, y, 'b-', 'LineWidth', 2);
hold on;
end
ax = gca
grid on;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
ax.XTick = -5:5
ax.YTick = -6:6
axis square;

Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Explore and Edit Images with Image Viewer App 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!