Message Boards Message Boards

0
|
5674 Views
|
8 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to obtain points of a graphic, in a dynamic way

Posted 9 years ago

Hello everyone,

My doubt is the next: I would like to obtain points of a graphic placing the mouse in the graphic's points. For example, if the graphic is y=2*x, sitting the mouse in the coordinate x=1, in the graphic, obtain in other variable y=2, to show it and use this result later.

Thank you very much for your time.

POSTED BY: Daniel G
8 Replies

This was the simplest solution that struck me. You might be able to make it work without clicking, but you'd be unable to copy the resulting number, for example. Investigate the options in the manipulate and locator documentation.

POSTED BY: David Gathercole
Posted 9 years ago

Thank you David for your response. In the code, there´s a part I don´t understand (for my ignorance). Why in these lines "Graphics[Line[{{p[[1]], -100}, {p[[1]], 100}}]]]" and "Dynamic[function[coordinate[[1]]]]" is the number one inside p[1] and coordinate[[1]]? For example, why not p[2] and coordinate [[2]], or simply p[ ] and coordinate[[ ]]?

POSTED BY: Daniel G

The variable p is a length 2 array containing the x and y coordinates of the point you clicked on. The 1s here specify taking the first element, and thus the x coordinate.

If you remove the Appearance -> None code, you can see the locator, providing an extra dimension of input that we are not making use of.

POSTED BY: David Gathercole
Posted 9 years ago

Okey, now I understand it.

Thank you very much David.

POSTED BY: Daniel G
Posted 9 years ago

Thank you for your response.

Could be possible that the locator, being visible, follows the function's direction? And are there any possibility that all occurs placing the mouse only, without click?

POSTED BY: Daniel G

You could use Locator controls in a Manipulate to do this.

For example:

function = Sin;

Manipulate[
 coordinate = p;
 Show[
  Plot[function[x], {x, 0, 2 Pi}],
  Graphics[Line[{{p[[1]], -100}, {p[[1]], 100}}]]
  ]
 , {{p, {3 Pi/4, 0}}, Locator, Appearance -> None}]

Dynamic[function[coordinate[[1]]]]

example

POSTED BY: David Gathercole
Posted 9 years ago
Dynamic[{coordinate[[1]], function[coordinate[[1]]]}]

to get x coordinate, too

POSTED BY: Okkes Dulgerci
Posted 9 years ago

Thank you Okkes.

POSTED BY: Daniel G
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