Message Boards Message Boards

0
|
3014 Views
|
21 Replies
|
12 Total Likes
View groups...
Share
Share this post:

Sliders expose information vertically; how to make them expose at an angle

Posted 1 year ago

I have a Manipulate in which a slider traces across the window a red hyperbola over an existing dotted hyperbola. The hyperbolas are rotated 30 degrees clockwise, but the slider gradually exposes the red hyperbola vertically. I have been trying to get the slider to sweep out the exposure of the red hyperbola at an angle parallel to the 30 degree rotated y-axis, but have not yet succeeded.

I prefer incorporating a transformation into code to rotate the slider exposure to the slant I want in order to preserve the slider. As an alternative, I suspect a 2D controller could achieve what I'm looking for. However, any idea that will expose the tracing hyperbola at an angle will be great. `


Manipulate[Module[{hyperbola, sliderHyperbola},
  hyperbola = 
   ContourPlot[{-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 
      0, y == 2/Sqrt[3] - x/Sqrt[3], 
     y == Sqrt[3] x + 8/Sqrt[3]}, {x, -14, 9}, {y, -6, 10}, 
    ContourStyle -> {
      {Directive[Black, Dotted]}, {Directive[Black, Dotted]}}];
  sliderHyperbola = 
   Plot[{-(1/Sqrt[3]) - Sqrt[3] x - Sqrt[
      1/3 + 12 x + 4 x^2], -(1/Sqrt[3]) - Sqrt[3] x + Sqrt[
      1/3 + 12 x + 4 x^2]
     }, {x, -9, y},
    PlotStyle -> {{Red, Thick}, {Red, Thick}}]; 
  Show[hyperbola, sliderHyperbola, Frame -> True, 
   ImageSize -> 20.1 16.1, AspectRatio -> Automatic, 
   PlotRange -> {{-9, 7}, {-6, 10}}]
  ], {y, -14, 8, ImageSize -> 300}, AutoAction -> True, 
 ContinuousAction -> True, SaveDefinitions -> True]
POSTED BY: William Stockich
21 Replies
Posted 1 year ago

Maybe something like this:

Manipulate[
 Show[
  {ContourPlot[{-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 
      0, y == 2/Sqrt[3] - x/Sqrt[3], 
     y == Sqrt[3] x + 8/Sqrt[3]}, {x, -14, 9}, {y, -6, 10}, 
    ContourStyle -> {{Directive[Black, Dotted]}, {Directive[Black, 
        Dotted]}}],
   ParametricPlot[(TranslationTransform[{-3/2, 7/(2 Sqrt[3])}]@*
       RotationTransform[-Pi/6])[{hyperbolaX[Sqrt[a2]][t], 
      hyperbolaY[Sqrt[a2]][t]}], {t, Pi/2 + .1, s}, 
    PlotStyle -> {Red, Thickness[.02]}]}, AspectRatio -> Automatic],
 {{s, Pi}, Pi/2 + .2, 3 Pi/2 - .1}]

Where:

aa = Sqrt[13/3];
bb = Sqrt[13/3];
hyperbolaX[a_][t_] := a Sec[t];
hyperbolaY[b_][t_] := b Tan[t];

The hyperbolaX and hyperbolaY are the parameterization functions for a hyperbola (in standard orientation). Inside the Manipulate I'm rotating and translating to bring it into alignment with your "background" hyperbola.

POSTED BY: Eric Rimbey

I'm surprised and grateful that you are so attentive to questions like mine from the community! Your previous coding has been monumental to me in advancing to my latest Manipulate, even if it is not apparent.

However, the slider in your manipulate reveals no hyperbola.

Where I'm really confused is with your definitions for aa and bb. These terms, hence their values, are not used in the manipulate program. Also, in manipulate you have an undefined a2. Shouldn't a2 have a value or range of values in manipulate?

I did replace a2 with your definitions in all the ways I could think of, and I did get the slider to trace out a left branch of an approximate hyperbola from bottom to top. What I want, however is for the slider to reveal the red hyperbola so that what is shown is always parallel to the transverse axis. I hope the two screenshots shown below for two different slider positions will show what I mean.

Is it possible to reveal the red hyperbola as the slider moves the tilted (imaginary) red line back and forth along the main axis?

If my remarks seem like criticism, please know that that any code you write personalized for me is the best learning experience I have going. I think my failing to precisely communicate what I want while trying to do it in as few words as possible is a standard in this community that I'm just starting to learn. If I'm not getting what I want, it's a fault I'll have to overcome. I benefit from all your code. To have attracted your interest is almost beyond belief.


