Re: Dynamic Text in Manipulate.
- To: mathgroup at smc.vnet.net
- Subject: [mg112037] Re: Dynamic Text in Manipulate.
- From: "David Park" <djmpark at comcast.net>
- Date: Thu, 26 Aug 2010 06:47:58 -0400 (EDT)
The code below constructs your diagram as a custom dynamic using
Presentations.
1) This uses the second argument of Dynamic to call a calcAll routine that
calculates all the secondary dynamic variables dependent on u.
2) I don't know how important it is to keep the coordinates rational, but I
stayed with that. This required the u = Rationalize[#] (instead of u= #) in
the second argument of the Dynamic Slider statement.
3) I calculate the centroid of the triangle using a Presentations routine
and then displace the vertex labels outward from the centroid. This is a
good method for placing labels on dynamic triangles.
4) There is then only one labeling routine, vertexLabel.
5) I think a Frame plot looks better than an Axes plot.
Needs["Presentations`Master`"]
DynamicModule[
{u = 0,
ptA, ptB, ptC, centroid, vertexLabel,
calcAll},
vertexLabel[name_String, pt_] :=
Module[{x = First[pt], y = Last[pt]},
Text[phrase[name, "{", x, ",", y, "}"],
pt + 0.75 Normalize[pt - centroid], {0, 0}]];
calcAll[u_] :=
(ptA = {2 - u, 8/5 - u (4/5)};
ptB = {4 - u, 11/5 - u (7/10)};
ptC = {23/5 - u, 23/5 - u (7/10)};
centroid = First@triangleCentroid[{ptA, ptB, ptC}]);
calcAll[u];
page[
{phrase["u: ",
Slider[Dynamic[u, (u = Rationalize[#]; calcAll[u]) &], {0, 2,
1/10},
Appearance -> "Labeled"]],
Draw2D[
{PointSize[0.02], Thick,
Dynamic@
{Line[{ptA, ptB, ptC, ptA}],
Point[{ptA, ptB, ptC}],
Directive[FontWeight -> Bold, FontSize -> 13, Black],
MapThread[
vertexLabel[#1, #2] &, {{"A", "B", "C"}, {ptA, ptB, ptC}}]}},
Frame -> True,
PlotRange -> {{-1.25, 6}, {-1, 6}},
PlotRangePadding -> 0.1,
GridLines -> {{0, 1, 2, 13/5, 4, 23/5}, {4/5, 8/5, 11/5, 16/5,
23/5}},
ImageSize -> 300]},
Spacings -> 1
]
]
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/
From: Matthias Bode [mailto:lvsaba at hotmail.com]
Hola:
The code below shifts a triangle with Manipulate[]. I want the coordinates
of the corners A{x;y}, B{x;y}, C{x;y} inside the {;} to change
with the shift.
Rather than my pedestrian dissecting method
Text["A {", {2 - u, 7/5 - u*(4/5)}],
Text[Dynamic[2 - u, u], {2.2 - u, 7/5 - u*(4/5)}],
Text[";", {2.32 - u, 7/5 - u*(4/5)}],
Text[Dynamic[8/5 - u*(4/5), u], {2.45 - u, 7/5 - u*(4/5)}],
Text["}", {2.6 - u, 7/5 - u*(4/5)}],
in five steps I would like to represent "A{x;y}" in ONE command Text[].
How can this be done?
Best regards,
MATTHIAS BODE
S 17.35775=B0, W 066.14577=B0
gra01 = Plot[x, {x, 0, 5}, AspectRatio -> 1,
PlotRange -> {{-0.5, 5.1}, {-0.5, 5}},
AxesLabel -> {x, y},
GridLines -> {{1, 2, 13/5, 4, 23/5}, {4/5, 8/5, 11/5, 16/5, 23/5}},
PlotStyle -> Directive[White]];
Manipulate[Show[{gra01, Graphics[{Directive[PointSize[0.02]],
Point[{{2 - u, 8/5 - u*(4/5)}, {4 - u,
11/5 - u*(7/10)}, {23/5 - u, 23/5 - u*(7/10)}}],
Directive[Thick],
Line[{{2 - u, 8/5 - u*(4/5)}, {4 - u, 11/5 - u*(7/10)},
{23/5 - u, 23/5 - u*(7/10)}, {2 - u,
8/5 - u*(4/5)}}], Directive[Dashed, Thin, Red],
Line[{{2, 8/5}, {23/5, 8/5}, {23/5, 23/5}, {2, 23/5}, {2, 8/5}}],
Line[{{4, 8/5}, {4, 11/5}}],
Line[{{23/5, 11/5}, {4, 11/5}}],
Directive[FontWeight -> Bold, FontSize -> 13, Black],
Text["A {", {2 - u, 7/5 - u*(4/5)}],
Text[Dynamic[2 - u, u], {2.2 - u, 7/5 - u*(4/5)}],
Text[";", {2.32 - u, 7/5 - u*(4/5)}],
Text[Dynamic[8/5 - u*(4/5), u], {2.45 - u, 7/5 - u*(4/5)}],
Text["}", {2.6 - u, 7/5 - u*(4/5)}],
Text["B {4; 11/5}", {4, 9/5}],
Text["C {23/5; 23/5}", {22/5, 24/5}]}]}], {u, 0, 2,
1/10}]