Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.7K 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 2 years 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 2 years 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
Posted 2 years 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 2 years 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
Posted 2 years 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
Posted 2 years 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

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
POSTED BY: Gianluca Gorni
Posted 2 years 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
Posted 2 years 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

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
Posted 2 years 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

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

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

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
Posted 2 years 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

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

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

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
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