Message Boards Message Boards

0
|
2024 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

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

Posted 11 years ago
"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]}]
POSTED BY: Keita Sumiya
2 Replies
Posted 11 years ago
Thank you for a quick and helpful suggestions.
Your method, putting x^2 + ^y2 -1
in dynamic[] works in our routine to solve our real problem.

However, in our problem, this method, keeping
the dynamic property of x and y is not necessary
and 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 than
staying inside the module after selecting the coordinates of points
by the mouse click measurement.
In the subsequent procedure, the dynamic property
is no longer necessary. We only wish to use the obtained values
just as usual static variables.
How could we 'UNWRAP' the dynamic property ?
POSTED BY: Keita Sumiya
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]}
]
POSTED BY: Sean Clarke
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