1
$\begingroup$

I'm writing a function so that if the user clicks on a certain region, a value is returned. The function takes in a condition list like the one below and a point.

condition = {(x + .5)^2 + y^2 < 1, (x - .5)^2 + y^2 < 1};

P1 = RegionPlot[condition[[1]] && condition[[2]], {x, -2, 2}, {y, -2, 2}, 
PlotStyle -> Red];  
P2 = RegionPlot[condition[[1]] && ! condition[[2]], {x, -2, 2}, {y, -2, 2}, 
PlotStyle -> Red];  
P3 = RegionPlot[condition[[2]] && ! condition[[1]], {x, -2, 2}, {y, -2, 2}, 
PlotStyle -> Red];

I can't figure this out at all. Can someone help me?

$\endgroup$
2
  • $\begingroup$ What and what ? Clarify the problem as right now you have so much info scattered across the post with no explicit connection to it ( the problem ) $\endgroup$
    – Sektor
    Apr 25, 2015 at 14:44
  • $\begingroup$ I edited the question. Does this make more sense? $\endgroup$ Apr 25, 2015 at 15:23

2 Answers 2

1
$\begingroup$

On one level, I'm not entirely sure how you want your function to work. It's not clear where the user is to click, when the function is called, and possibly (in the solution I propose below) where the return value of the function is to be stored.

The closest thing appears to me to be a ClickPane. ClickPane calls a function when it is clicked. The function can stored the calculated value in an external variable. Code inside a Dynamic can then be updated with the new value resulting from the click. Here is a simple example. The function returns a number associated with each region P1, P2, P3; the value 0 corresponds to a click outside all regions.

P1 = ImplicitRegion[condition[[1]] && condition[[2]], {{x, -2, 2}, {y, -2, 2}}];
P2 = ImplicitRegion[condition[[1]] && ! condition[[2]], {{x, -2, 2}, {y, -2, 2}}];
P3 = ImplicitRegion[condition[[2]] && ! condition[[1]], {{x, -2, 2}, {y, -2, 2}}];
ClickPane[
 Show[BoundaryDiscretizeRegion[#, Method -> "Continuation"] & /@ {P1, P2, P3}],
 (foo = Which[
     # ∈ P1, 1,
     # ∈ P2, 2,
     # ∈ P3, 3,
     True, 0]) &
 ]
Dynamic[foo]
$\endgroup$
0
$\begingroup$
RegionPlot[{
  Mouseover[(x + .5)^2 + y^2 < 1 && (x - .5)^2 + y^2 < 1, 
   Text[Style["My first region", 16]]], 
  Mouseover[(x + .5)^2 + y^2 < 1 && ! (x - .5)^2 + y^2 < 1, 
   Text[Style["My second region", 16]]],
  Mouseover[! (x + .5)^2 + y^2 < 1 && (x - .5)^2 + y^2 < 1, 
   Text[Style["My third region", 16]]]
  },
 {x, -2, 2}, {y, -2, 2}]

or

RegionPlot[{
  Tooltip[(x + .5)^2 + y^2 < 1 && (x - .5)^2 + y^2 < 1, 
   Text[Style["My first region", 16]]], 
  Tooltip[(x + .5)^2 + y^2 < 1 && ! (x - .5)^2 + y^2 < 1, 
   Text[Style["My second region", 16]]],
  Tooltip[! (x + .5)^2 + y^2 < 1 && (x - .5)^2 + y^2 < 1, 
   Text[Style["My third region", 16]]]
  },
 {x, -2, 2}, {y, -2, 2},
 PlotStyle -> {Red, Green, Blue}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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