Hello, I wrote a Script with Drawing Functions for use in later Projects. But I have a problem. If I call the function drawrectangle It is only drawing the left and the top line of the rectangle. I cannot find a solution for this problem. What is my mistake?
radius = 0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [] = drawcircle(radius,xincircle,yincircle) circle = 0:0.01:2*pi*radius; xcircle = radius*sin(circle) + xincircle; ycircle = radius*cos(circle) + yincircle; plot(xcircle,ycircle);endfunction [] = drawline(linex1,liney1,linex2,liney2) linex = linex1:0.01:linex2; liney = liney1:0.01:liney2; plot(linex,liney);endfunction [] = drawpoint(pointx,pointy,thickness) scatter(pointx,pointy,thickness,'filled');endfunction [] = drawrectangle(cornerx,cornery,width,height) drawline(cornerx,cornery,cornerx+width,cornery); drawline(cornerx+width,cornery,cornerx+width,cornery-height); drawline(cornerx+width,cornery-height,cornerx,cornery-height); drawline(cornerx,cornery-height,cornerx,cornery);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%xlim([-10,10]);ylim([-10,10]);axis equal;hold on%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
drawcircle(1,0,0);drawline(-10,-10,10,10);drawpoint(0,2,100);drawrectangle(-5,5,10,10);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%hold off
Small explanation of the Code: over the first % seperator, I define a variable that is needed in the draw circle function. Between the first and the second seperator are the functions. Between the second and third seperator I configure some parameters for the figure and there is the hold on command. Between the third and the fourth seperator I call the functions. This is the section where my later code will be written. After the last it is just the hold off command.
Best Answer