# Can we use the values of a dynamic variable (by a click) in further calc. ?

Posted 10 years ago
1875 Views
|
2 Replies
|
3 Total Likes
|
 "Can we use the values of a dynamic variable (obtained by a mouse click) in further calculation?"The following module displays the position of point A and displays their numerical values. However, we wish to judge if they are inside a unit circle by calsulating x^2 + y^2 - 1. However, this displays for A=(0.5,0.3) simply 0.5^2 + 0.3^2 - 1 rather than -0.66. Any suggestion is welcome? (We have to solve a similar but more complicated, and this is a simplified version. )DynamicModule[{A = {0, 0}}, {ClickPane[   Dynamic@Show[Graphics[Circle[]],      Graphics[Line[{{-1.1, 0}, {1.1, 0}}]],      Graphics[Point[A]]], (A = #) &], Dynamic[A]}]
2 Replies
Sort By:
Posted 10 years ago
 Thank you for a quick and helpful suggestions.Your method, putting x^2 + ^y2 -1in dynamic[] works in our routine to solve our real problem.However, in our problem, this method, keepingthe dynamic property of x and y is not necessaryand it seems introducing complication.It is indeed nice that the values always respond the mouse position,but for us it is not nessary.We wish strongly to work 'outside the module' rather thanstaying inside the module after selecting the coordinates of pointsby the mouse click measurement.In the subsequent procedure, the dynamic propertyis no longer necessary. We only wish to use the obtained valuesjust as usual static variables.How could we 'UNWRAP' the dynamic property ?
Posted 10 years ago
 You don't have to do it this way, but I find it more readable to use individual variables for the x and y coordinates:DynamicModule[{x = 0,   y = 0},     {ClickPane[        Dynamic@Show[Graphics[Circle[]],Graphics[Line[{{-1.1, 0}, {1.1, 0}}]], Graphics[Point[{x, y}]]],         ({x, y} := #) &],     Dynamic[x^2 + y^2 - 1]}]