Message Boards Message Boards

0
|
1919 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Moving a line parallel to itself in Manipulate

Posted 1 year ago

I want to do a geometrical manipulation in Graphics that requires moving a line segment in any direction, but always parallel to its original position. To control the movement of the line in the plane I would like to be able to attach something like a Locator to the line.

So far, in Mathematica, it seems like all movement functions are based on a point, or rotation about a point. Essentially, I want to do a dynamic translation rather than a rotation. I'm trying connect the Line function to the Locator function at present, but so far have not succeeded.

POSTED BY: William Stockich
6 Replies

Hi Eric,

You may have given me what I want, but I won't be able to understand how you did it without learning to understand how the whole program works. You've used some functions I didn't even know existed, and you've used the trig functions, for instance, in ways I've never seen.

You've given me an extremely useful program to study, so I will now take some time to see how far I can get with it on my own. If something comes up that puzzles me, I'll attach another question to these, if that's possible. It may be more than a week and possibly much longer.

I feel like I've had the amazing good fortune to receive from you far better help than I expected. I can imagine you being like a musician, who, when given the name of a tune, can knock out a virtuoso performance every time. Thank you for giving me your time and the benefit of your high-quality knowledge.

William Stockich

POSTED BY: William Stockich
Posted 1 year ago

However, if you are able to pass along that result

I'm sorry, but don't understand what you're asking for. Your refactored code seems to do exactly what you've described--well done!

The only thing I can think that you might be asking for is to allow one to arbitrarily define the horizontal constraining line instead of hard-coding it. Maybe something like this (I've changed some of the parameters just because I liked the look better):

Manipulate[
 Graphics[
  {Darker@Green, Line[{{-constraint, 0}, {constraint, 0}}],
   GrayLevel[.5], Line[{-.5 length {Cos@angle, Sin@angle}, .5 length {Cos@angle, Sin@angle}}],
   Black, PointSize[.02], Point[{0, 0}],
   Blue, TranslationTransform[p][Line[{-.5 length {Cos@angle, Sin@angle}, .5 length {Cos@angle, Sin@angle}}]]},
  PlotRange -> {{-10, 10}, {-10, 10}},
  AspectRatio -> 1,
  Frame -> True],
 {{constraint, 5}, 0, 10},
 {{p, {0, 0}}, {-constraint, 0}, {constraint, 0}, Locator},
 {{angle, Pi/4}, 0, Pi},
 {{length, 10}, 1, 20}]
POSTED BY: Eric Rimbey

Hi Eric,

Again you've done exactly what I wanted. Regarding the horizontal line I mentioned, I inserted a line in your Manipulate that visually gives what I am seeking. The imitation of my code for the line is that the Locator is not really constrained to the horizontal line.

Manipulate[Graphics[{GrayLevel[.5], Line[{{-5, 0}, {5, 0}}], Line[{-.5 length {Cos@angle, Sin@angle}, .5 length {Cos@angle, Sin@angle}}], Black, Point[{0, 0}], Blue, TranslationTransform[p][ Line[{-.5 length {Cos@angle, Sin@angle}, .5 length {Cos@angle, Sin@angle}}]]}, PlotRange -> 10], {{p, {0, 0}}, {-5, 0}, {5, 0}, Locator}, {{angle, Pi/4}, 0, Pi}, {{length, 3}, 1, 5}]

I expect that I will eventually figure out how to make the Locater slide under constraint. However, if you are able to pass along that result, I would be most grateful.

I must admit that I barely understand the program you have written for me, but it is perfect to study because it does not include anything of unimportance that could be distracting. You have helped me avoid perhaps many weeks of perplexity. I compliment you on your programming skill and your willingness to share it. Thank you too, but saying so seems hardly adequate.

William Stockich

By the way, my goal is to illustrate a research paper. It is from Descartes' Geometry, 1637, and this geometric construction is an example of the very first treatment of a 2nd degree equation in analytic geometry in revolutionary notation which is used to this day.

While Descartes' math appears to be modern, his way of explaining it is so convoluted that in the nearly 400 hundred years since, very little has published attempting to explain what he was doing. It's not complicated but I'm guessing that any explanatory study has been too time-consuming to be worth the effort.

POSTED BY: William Stockich
Posted 1 year ago

I'm not entirely sure I understand, but see if this is what you're looking for:

Manipulate[
 Graphics[
  {GrayLevel[.5], 
   Line[{-.5 length {Cos@angle, Sin@angle}, .5 length {Cos@angle, 
       Sin@angle}}],
   Black, Point[{0, 0}],
   Blue, 
   TranslationTransform[p][
    Line[{-.5 length {Cos@angle, Sin@angle}, .5 length {Cos@angle, 
        Sin@angle}}]]},
  PlotRange -> 10],
 {{p, {0, 0}}, {-5, 0}, {5, 0}, Locator},
 {{angle, Pi/4}, 0, Pi},
 {{length, 3}, 1, 5}]

This is almost identical to the previous, but we've constrained the locator, and you can see the difference where we specify the Locator control:

{{p, {0, 0}}, {-5, 0}, {5, 0}, Locator}
POSTED BY: Eric Rimbey

Hi Eric,

That's exactly what I wanted. In fact it's incredible! Given the time of year, I'll think of it as a great present! Perhaps with your skill, you can answer the remaining part of the line translation puzzle I did not ask about.

Is it possible for you to write code that would allow attaching the Locator to say, another fixed horizontal line, so that I could slide the Locator (with its fixed oblique line) left and right along the horizontal line? This is my ultimate goal.

I don't yet know how to code very well with the Locator function. Your program offers a helpful study. Thank you for your excellent and rapid reply.

William Stockich

POSTED BY: William Stockich
Posted 1 year ago

Maybe something like this:

Manipulate[
 Graphics[
  {GrayLevel[.5], 
   Line[{-.5 length {Cos@angle, Sin@angle}, .5 length {Cos@angle, 
       Sin@angle}}],
   Black, Point[{0, 0}],
   Blue, 
   TranslationTransform[p][
    Line[{-.5 length {Cos@angle, Sin@angle}, .5 length {Cos@angle, 
        Sin@angle}}]]}, PlotRange -> 10],
 {{p, {0, 0}}, Locator},
 {{angle, Pi/4}, 0, Pi},
 {{length, 3}, 1, 5}]
POSTED BY: Eric Rimbey
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