Problems with plotting multiple objects over each other

조회 수: 4 (최근 30일)
Harold
Harold 2013년 3월 21일
I'm using the rectangle function to fill in a circle located at the center point (x,y) of a grid square and width and weigth (1,1) with curvature (1,1)...in other words a circle that touches the bounds of a grid square. This happens whenever I left click on the plot. I want to be able to right click in a grid square a have the filled in circle erase. For some reason Matlab won't overlay rectangles with the same center point. I was hoping to use the rectangle function again but with a black color (since my background is black). Once I get this part working, I want to extend it to replace any circle I click on with another circle of a different color I've picked already. Is there work around that I could use?
  댓글 수: 2
Jan
Jan 2013년 3월 21일
I do not understand the question. What does this mean: "have the filled in circle erase"? Or "For some reason Matlab won't overlay rectangles with the same center point."?
Harold
Harold 2013년 3월 22일
What I mean is I want to be able to delete the filled circle when I right click on it or if I left click on it with a different color selected. For example, in the picture here http://i50.tinypic.com/23if88j.jpg I first selected the blue color and left clicked on the grid squares. I then change to the red color and click on the grid squares. That blue circle should of been replaced with a red circle when I left clicked on it. I have the same problem when I try to right click on the circle. When I right click within the bounds of a grid square, the circle should be replaced with a circle colored in black (essentially erasing that circle from the board).

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

답변 (2개)

Wouter
Wouter 2013년 3월 21일
You could try to edit the renderer of the figure window:
set(gcf,'renderer','opengl') % changes the renderer of the current fig to opengl
set(gcf,'renderer','painters') %changes the renderer to painters
set(gcf,'renderer','zbuffer') %changes the renderer to buffer
A different renderer might be able to get rid of your visualisation problems.
  댓글 수: 1
Harold
Harold 2013년 3월 22일
Wouter,
Unfortunately editing the renderer did not work.

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


Image Analyst
Image Analyst 2013년 3월 22일
When you call rectangle, store the handle of it in a 6 by 6 array at the location of the circle in the grid. Then when you have to change the color, delete the handle before drawing the new one.
% Draw.
handleArray(row, column) = rectangle(.....
When it comes time to draw a new circle of a different color:
% Erase that handle to clear the circle.
delete(handleArray(row, column));
% Draw new circle at that location.
handleArray(row, column) = rectangle(.....
  댓글 수: 2
Harold
Harold 2013년 3월 22일
편집: Harold 2013년 3월 22일
I am trying to implement this code and I seem to be encountering a problem. When I right click in a grid square that has a circle, nothing happens. If I right click in a grid square that does not have a circle, an error appears stating "Invalid or deleted object". Which makes sense since there is no data to be deleted at that particular (row,col). I have no clue as to why your code is not working when there is a right click action in a grid square that contains a circle. I think the problem has to do with checking the button type.
Edit: Another problem I am having is that if I try and draw more than one circle of the same color one after the other, only the handle of the last circle drawn is kept in the array. Also, if I try and left click on a circle that already contains a circle the old circle will not get replaced by the new color choice.
As of now this is my code structure:
1) Get position of mouse in the figure.
2) If mouse is within bounds of axis (by comparing mouse location in figure to axis bounds by get(gca,'Position')), call @select_point.
3) Logic condition within select_point.m
if strcmp(btn_type,'normal')
handleArray(row_num, col_num) = rectangle...
hold on
elseif strcmp(btn_type,'alt')
delete(handleArray(row_num, col_num))
end
4) Plot grid lines using plot_grid.m. The variable div sets how many divisions each side of the grid will have. I decided to make my own grid due to resizing issues.
function plot_grid(div)
% specify the minor grid vector
xg = [0:1:div];
% specify the Y-position and the height of minor grids
yg = [0:1:div];
%vertical lines
x = repmat(xg,length(xg),1);
y = repmat(flipud(yg'),1,length(yg));
plot([x,x'],[y,y'],'w')
set(gca,'Color',[0, 0, 0]);
set(gca, 'XTick',[]);
set(gca, 'YTick',[]);
box off
axis square
Harold
Harold 2013년 3월 24일
No other suggestions? If you would like here is the fully developed code as of thus far. Flow_FreeGUI is the main program that you should run.

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

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by