Manipulate of slanted slider

POSTED BY: William Stockich
Posted 1 year ago

Sorry about the variables. I must have changed how I wanted to represent my solution, but didn't finish the job. But it doesn't matter, cause that's not what you wanted!

I misunderstood what you wanted, but now I think I get it. Unfortunately, I'm running out and won't have time for a few days. If you still haven't gotten what you need by next week, I'll give it another go.

POSTED BY: Eric Rimbey
Posted 1 year ago

For what it's worth, I think this is what I wanted to provide before:

aa = Sqrt[13/3];
bb = Sqrt[13/3];
hyperbolaX[a_][t_] := a Sec[t];
hyperbolaY[b_][t_] := b Tan[t];Manipulate[
 Show[{ContourPlot[{-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + 
       y^2 == 0, y == 2/Sqrt[3] - x/Sqrt[3], 
     y == Sqrt[3] x + 8/Sqrt[3]}, {x, -14, 9}, {y, -6, 10}, 
    ContourStyle -> {{Directive[Black, Dotted]}, {Directive[Black, 
        Dotted]}}], 
   ParametricPlot[(TranslationTransform[{-3/2, 7/(2 Sqrt[3])}]@*
       RotationTransform[-Pi/6])[{hyperbolaX[aa][t], 
      hyperbolaY[bb][t]}], {t, Pi/2 + .1, s}, 
    PlotStyle -> {Red, Thickness[.02]}]}, 
  AspectRatio -> Automatic], {{s, Pi}, Pi/2 + .2, 3 Pi/2 - .1}]
POSTED BY: Eric Rimbey

I doubt that anyone else will offer a solution for me. I feel unbelievably lucky that you found something in my program to devote your time and attention to it. Even if I never get any more code from you, I will remember how much I've learned from your efforts.

Anything you send my way will be more beneficial than anything I can think of because it will be customized to me - even if it has mistakes!

POSTED BY: William Stockich

OMG that is unbelievable! Your modifications provide exactly what I was looking for! Even more amazing is that you pretty much left my basic program as it was and inserted a single function you defined to accomplish the feat.

I'm glad you used pure functions. I'm sorry to say that even though I've been using Mathematica off and on for nearly 20 years, I still don't understand pure functions, and have no idea when they should be the function of choice. I know you used them because they were especially advantageous in some way. But I have no idea of the advantage you gained; all I see is confusion.

I've never learned any kind of programming except what I've learned about Mathematica through self-study. And I'm not a dedicated programmer. Rather I've tried to use Mathematica as a research and study aid, so there have been stretches of years when I've drifted away from using it.

Nevertheless, I've done countless practice examples with pure functions, but never have been able to see the light. It's always seemed as if they were like foreign words for which there was no dictionary.

Therefore, what makes your pure functions so significant is that they are cast in a programming framework I've been struggling with for quite a while. Hopefully that will make them understandable to me. Finally, I apologize for taking up your time writing so much and saying nothing to your benefit. However, if you are still with me, would you consider writing for me the code the cumbersome way I would?

I really did not think anyone would be interested in answering my question. But thanks to you, I now have exactly what I was not sure I would ever get!

William Stockich

POSTED BY: William Stockich
Posted 1 year ago

I'm not actually sure that I can do that. As far as I can tell, the RegionFunction option expects to be given something with head Function. So, I think we're going to end up with some "pure" function somewhere along the way. Sorry.

POSTED BY: Eric Rimbey
Posted 1 year ago

Your hyperbola does not depend on p, so that it is better to pre-calculate it before feeding it to Manipulate. I have rearranged things a little in a way that seems a little cleaner to me:

hyperbola = 
  ContourPlot[{-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 0,
     y == 2/Sqrt[3] - x/Sqrt[3], y == Sqrt[3] x + 8/Sqrt[3]},
   {x, -9, 7}, {y, -6, 10},
   ContourStyle -> Directive[Black, Dotted], ImageSize -> 20.1 16.1];
sliderHyperbola[p_] := 
  ContourPlot[-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 
    0, {x, -14, 9}, {y, -6, 10}, ContourStyle -> Red, 
   RegionFunction -> Function[{x, y}, y > x Sqrt[3] - p]];
Manipulate[
 Show[hyperbola, sliderHyperbola[p]],
 {p, -14, 8}]

I hope it doesn't confuse you.

POSTED BY: Updating Name

I was asking Upgrading Home to rewrite his definition using pure functions:


MyRegionFunction[p_] := #2 > #1 Sqrt[3] - p &


in the clumsy way I would try to write without pure functions a definition that would do the same thing.

