Generating Geometry Patterns at Scale
4 次查看(过去 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!