필터 지우기
필터 지우기

Draw an array of colored circles (i.e, "rectangles")

조회 수: 4 (최근 30일)
Douglas Anderson
Douglas Anderson 2018년 12월 2일
댓글: Douglas Anderson 2018년 12월 3일
Hello!
I would like to know if there is a simpler way to draw an array of colored circles. I have been using rectangles that have curvature to make them circles, created in a loop.
The following code draws one row of circles and then an array of several shorter rows of circles:
% Draw holes row one
for hole = 1:num_holes_row_one
x = (hole) * spacing_row_one;
y = -burden ;
rectangle('Position',[x y w h],'Curvature',[1 1],'facecolor','r');
hole_position_array(hole,:) = [x y];
end
num_holes = num_holes_rest_of_shot;
% Draw holes rest of array
hole_num = 1;
for row = 1:num_rows
for hole = 1:num_holes
this_hole_num = hole_num + num_holes_row_one;
x = ((hole-1) * spacing_rest_of_shot) + spacing_row_one;
y = -(row +1) * burden ;
if kill_me(this_hole_num) == 0
rectangle('Position',[x y w h],'Curvature',[1 1],'facecolor','r');
end
hole_position_array(this_hole_num,:) = [x y];
hole_num = hole_num + 1;
end
end
"kill_me()" is an array showing which are not to be printed. Is there a tool for multiple rectangles? Any thoughts on this are appreciated.
Doug Anderson
  댓글 수: 2
Image Analyst
Image Analyst 2018년 12월 2일
Please give us code that runs. What is num_holes_row_one? Also give any other variables that we'll need to run your code.
Douglas Anderson
Douglas Anderson 2018년 12월 3일
Thank you for responding.
Here is code that works on its own, separate from the rest of the application.
As an FYI, during the run of the application, several of the "holes" may be deleted, thus the "kill_me" array, which I have commented out. Also, the hole numbering has to start either on the left or the right, AND deletions from both left and right numbering must occur. The red dots need to be removed (a separate function), and renumbered appropriately. The whole left opening works fine, but opening on the right is a nightmare with the deletions.
% Multi circle test
figure
% Dummy Dimensions
num_holes_row_one = 8;
num_rows = 4;
num_holes_rest_of_shot = 5;
burden = 10;
spacing_row_one = 10;
spacing_rest_of_shot = ((num_holes_row_one - 1) / (num_holes_rest_of_shot - 1)) * spacing_row_one ;
total_holes = num_holes_row_one + (num_holes_rest_of_shot * num_rows);
kill_me = zeros(total_holes,1);
% Size of shot
total_depth = burden * (num_rows + 3); % Add extra row for first row
total_width = spacing_row_one * (num_holes_row_one + 1);
% Hole Position Array (to be filled in loop)
hole_position_array = zeros(total_holes,2);
%if ~exist('text_position_array')
text_position_array = zeros(total_holes,2);
%end
% Determine size of symbol
hole_size_factor = 10; % This seems to work well
hole_diameter = spacing_row_one / hole_size_factor;
w = hole_diameter;
h = hole_diameter;
% Label Adjustment
vert_adjust = w * 2;
horiz_adjust = w/2;
opendir = input('Open left = 1, Open right = -1: ');
% Draw holes row one
for hole = 1:num_holes_row_one
x = (hole) * spacing_row_one;
y = -burden ;
rectangle('Position',[x y w h],'Curvature',[1 1],'facecolor','r');
hole_position_array(hole,:) = [x y];
end
num_holes = num_holes_rest_of_shot;
% Draw holes rest of array
hole_num = 1;
for row = 1:num_rows
for hole = 1:num_holes
this_hole_num = hole_num + num_holes_row_one;
x = ((hole-1) * spacing_rest_of_shot) + spacing_row_one;
y = -(row +1) * burden ;
if kill_me(this_hole_num) == 0
rectangle('Position',[x y w h],'Curvature',[1 1],'facecolor','r');
end
hole_position_array(this_hole_num,:) = [x y];
hole_num = hole_num + 1;
end
end
%Draw Hole Numbers
%opendir = handles.opendir;
switch opendir
case 1 % Open from the left
hole_num = 1;
hole_summer = 1;
case -1
hole_num = num_holes_row_one;
hole_summer = -1;
end
for hole = 1:num_holes_row_one
x = (hole) * spacing_row_one + horiz_adjust;
y = -burden + vert_adjust; %-(row) * burden + vert_adjust;
text(x,y,num2str(hole_num),'horizontalalignment','center',...
'verticalalignment','bottom');
text_position_array(hole_num,:) = [x y];
hole_num = hole_num + hole_summer; %1;
end
%Rest of Rows
switch opendir
case 1
hole_to_print = hole_num;
dir_switcher = 0;
case -1
hole_to_print = hole_num + num_holes_row_one + num_holes;
dir_switcher = 1;
end
hole_num = 1;
hole_label = 1;
for row = 1:num_rows
for hole = 1:num_holes
this_hole_num = hole_num + num_holes_row_one;
hole_label = this_hole_num;
x = (hole -1) * spacing_rest_of_shot + spacing_row_one + horiz_adjust;
y = -(row + 1) * burden + vert_adjust;
if kill_me(this_hole_num) == 0
text(x,y,num2str(hole_to_print),'horizontalalignment','center',...
'verticalalignment','bottom');
hole_to_print = hole_to_print + 1;
else
%hole_num = hole_num - 1 ;
end
hole_num = hole_num + 1 ;
%{
if kill_me(this_hole_num) == 0
if hole == num_holes && dir_switcher == 1
hole_to_print = hole_to_print + (num_holes * 2) -1;
else
hole_to_print = hole_to_print + hole_summer;
end
end
text_position_array(this_hole_num,:) = [x y];
%}
%hole_num = hole_num + 1;
end
end
axis equal
axis off
Thanks again for looking at this! You folks are great.
Doug Anderson

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometry and Mesh에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by