1
$\begingroup$

The following code is used to draw circles;

 pts={{0.02,0.44},{0.08,0.58},{0.22,0.57},{0.3,0.9},{0.39,0.24},{0.44,0.79},{0.65,0.19},{0.82,0.93},{0.93,0.7},{0.95,0.11}}
 r = 0.2; 
 Show[Graphics[{Blue, Circle[#, r] & /@ pts, Black, Point[pts], 
      FaceForm[Opacity[.5,LightBlue]],EdgeForm[{Thick,Darker@Blue}],disks}]] 

The output would be as the following image;

Multiple circles image

I want to do the following;

  • Label the circles' centers according to the order of the pts points; e.g. circle with center pts of {0.02,0.044} has the label of X1 and so on for other circles.
  • Draw multiple lines that have start point (0,0) with different angles (0:5:90).
  • For each line;
    • Get the number of circles, intersected with that line.
    • Get the indices of circles that intersected with that line.
    • Get intersection points' values that resulted from the intersection between that line and the circles which intersected with that line.
    • Sort these intersection points ascending x-coordintes.

So, the output would be like the following image; But adding also tool-tip; So, by clicking on each line; I should get the output like that;

For example; By clicking on the line of degree(0); it should give the following output;

  • Line of degree: 0
  • no. of circles intersected with that line: 2
  • Indices of circles intersected with that line: X7 , X8
  • Points of intersection values ,sorted ascending to x-axis:
    • Points with line and circle X7 C1(x1,y1),C1(x2,y2): {{0.5878,0},{0.71222,0}}
    • Points with line and circle X8 C2(x1,y1),C2(x2,y2): {{0.78307,0},{1.117,0}}

Intersectio points

  • Then make loop as following to get value of L;

Loop to get value of L

Where;

  • m: is the number of circles intersected with each line.

  • C: is the intersection points.

  • j: is the index of each circle j=1,.....,m.

Any suggestions for code to do that??

$\endgroup$
2
$\begingroup$

This gets you part of the way

pts = {{0.02, 0.44}, {0.08, 0.58}, {0.22, 0.57}, {0.3, 0.9}, {0.39, 0.24},
 {0.44, 0.79}, {0.65, 0.19}, {0.82, 0.93}, {0.93, 0.7}, {0.95, 0.11}};
labels = {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10"};
angles = Table[{Cos[a], Sin[a]}, {a, 0, 90 Degree, 5 Degree}];
endpts = Map[#*1.2/(Max @@ #) &, angles];
r = 0.2;
int = Quiet[Table[Map[{x, y} /. 
   Solve[{y == Tan[a] x, (y - #[[2]])^2 + (x - #[[1]])^2 == r^2}, {x, y},
     Reals]&, pts], {a, 0, 85 Degree, 5 Degree}]];
Print["Get the number of circles, intersected with that line=", 
  Map[Length, int /. {x, y} -> Sequence[]]];
Print["Get the indices of circles that intersected with that line=", 
  Map[First, Map[Thread[{Range[10], #}]&, int] /. {_, {x, y}}->Sequence[], {2}]];
Print["Intersection points' values that resulted from the intersection between that \
  line and the circles which intersected with that line=", 
  Map[Partition[Flatten[#], 2]&, int /. {x, y}->Sequence[]]];
Print["Sort these intersection points ascending x-coordintes=", 
  Map[SortBy[#, First]&, Map[Partition[Flatten[#], 2]&, int /. {x, y}->Sequence[]]]];
Show[Graphics[{Blue, Circle[#, r]& /@ pts, Black, Point[pts], 
  FaceForm[Opacity[.5, LightBlue]], EdgeForm[{Thick, Darker@Blue}]}],
  Graphics[{Text @@@ Thread[{labels, pts}]}], 
  Graphics[{Line[{{0, 0}, #}]& /@ endpts}], 
  Graphics[{Red, Circle[#, .02]& /@ Partition[Flatten[int /. {x, y}->Sequence[]], 2]}]]

You should be able to take each one of those Print and turn them into your interactive graphical tool tip clicking manipulate application.

You should be very careful with this and test it extensively. It appears to work with the example data you had, but I would not be surprised if there are problems if you had, for example, a line which intersected no circles or other similar unusual cases.

$\endgroup$
  • $\begingroup$ Thanks so much for your help and your notice. $\endgroup$ – Eman Sep 10 '18 at 20:00
1
$\begingroup$

I didn't do compute l parts but here's the function to compute values:

compulteInterSection[l : Line[{x1_, y2_}], circles_] :=    
 Module[{degree, res, n, ind, points},
  degree = ArcTan @@ (y2 - x1);
  res = RegionIntersection[l, #] & /@ circles;
  n = Count[res, _Point];
  ind = Flatten[Position[res, _Point]];
  points = 
   Sort[If[VectorQ[#], {#}, #]] & /@ Cases[res, _Point][[All, 1]];
  {degree, n, ind, points}
  ]

Some utility function to make pod:

makePod[{deg_, 0, _, _}] := Grid[{
   {"Line of Degree:", deg},
   {"# of circle intersect:", 0},
   {"Indices of circles", "" },
   {"Points of intersection values: ", ""}
   }, Alignment -> {Left, Top}
  ]

makePod[{deg_, n_, ind_, points_}] :=
 Grid[{
   {"Line of Degree:", deg},
   {"# of circle intersect:", n},
   {"Indices of circles", 
    StringTrim[StringJoin["X" <> ToString[#] <> ", " & /@ ind], 
     ", "] },
   {"Points of intersection values: ", Grid[points]}
   }, Alignment -> {Left, Top}
  ]

I just make the example using Manipulate, you could modify it other form you want. It has a tooltip:

labels = Text[Style["X" <> ToString[#1], Red, 14], #2, {0, -1} ] & @@@
    Transpose[{Range[Length[circles]], pts}];

circles = Circle[#, r] & /@ pts;

Manipulate[
 Block[{res},
  res = compulteInterSection[Line[{{0, 0}, 2 {Cos[p], Sin[p]}}], 
    circles];
  Overlay[{Graphics[{Blue, circles, 
      labels, {ColorData["Rainbow"][2 p /Pi], 
       Tooltip[Line[{{0, 0}, 2 {Cos[p], Sin[p]}}], makePod[res]], Red,
        Circle[#, .015] & /@ Flatten[res[[4]], 1]}}, Frame -> True, 
     PlotRange -> {{-0.2, 1.2}, {-0.2, 1.2}}, ImagePadding -> 40], 
    If[pq, Panel[Chop@makePod[res]], Nothing]}, All, 1]
  ],
 {p, 0, Pi/2},
 {{pq, False, "show pod"}, {True, False}}, ContentSize -> {420, 400}
 ]
$\endgroup$
  • $\begingroup$ Thanks so much for your help. $\endgroup$ – Eman Sep 11 '18 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.