Nevertheless, it is you that got me moving ahead immediately in answering my first question a couple of weeks ago. All of your coding was of the greatest enlightenment for me because it was tailored to my focus. Thanks for getting me to where I am now so quickly.

I watched the pro football players so excited with their victories, sometimes living in dreams beyond their expectations. Believe me, after struggling without success for so long, when I watched the output of your program (and Upgrading Name's) unfold, I felt pretty good myself.

POSTED BY: William Stockich
Posted 1 year ago

That post was mine (this is Eric). Sometimes this site sets the name to "Updating Name" for some reason. Must be some sort of error condition that triggers that.

Anyway, I would try to show you another way to write MyRegionFunction, but it's being used in the RegionFunction option, and that option seems to expect a Function expression, so there's no point in trying to show you a different way to do it.

Now, if your confusion is just with the # and & stuff, then another user (who's name I don't know because for me it's just showing as "Updating Name") wrote it this way: RegionFunction -> Function[{x, y}, y > x Sqrt[3] - p]]

If that's what you're asking for, then there you have it with thanks to that mystery, anonymous user.

POSTED BY: Eric Rimbey

Appreciate your quick response. Unfortunately, I'm only getting pink output. It seems the two plots won't combine. If you paste back from the browser do you get a working output?

Above, in my response to Eric Rimbey, I referred to you as "Upgrading Home"! How bad is that? I got your first name and last name wrong! My humble apologies.

POSTED BY: William Stockich

I get the output as expected, no errors, in both versions 12.0 and 13.2. What version are you using? Try with a fresh kernel.

I wonder why you set ImageSize -> 20.1 16.1, which seems bizarre to me. Did you mean to give separate width and height? That is done with ImageSize -> {20.1, 16.1}.

Don't worry about the name.

POSTED BY: Gianluca Gorni

I intended the ratio to be 16 by 16. But I'm also using diagonal gridlines which I left out of the programs I sent in order to simplify them. When the gridlines were in, even with Frame -> True, the right edge of the frame did not appear. As for the 16.1, I was confused. I thought I was making the frame wider but but the right edge was not appearing. Eventually I realized my mistake and changed 20 to 20.1, which allowed the right edge to show up. I forgot to change 16.1 back to 16.
As for what is wrong here, so far I've repasted it, but without success. I will keep testing. I'm using windows 10 from 2019 and I installed V13.2 when it came out.

All I can say is that your assistance is super remakable. I consider myself very lucky.

POSTED BY: William Stockich

ImageSize specifies the size in printer points. Your 16 by 16 is very very small. The picture becomes visible because you wrote 20.1 16.1, which is interpreted as a multiplication.

I have no idea why you cannot reproduce the Manipulate.

POSTED BY: Gianluca Gorni

Yes, when I quit the kernel the Manipulate worked. As for the Image function, I wasn't thinking clearly when I tried to answer the question. I had Image calling for a 320x320 square, but when I wanted to center the hyperbola with the right amount showing, I used PlotRange.

Thank you for your interest and observations.

POSTED BY: William Stockich
Posted 1 year ago

You might try RegionFunction. Let's create a function to use:

MyRegionFunction[p_] := #2 > #1 Sqrt[3] - p &

Here's an updated version of your Manipulate. I removed some options and removed a stray ImageSize option, so you might need to put some things back in. The important change is with how sliderHyperbola is defined. There might be a more performant way to do this, but this at least gets you the functionality you want (I think :) ).

Manipulate[
 Module[
  {hyperbola, sliderHyperbola},
  hyperbola =
   ContourPlot[
    {-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 0,
     y == 2/Sqrt[3] - x/Sqrt[3],
     y == Sqrt[3] x + 8/Sqrt[3]},
    {x, -14, 9}, {y, -6, 10}, 
    ContourStyle -> {{Directive[Black, Dotted]}, {Directive[Black, 
        Dotted]}}];
  sliderHyperbola =
   ContourPlot[
    -10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 0,
    {x, -14, 9}, {y, -6, 10},
    ContourStyle -> Directive[Red],
    RegionFunction -> MyRegionFunction[p]];
  Show[
   hyperbola,
   sliderHyperbola,
   Frame -> True,
   ImageSize -> 20.1 16.1,
   AspectRatio -> Automatic, PlotRange -> {{-9, 7}, {-6, 10}}]],
 {p, -14, 8}]
POSTED BY: Eric Rimbey

Eric, your latest is just fantastic! I was feeling that I was wearing you out and should give you a rest. In what you already provided, there is much I don't understand. So I figured I should be analyzing and understanding what I've gotten before I pester you further with more questions.

But you surprised me by creating even more code tailored to my interests. I've never had any experience with Mathematica as enjoyable and satisfying as I've had getting these coding efforts from you. I don't want to forget contribution from Anonymous either, with those pure functions. Even though you've shown me the longhand form, my substitutions to longhand still fail. Whenever I see a #, I feel defeat with everything that follows. I feel so dumb dealing with those #s for 20 yrs and still not getting what they do.

One thing I've come to wish I also had in the Manipulate is that the slanting red line that I drew in the two screenshots I posted actually existed. I drew that red line to show how it revealed the red hyperbola symmetrically about the main axis. Presently, when the slider is moving between the two vertices of the hyperbola, nothing is visually happening in the Manipulate window. I think it would be neat to see it moving between the vertices.

Inclusion of the line is just a wishful dream, however, and even mentioning it is selfish. In mentioning it I feel I'm asking too much of your generosity - not a good thing to say about myself. You have already provided me with more than I ever imagined. Thank you for all your time, effort, and interest. There are really no words that seem adequate.

POSTED BY: William Stockich
Posted 1 year ago

I actually didn't post anything new recently. I don't know why it says I did. But anyway, it's easy to add a line. Starting with Gianluca's version, just add a graphics element with an InfiniteLine:

hyperbola = 
  ContourPlot[{-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 0,
     y == 2/Sqrt[3] - x/Sqrt[3], y == Sqrt[3] x + 8/Sqrt[3]}, {x, -9, 
    7}, {y, -6, 10}, ContourStyle -> Directive[Black, Dotted], 
   ImageSize -> 20.1 16.1];
sliderHyperbola[p_] := 
  ContourPlot[-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 
    0, {x, -14, 9}, {y, -6, 10}, ContourStyle -> Red, 
   RegionFunction -> Function[{x, y}, y > x Sqrt[3] - p]];
Manipulate[
 Show[hyperbola, sliderHyperbola[p], 
  Graphics[{Blue, InfiniteLine[{0, -p}, {1, Sqrt[3]}]}]], {p, -14, 8}]

Just style it however you want.

POSTED BY: Eric Rimbey

If there were ever such a thing as a Mathematica "high," I'm in one today, thanks to you, Eric. It was just before Christmas when I had my doubts that it was even possible to get a line to move parallel to itself.

As for your last program with the infinite line, I kept getting an error on execution, even after quitting the kernel. This was the same error I was getting yesterday. I did not have the success reported by Gianluca Gorni.

Eventually it occurred to me that the defined variables were not enclosed in Module. Therefore, I took your new code for the infinite line, and put it in the program that had the Module. I'm writing a paper and I wanted to use this Manipulate to illustrate it. Without your help I never would have developed the Manipulate. About all I did was furnish the idea.

Thank you for bringing into existence what I could only imagine. Here is how I put the variables inside Module:


Manipulate[
 Module[{hyperbola, sliderHyperbola, sliderLine}, 
  hyperbola = 
   ContourPlot[{-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 
      0, y == 2/Sqrt[3] - x/Sqrt[3], 
     y == Sqrt[3] x + 8/Sqrt[3]}, {x, -14, 9}, {y, -6, 10}, 
    ContourStyle -> {{Directive[Black, Dotted]}}]; 
  sliderHyperbola = 
   ContourPlot[-10 x - x^2 + (2 y)/Sqrt[3] + 2 Sqrt[3] x y + y^2 == 
     0, {x, -14, 9}, {y, -6, 10}, ContourStyle -> Directive[Red], 
    RegionFunction -> MyRegionFunction[p]];
  sliderLine = Graphics[{Blue, InfiniteLine[{0, -p}, {1, Sqrt[3]}]}];
  Show[hyperbola, sliderHyperbola, sliderLine, Frame -> True, 
   ImageSize -> 400.1, AspectRatio -> Automatic, 
   PlotRange -> {{-9.5, 6.5}, {-6, 10}}]], {p, -28, 19, 0.025}, 
 ContinuousAction -> True]

POSTED BY: William Stockich
Posted 1 year ago

Hmm. That's weird. Maybe different version behave differently. I'm using 13.2. Anyway, glad you got something working!

POSTED BY: Eric Rimbey

I'm using 13.2 also. I imagine that you, as an advanced programmer, have been able to size up my situation so well that you can just edit one version and not have any conflicts

I have multiple versions of the Manipulates you and others have posted for me, and I think in storage I somehow make the same words have different definitions. I think that's why I get failures. That's why I use Module, correctly or incorrectly.

POSTED BY: William Stockich
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