# DynamicModule with constant image size

I am new to this forum - I wonder if someone can help me improve this code.

1. I would like the angle $\theta$ to start in the middle of the slider i.e. $\theta = 0$ instead of starting at $\theta = -90$.

2. How do I keep the circle size constant as I slide the $\theta$?

Mohr[σxx_, σyy_, τxy_] :=
DynamicModule[{g1, g2, g3}, OC = 1/2*(σxx + σyy);
R = Sqrt[((σxx - σyy)/2)^2 + τxy^2] ;
g1 = {Thickness[0.01], Circle[{OC, 0}, R]}; σxx1 :=
1/2*(σxx + σyy) + 1/2*(σxx - σyy)*Cos[2*θ*Degree] + τxy*
Sin[2*\[Theta]*Degree];
σyy1 := 1/2*(σxx + σyy) + 1/2*(σyy - σxx)*Cos[2*θ*Degree] - τxy*Sin[2*θ*Degree];
τxy1 := 1/2*(σyy - σxx)*Sin[2*θ*Degree] + τxy*Cos[2*θ*Degree];
τxy1a := 1/2*(σyy - σxx)*Sin[(2*θ*Degree + π)] + τxy*Cos[(2*θ*Degree + π)];
pts = {{σxx1, -τxy1}, {σyy1, -τxy1a}};
g2 = {PointSize[0.05], Red, Point[pts] ,
Inset[Row[{"\!$$\*SubscriptBox[\(σ$$, $$xx$$]\) = ", NumberForm[σxx1, {6, 2}], ";",
"  \!$$\*SubscriptBox[\(τ$$, $$xy$$]\) = ", NumberForm[-τxy1, {6, 2}]}],
Dynamic[{pts[[1, 1]], pts[[1, 2]]}]],
Inset[
Row[{"\!$$\*SubscriptBox[\(σ$$, $$yy$$]\) = ", NumberForm[σyy1, {6, 2}], ";",
"  \!$$\*SubscriptBox[\(τ$$, $$xy$$]\) = ", NumberForm[-τxy1a, {6, 2}]}],
Dynamic[{pts[[2, 1]], pts[[2, 2]]}]]
}  ;
g3 = {Thickness[0.01], Blue, Line[pts]};
{Column[{Graphics[{g1, Dynamic[g2], Dynamic[g3],
Inset[Text[Style["Mohr's circle", 18, Purple, Italic]], {49.58, 68.99}]},
ImageSize -> 300 ],
Row[{"θ = " Slider[Dynamic[θ], {-90, 90}], Dynamic@θ " degree"}]}]}]

Mohr[100, 0, 25]


Edit

barebones version

Mohr[x_, R_] :=
DynamicModule[{g1, g2},
g1 = Circle[{x, 0}, R];
pts = Dynamic @{{R Cos@t + x, R Sin@t}, {R Cos[t + Pi] + x, R Sin[t + Pi]}};
g2 = {PointSize[0.05], Red, Point[Dynamic@pts],
Inset["A very long text", Dynamic@(pts[[1, 1]])]};
{Column[{Graphics[{g1, Dynamic[g2]}, Axes -> True],
Row[{"t = " Slider[Dynamic[t], {-Pi/2, Pi/2}], Dynamic@t }]}]}]

Mohr[100, 25]

• Did you write this code? Jul 14, 2012 at 17:21
• Please reduce your code sample the the minimum where your questions are meaningful and useful for others Jul 14, 2012 at 18:56
• @RChai, welcome to the site! We will do our best to help you out learn this great language! As to your first question, give it a shot by looking up Slider in the documentation. Let us know if you get stuck
– Rojo
Jul 14, 2012 at 23:24
• @RChai let me second Rojo's welcome, and suggest that you register your account. That way, any upvotes from your future questions and answers will be added to the one you have from this question. Jul 15, 2012 at 3:19

Adding ImagePadding and ImageSize options and a few changes in the barebones version of your code:

Mohr2[x_, R_] := DynamicModule[{g1, g2, pts}, g1 = Circle[{x, 0}, R];
t = 0;
pts = Dynamic@{{R Cos@t + x, R Sin@t}, {R Cos[t + Pi] + x, R Sin[t + Pi]}};
g2 = {PointSize[0.05], Red, Point[Dynamic@pts], Line[Dynamic@pts],
Inset["A very long text", Dynamic@(pts[[1, 1]])]};
Column[{Graphics[{g1, Dynamic@g2}, Axes -> True, ImagePadding -> 30,
ImageMargins -> 0, ImageSize -> 300],
Row[{"t = " Slider[Dynamic[t], {-Pi, Pi}], Dynamic@t}]},
Alignment -> Center]]

Mohr2[200, 15]


gives