Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6726077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:53:02+00:00 2026-05-26T09:53:02+00:00

I’ve been using a function file [ret]=drawellipse(x,y,a,b,angle,steps,color,img) . Calling the function through a script

  • 0

I’ve been using a function file [ret]=drawellipse(x,y,a,b,angle,steps,color,img). Calling the function through a script file to draw random ellipses in image. But once i set the random center point(x,y), and random a, b, there is high possibility that the ellipses intersection would occur. How can i prevent the intersection? (I’m supposed to draw the ellipses that are all separate from each other)
Well, over here i have a function file which is to check whether the ellipses got overlap or not,overlap = overlap_ellipses(x0,y0,a0,b0,angle0,x1,y1,a1,b1,angle1). If the two ellipses are overlap, then the ‘overlap=1’, otherwise ‘overlap=0’.
Based on all these, i tested in the command window:

x=rand(4,1)*400;  % x and y are the random coodinates for the center of ellipses
y=rand(4,1)*400;
a=[50 69 30 60];  % major axis   for a and b, i intend to use random also in the future
b=[20 40 10 40];  % minor axis
angle=[30 90 45 0]; % angle of ellipse
steps=10000;
color=[255 0 0];   % inputs for another function file to draw the ellipse
img=zeros(500,500,3);

The following i want to dispaly the ellipses if overlap==0, and ‘if overlap==1’, decrease the a and b, till there is no intersection. Lastly, to imshow the img.

for i=1:length(x)
img=drawellipse(x(i),y(i),a(i),b(i),angle(i),steps,color,img);
end

For me now, i have difficulty in coding the middle part. How can i use the if statement to get the value of overlap and how to make the index corresponding to the ellipse i need to draw.

i tested a bit like

for k=1:(length(x)-1)
overlap = overlap_ellipses(x(1),y(1),a(1),b(1),angle(1),x(1+k),y(1+k),a(1+k),b(1+k),angle(1+k))
end

it returns

overlap=0
overlap=0
overlap=1

it is not [0 0 1]. I can’t figure it out, thus stuck in the process.
The final image shoule look like the picture in this voronoi diagram of ellipses.
(There is no intersection between any two ellipses)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:53:03+00:00Added an answer on May 26, 2026 at 9:53 am

    The solution proposed by @arne.b (the first one) is a good way to rasterize non-overlapping ellipses.

    Let me illustrate that idea with an example. I will be extending my previous answer:

    %# color image
    I = imread('pears.png');
    sz = size(I);
    
    %# parameters of ellipses
    num = 7;
    h = zeros(1,num);
    clr = lines(num);             %# color of each ellipse
    x = rand(num,1) .* sz(2);     %# center x-coords
    y = rand(num,1) .* sz(1);     %# center y-coords
    a = rand(num,1) .* 200;       %# major axis length
    b = rand(num,1) .* 200;       %# minor axis length
    angle = rand(num,1) .* 360;   %# angle of rotation
    
    %# label image, used to hold rasterized ellipses
    BW = zeros(sz(1),sz(2));
    
    %# randomly place ellipses one-at-a-time, skip if overlaps previous ones
    figure, imshow(I)
    axis on, hold on
    for i=1:num
        %# ellipse we would like to draw directly on image matrix
        [ex,ey] = calculateEllipse(x(i),y(i), a(i),b(i), angle(i), 100);
    
        %# lets plot the ellipse (overlayed)
        h(i) = plot(ex,ey, 'LineWidth',2, 'Color',clr(i,:));
    
        %# create mask for image pixels inside the ellipse polygon
        mask = poly2mask(ex,ey,sz(1),sz(2));
    
        %# get the perimter of this mask
        mask = bwperim(mask,8);
    
        %# skip if there is an existing overlapping ellipse
        if any( BW(mask)~=0 ), continue, end
    
        %# use the mask to place the ellipse in the label image
        BW(mask) = i;
    end
    hold off
    legend(h, cellstr(num2str((1:num)','Line%d')), 'Location','BestOutside')    %'
    
    %# set pixels corresponding to ellipses using specified colors
    clr = im2uint8(clr);
    II = I;
    for i=1:num
        BW_ind = bsxfun(@plus, find(BW==i), prod(sz(1:2)).*(0:2));
        II(BW_ind) = repmat(clr(i,:), [size(BW_ind,1) 1]);
    end
    figure, imshow(II, 'InitialMagnification',100, 'Border','tight')
    

    all_overlayed_ellipses
    rasterized_nonoverlapping_ellipses

    Note how the overlap test is performed in the order the ellipses are added, thus after Line1 (blue) and Line2 (green) are drawn, Line3 (red) will be skipped because it overlaps one of the previous ones, and so on for the rest…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.