MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Visualizing a geometric problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113221] Re: Visualizing a geometric problem
  • From: Maxim <m.r at inbox.ru>
  • Date: Tue, 19 Oct 2010 05:56:08 -0400 (EDT)
  • References: <i9ehon$6rh$1@smc.vnet.net>

On Oct 17, 5:05 am, Velina Veleva <vvvel... at gmail.com> wrote:
> I am trying to figure out a way to move two points, X and Y,
> independently of one another along the edges of an equilateral
> triangle with vertices A, B, and C.  There are also some collision
> rules that need to be taken into account:
>
> (1)  If X is at a vertex, say vertex A, then Y cannot be on A or on
> the edges adjacent to it.  i.e., Y can only be on vertices B or C or
> the edge BC.
> (2)  If X is on an edge, say AB, then Y cannot be on A, nor B, nor any
> of the edges adjacent to A and B.  i.e., Y must be on vertex C
>
> I have figured out how to move the two points along the triangle using
> a pair of sliders, but I can't figure out how to implement the
> collision rules. I tried using the Exclusions option for Slider but
> the results are not what I expect.  I would prefer to drag the points
> along the triangle rather than using sliders, so if someone knows how
> to do that instead it would be helpful. Ideally, I would be able to
> move the two points from a vertex to either one of the edges instead
> of coming to a stop at one of them. Here is my code so far.
>
> MyTriangle[t_] :=
>  Piecewise[{{{-1, 0} + (t/100) {1, Sqrt[3]},
>     100 > t >= 0}, {{0, Sqrt[3]} + (t/100 - 1) {1, -Sqrt[3]},
>     200 > t >= 100},
>    {{1, 0} + (t/100 - 2) {-2, 0}, 300 >= t >= 0}}]
> excluded[x_] := \[Piecewise] {
>    {Range[0, 99]~Join~Range[201, 299], x == 0},
>    {Range[0, 199], x == 100},
>    {Range[101, 299], x == 200},
>    {Range[0, 199]~Join~Range[201, 299], 0 < x < 100},
>    {Range[1, 299], 100 < x < 200},
>    {Range[0, 99]~Join~Range[101, 299], 200 < x < 300}
>   }
> {Dynamic[t], Dynamic[x]}
> {Slider[Dynamic[t], {0, 299, 1}, Exclusions -> Dynamic[excluded[x]]],
>  Dynamic[t]}
> {Slider[Dynamic[x], {0, 299, 1}, Exclusions -> Dynamic[excluded[t]]],
>  Dynamic[x]}
> Dynamic[Graphics[{PointSize[Large], Point[MyTriangle[t]],
>    Point[MyTriangle[x]],
>    Line[{{-1, 0}, {1, 0}, {0, Sqrt[3]}, {-1, 0}}]},
>   PlotRange -> {{-1.2, 4.2}, {-.2, 2}}]]

Here's how you can implement the collision rules using a custom
tracking function for the control variables:

DynamicModule[
 {verts = {{-1., 0.}, {1., 0.}, {0., Sqrt[3.]}},
  sides = {{2., 0.}, {-1., Sqrt[3.]}, {-1., -Sqrt[3.]}},
  xy = {{0., 0.}, {0., Sqrt[3.]}},
  lambdas, dists, sidei, verti, i, j},
 LocatorPane[Dynamic[xy,
   Function[newxy,
    If[newxy == xy, Return[]];
    {i, j} = If[newxy[[1]] == xy[[1]], {2, 1}, {1, 2}];
    lambdas = MapThread[(newxy[[i]] - #).#2/#2.#2 &, {verts, sides}];
    lambdas = Clip[lambdas, {.025, .975}, {0., 1.}];
    dists =
     MapThread[
      Norm[newxy[[i]] - #3*#2 - #] &, {verts, sides, lambdas}];
    sidei = First@Ordering@dists;
    If[! lambdas[[sidei]] != 0. != 1.,
     verti = Mod[sidei + Boole[lambdas[[sidei]] == 1.], 3, 1];
     xy[[i]] = verts[[verti]];
     If[xy[[j]] != Sequence @@ verts[[Delete[{1, 2, 3}, verti]]],
      xy[[j]] = Mean@verts[[Delete[{1, 2, 3}, verti]]]],
     xy[[i]] = lambdas[[#]]*sides[[#]] + verts[[#]] &@sidei;
     xy[[j]] = verts[[Mod[sidei + 2, 3, 1]]];
     ]]],
  Graphics[Line@verts[[{1, 2, 3, 1}]]],
  LocatorAutoCreate -> False]]

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: Re: Mimicking the TI calculator graph "trace" function
  • Next by Date: Re: Release dates for Mathematica versions
  • Previous by thread: Visualizing a geometric problem
  • Next by thread: Generalized additive models