1
$\begingroup$

I have been trying to plot a variable which is nested inside a manipulate. Here is a simplified version of the program.

pts = Table[{i, 0, 1}, {i, 0, 10}];
Manipulate[
R1 = Cylinder[{{3, 0, 0}, {3, 0, 2}}, x];
R2 = Cylinder[{{7, 0, 0}, {7, 0, 2}}, x];
R3 = RegionIntersection[R1, R2];
productY = Count[RegionMember[R3, pts], True];
Column[{
Text[productY],
Graphics3D[{
 Point[pts],
 Opacity[0.1],
 R1,
 R2
}],
Plot[productY, {t, 0, 10}]
}], {{x, 1, "variable x"}, 1, 5, 1}]

This creates a program which looks like this:

image

The program shows "5" as 5 dots are within the intersection of the two cylinders with radius "x". What I would like to plot is a graph of the number of dots within the intersection against variable x. Any ideas...?

Thank you.

$\endgroup$
  • $\begingroup$ Nothing is clear from these explanations. Give an example of your code from start to finish. $\endgroup$ – Alex Trounev Oct 15 '18 at 6:45
  • $\begingroup$ Alright. Lemme try to get a simplified example. $\endgroup$ – And a bit of soy. Oct 15 '18 at 7:02
1
$\begingroup$

You can also acquire a symbolic solution to this question with Total of Boole (truth value to 0/1) values of membership on parametric regions:

FullSimplify@
 Total[Function[{u, v, w}, 
    Evaluate@
     Boole@RegionMember[
       RegionIntersection[
        Cylinder[{{3, 0, 0}, {3, 0, 2}}, x], 
        Cylinder[{{7, 0, 0}, {7, 0, 2}}, x]], {u, v, w}]] @@@ 
   Table[{i, 0, 1}, {i, 0, 10}]]

Boole[x >= 2] + 2 (Boole[x >= 3] + Boole[x >= 4] + Boole[x >= 5] + Boole[x >= 6] + Boole[x >= 7])

And plot it:

Plot[FullSimplify@
  Total[Function[{u, v, w}, 
     Evaluate@
      Boole@RegionMember[
        RegionIntersection[
         Cylinder[{{3, 0, 0}, {3, 0, 2}}, x], 
         Cylinder[{{7, 0, 0}, {7, 0, 2}}, x]], {u, v, w}]] @@@ 
    Table[{i, 0, 1}, {i, 0, 10}]], {x, 1, 10}, Evaluated -> True]

enter image description here

$\endgroup$
0
$\begingroup$

If I understood your question correctly, then you can rip out the inner part of your code above and use ListLinePlot by creating a table containing {x, productY} elements:

pts = Table[{i, 0, 1}, {i, 0, 10}];
ListLinePlot[
 Table[{x,
   R1 = Cylinder[{{3, 0, 0}, {3, 0, 2}}, x];
   R2 = Cylinder[{{7, 0, 0}, {7, 0, 2}}, x];
   R3 = RegionIntersection[R1, R2];
   Count[RegionMember[R3, pts], True]},
  {x, 5}]
 ]

Mathematica graphics

$\endgroup$

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.