Message Boards Message Boards

0
|
5664 Views
|
6 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Plot circles with given centres?

Posted 6 years ago

Hi there,

I have a problem regarding Mathematica. I want to plot circles, which centres (coordinates) I am given in an array which looks something like this:

array=[{x1,y1},{x2,y2},{x3,y3}]

The circles must be as big as possible, but mustn't intersect with each other (they can touch though).

Any help will be greatly appreciated.

Kind regards.

POSTED BY: Matej Rakar
6 Replies
Posted 6 years ago

Now it's clear to me. Thank you and be well.

POSTED BY: Matej Rakar
In[3]:= cntrs = {{1, 2}, {-1, 1}, {1, 3}};

In[4]:= cons = 
 Flatten @ 
  Table[r[i] + r[j] <= 
    Sqrt[(cntrs[[i]] - cntrs[[j]]).(cntrs[[i]] - cntrs[[j]])], {i, 
    2}, {j, i + 1, 3}]

Out[4]= {r[1] + r[2] <= Sqrt[5], r[1] + r[3] <= 1, 
 r[2] + r[3] <= 2 Sqrt[2]}

In[5]:= sln = 
 NMaximize[{r[1] + r[2] + r[3], Sequence @@ cons}, {r[1], r[2], r[3]}]

Out[5]= {3.03225, {r[1] -> 0.20382, r[2] -> 2.03225, r[3] -> 0.79618}}

In[7]:= Show[
 Graphics @ Table[Circle[cntrs[[i]], r[i]], {i, 3}] /. sln[[2]], 
 Graphics @ Table[Point[cntrs[[i]]], {i, 3}]]

enter image description here

POSTED BY: Frank Kampas

It's a global optimization problem. Suppose you are given 3 centers. Your variables will be the radii of the 3 circles. Your objective function could be the sum of the 3 radii. Your constraints are the three constraints that the circles not overlap, that the sum of the radii of each pair be less than or equal to the distance between the centers of the pair of circles. You could do it with NMaximize.

POSTED BY: Frank Kampas
Posted 6 years ago

Thanks for the reply Frank. I already know this, but I am struggling with Mathematica syntax. I can't find a way to calculate and then plot those circles. Could you elaborate on this a bit more?

Thank you in advance.

POSTED BY: Matej Rakar

The constraint that two circles not overlap is that the distance between the centers must be greater than or equal to the sum of their radii.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract