Matlab: Circle Plotting Error

ISHAN TOPRE

ISHAN TOPRE

@ishan-nohePN Oct 8, 2024
I have a matlab program. In that program I do not know the function for plotting a circle. Whether it is fplot, ez plot, funplot. Can any body guide me?
clc, clear all, clf,close
a = input('Give the centre X coord : ');     % X coord of centre
b = input('Give the centre Y coord : ');     % Y coord of centre
r = input('Give the radius of circle : ');   % Radius of the circle to be drawn
inc = input('Give the increment step for coordinate[Default:1]: '); % Use the value
if isempty(inc)                              % of inc greater than 1
    inc =1;                                  % usually less than radius
end

x = 0;
y = r;
d= 3-2*r;

while(x < y)
    plot(a,b,x,y,r);
    if d>=0
        d = d +4*(x-y)+10;
        x = x + 1/inc;
        y = y - 1/inc;
    else
        d = d + 4*x +6;
        x = x+1/inc;
    end
end
plot(a,b,p,q,r)
for i= -1:2:1
    for j= -1:2:1
        plot(a+i*p,b+j*q,'r.');
        plot(a+i*q,b+j*p,'r.');
        grid off
        hold on
    end
end
title('Bresenham circle')
axis([a-r-1 a+r+1 b-r-1 b+r+1])
axis equal;

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • ISHAN TOPRE

    ISHAN TOPRE

    @ishan-nohePN Sep 30, 2014

    #-Link-Snipped-# do you know matlab?
    This is bresenham's circle algorithm.
  • ISHAN TOPRE

    ISHAN TOPRE

    @ishan-nohePN Sep 30, 2014

    #-Link-Snipped-# #-Link-Snipped-# anyone from computer science.
  • Abhishek Rawal

    Abhishek Rawal

    @abhishek-fg9tRh Sep 30, 2014

    #-Link-Snipped-# No idea on anything related to Matlab even though I am from ECE discipline. Sorry.
  • Shashank Moghe

    Shashank Moghe

    @shashank-94ap1q Oct 1, 2014

    Issue
    I have a matlab program. In that program I do not know the function for plotting a circle. Whether it is fplot, ez plot, funplot. Can any body guide me?
    clc, clear all, clf,close
    a = input('Give the centre X coord : ');     % X coord of centre
    b = input('Give the centre Y coord : ');     % Y coord of centre
    r = input('Give the radius of circle : ');   % Radius of the circle to be drawn
    inc = input('Give the increment step for coordinate[Default:1]: '); % Use the value
    if isempty(inc)                              % of inc greater than 1
        inc =1;                                  % usually less than radius
    end
     
    x = 0;
    y = r;
    d= 3-2*r;
     
    while(x < y)
        plot(a,b,x,y,r);
        if d>=0
            d = d +4*(x-y)+10;
            x = x + 1/inc;
            y = y - 1/inc;
        else
            d = d + 4*x +6;
            x = x+1/inc;
        end
    end
    plot(a,b,p,q,r)
    for i= -1:2:1
        for j= -1:2:1
            plot(a+i*p,b+j*q,'r.');
            plot(a+i*q,b+j*p,'r.');
            grid off
            hold on
        end
    end
    title('Bresenham circle')
    axis([a-r-1 a+r+1 b-r-1 b+r+1])
    axis equal;

    What exactly do you want to accomplish? Do you want a readymade fn() or do you want to use the algorithm?

    Are you saying the algorithm code does not plot what you want it to plot?
  • ISHAN TOPRE

    ISHAN TOPRE

    @ishan-nohePN Oct 1, 2014

    I wanted a function to be used instead of "funplot". Apparently the problem was solved.
  • Shashank Moghe

    Shashank Moghe

    @shashank-94ap1q Oct 2, 2014

    Issue
    I wanted a function to be used instead of "funplot". Apparently the problem was solved.

    What did you use instead of plot()? You can also do one easy trick in such cases, in case you are not sure of which plotting fn() to use: Go to the variables window, select the variables you want to plot, and on the top of that sub-window, there is a plot "tool", more like a drop down, which gives you a complete idea about all the possible plots you can get.
  • ISHAN TOPRE

    ISHAN TOPRE

    @ishan-nohePN Oct 2, 2014

    I used funplot only. There was an error with variables defined.
  • Shashank Moghe

    Shashank Moghe

    @shashank-94ap1q Oct 2, 2014

    On a side note, I am surprised how little Engineers use Matlab 😔 It is by far Computational Science's best tool ever!