Message Boards Message Boards

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

Dynamic locator with a complex number

Posted 2 years ago

In the reference page for the Locator function, 2nd basic example, I found this:

DynamicModule[{p = {0.5, 0.5}}, {Graphics[Locator[Dynamic[p]], PlotRange -> 2], Dynamic[p]}]

I tried to replicate this command for complex number p, in two ways, but for no success:

DynamicModule[{p = 0.5 + I 0.5},
 {
  Graphics[{Locator[Dynamic[ReIm[p]]], Circle[]}, PlotRange -> 2]
  , Dynamic[p]}]

and

DynamicModule[{p = 
   0.5 + I 0.5}, {ComplexListPlot[{Locator[Dynamic[p]], Circle[]}, 
   PlotRange -> 2], Dynamic[p]}]

My objective is to do some complex algebra manipulations on the point p, and therefore I want to present it as a complex number in the first place. I know I can do the algebra on p[[1]] + I p[[2]] but I would like to check for the option of assigning to p a complex number.

POSTED BY: Ehud Behar
8 Replies
Posted 2 years ago

Murray Eisenberg and Rohit Namjoshi, Thanks a lot for all of your comments.

POSTED BY: Ehud Behar
Posted 2 years ago

Hi Ehud,

Do you mean something like this?

DynamicModule[{p = {0.5, 0.5}}, {Graphics[Locator[Dynamic[p]], PlotRange -> 2], 
  Dynamic[Complex[Sequence @@ p]]}]

BTW, was my answer to your earlier question helpful?

POSTED BY: Rohit Namjoshi

That's nice!

It seems to me there ought to be a built-in function, say ToComplex, that does what Complex[Sequence @@ #]& does. This would be an inverse to the built-in function ReIm.

This just seems such a basic thing to have. Something that even beginners could make sense of, as opposed to Sequence @@ p, that is, Apply[Sequence, p], which involve two non-elementary programming constructs, Apply and Sequence.

POSTED BY: Murray Eisenberg
Posted 2 years ago

I looked up the net and the documentation and couldn't find a built in function to this type of conversion. I would be glad to get to know a simple way for doing it.

POSTED BY: Ehud Behar
Posted 2 years ago

Hi Murray,

I was being dumb, easier way

Complex @@ {0.5, 0.5}
(* 0.5 + 0.5 I *)

toComplex = Complex @@ # &

toComplex[{0.5, 0.5}]
toComplex@{0.5, 0.5}
POSTED BY: Rohit Namjoshi

Perhaps better to overload like this:

toComplex[xy_] := Complex @@ xy
toComplex[x_, y_] := Complex[x, y]

Then one can do, for example, both the following...

toComplex[{3, 4}]
toComplex[3, 4]

... and get the same result.

POSTED BY: Murray Eisenberg
Posted 2 years ago

So is it correct to say that one should avoid complex numers inside Dynamic? Because that the Locator acts on a point on the canvas (which is not the nature of a complex number represented as a point)?

And yes, your answer for my previous question was great. Please forgive me for not answering or replying.

POSTED BY: Ehud Behar

Ehud, Alas, the Mathematica developers, including Stephen Wolfram, have never really come to grips with complex numbers as basic objects to use in Graphics — even though Complex is not only a built-in type and even though by default many functions assume their arguments are complex rather than real.

POSTED BY: Murray Eisenberg
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