Generating Geometry Patterns at Scale
14 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm new to matlab, and I'm wondering if it's possible to do the following:
- generate an image with specific dimensions
- plot (or logically define) equally spaced geometries within the image.
currently I have the ablility to plot multiple geometries:
xCenter = 10;
yCenter = 10;
% Modification to the FAQ is the next two lines.
numSides = 6; % <=== CHANGE THIS NUMBER
theta = linspace(0, 2*pi, numSides + 1);
% Rotate the shape by subtracting an offset.
theta = theta - pi/3;
%theta - pi/3 is for 6 sides
%theta - pi/6 for 3 sides
%teheta - pi/4 for 4 sides
%theta - pi/2 for upsideown 5 sides
radius = 5;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
plot(x, y);
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;
fill(x,y,'r')
Which plots this or other polygons based on the value for numSides:
(I can make circles this way by increasing numSides to a large number)

I also found a different approach for circles:
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 10;
circlePixels = (rowsInImage - centerY).^2 + (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
title('Binary image of a circle');
Which shows this:

It would be cool if I could duplicate the image above and place the two side by side. Is that possible?
Is it also possible to "flatten" the plot of the red polygon above into an image so that I can do the same duplicaition prossess?
Essentially our team needs many images with varied geometries and spacings. Doing this is photoshop, for example, would not be practicle. Is matlab the best place to easily do this? If so, is this the best route?
Thanks,
0 件のコメント
回答 (2 件)
Chunru
2021 年 11 月 29 日
What does flattenong the plot of the red polygon mean?
xCenter = 10;
yCenter = 10;
% Modification to the FAQ is the next two lines.
numSides = 6; % <=== CHANGE THIS NUMBER
theta = linspace(0, 2*pi, numSides + 1);
% Rotate the shape by subtracting an offset.
theta = theta - pi/3;
%theta - pi/3 is for 6 sides
%theta - pi/6 for 3 sides
%teheta - pi/4 for 4 sides
%theta - pi/2 for upsideown 5 sides
radius = 5;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
subplot(121)
plot(x, y);
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;
fill(x,y,'r')
axis equal
axis tight
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 10;
circlePixels = (rowsInImage - centerY).^2 + (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
subplot(122)
image(circlePixels) ;
colormap([0 0 0; 1 1 1]);
title('Binary image of a circle');
axis equal
axis tight
0 件のコメント
Steven Lord
2021 年 11 月 29 日
Consider using polyshape and the convenience function nsidedpoly.
h = nsidedpoly(6, 'Center', [10 10], 'Radius', 5);
plot(h)
figure
harray = repmat(h, 1, 5);
for k = 1:numel(harray)
harray(k) = translate(h, 10*k, 5*k);
end
plot(harray)
hold on
plot(nsidedpoly(1000, 'Center', [40 40], 'Radius', 8))
axis equal
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


