CrazyEngineers
  • Matlab: Circle Plotting Error

    ISHAN TOPRE

    ISHAN TOPRE

    @ishan-nohePN
    Updated: Oct 8, 2024
    Views: 1.5K
    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;
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • ISHAN TOPRE

    MemberSep 30, 2014

    #-Link-Snipped-# do you know matlab?
    This is bresenham's circle algorithm.
    Are you sure? This action cannot be undone.
    Cancel
  • ISHAN TOPRE

    MemberSep 30, 2014

    #-Link-Snipped-# #-Link-Snipped-# anyone from computer science.
    Are you sure? This action cannot be undone.
    Cancel
  • Abhishek Rawal

    MemberSep 30, 2014

    #-Link-Snipped-# No idea on anything related to Matlab even though I am from ECE discipline. Sorry.
    Are you sure? This action cannot be undone.
    Cancel
  • Shashank Moghe

    MemberOct 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?
    Are you sure? This action cannot be undone.
    Cancel
  • ISHAN TOPRE

    MemberOct 1, 2014

    I wanted a function to be used instead of "funplot". Apparently the problem was solved.
    Are you sure? This action cannot be undone.
    Cancel
  • Shashank Moghe

    MemberOct 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.
    Are you sure? This action cannot be undone.
    Cancel
  • ISHAN TOPRE

    MemberOct 2, 2014

    I used funplot only. There was an error with variables defined.
    Are you sure? This action cannot be undone.
    Cancel
  • Shashank Moghe

    MemberOct 2, 2014

    On a side note, I am surprised how little Engineers use Matlab 😔 It is by far Computational Science's best tool ever!
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register