1
$\begingroup$

On my Windows 10 machine, Manipulate with TriangleMeasurement locks up once I start changing the sliders. Even with SynchronousUpdating -> False and ContinuousAction -> False it still locks up. Code below draws a triangle and then uses TriangleMeasurement to compute the area. It locks up after several movements of sliders. I wonder if someone could confirm this is reproducible or perhaps I'm not setting up Manipulate correctly.

Manipulate[
  a = {1, 4};
  b = {1, s2};
  c = {u2, v2};
  o = {0, 0};
  myTriangle = {EdgeForm[Black], FaceForm[], Triangle@{a, b, c}};
  cobArea = TriangleMeasurement[{a, o, c}, "Area"];
  Show[
    Graphics @ 
      {myTriangle, Line @ {o, c}, Line @ {o, b}, Line @ {o, a}}, 
      Axes -> True, PlotRange -> 5], 
  {{v2, -1}, -0.1, -5}, 
  {{s2, -1}, -0.1, -5}, 
  {{u2, -1}, -0.3, -5}, 
  TrackedSymbols :> True, 
  SynchronousUpdating -> False, 
  ContinuousAction -> False]
$\endgroup$
  • $\begingroup$ What happens when you use := ? $\endgroup$ – CA Trevillian Dec 19 '19 at 16:40
  • $\begingroup$ The :=TriangleMeasurement is working. Would you know why I have to use the delay assignment here? $\endgroup$ – Dominic Dec 19 '19 at 17:19
  • $\begingroup$ I don't think this has anything to do with the delayed assignment. The reason the Manipulate is working when you use cobArea := is because that value is never used, so the calculation involving TriangleMeasurement is never actually carried out. Instead, I think this might be related to the fact that, for some values of your parameters, your three points become collinear. This might make the EXPERIMENTAL TriangleMeasurement function misbehave. Consider for instance: u2 = -1.2 and v2 = -4.8. $\endgroup$ – MarcoB Dec 19 '19 at 17:38
  • $\begingroup$ Yes. It does indeed fail when I use the value of cobArea with the statement text1=Text[cobArea,{-4,5}] and then use it in the Graphics statement. $\endgroup$ – Dominic Dec 19 '19 at 17:52
  • $\begingroup$ I should point out it fails even when the points are not colinear as the application I'm actually trying to use it prevents the points from being so and therefore no values of the controls make them colinear. $\endgroup$ – Dominic Dec 19 '19 at 18:04
1
$\begingroup$

b,c,o must depend on the Manipulate- parameters!

Try (now with Module, changed Manipulate parameter range and changed PlotRange)

Module[
{a, b, c, o, myTriangle, cobArea},
a = {1, 4};
b[v2_, s2_, u2_] := {1, s2};
c[v2_, s2_, u2_] := {u2, v2};
o[v2_, s2_, u2_] := {0, 0};
Manipulate[
myTriangle = {EdgeForm[Black], FaceForm[],Triangle@{a, b[v2, s2, u2],c[v2, s2, u2]}};
cobArea =TriangleMeasurement[{a, o[v2, s2, u2], c[v2, s2, u2]}, "Area"];
Show[Graphics@{myTriangle, Line@{o[v2, s2, u2], c[v2, s2, u2]},Line@{o[v2, s2, u2], b[v2, s2, u2]}, Line@{o[v2, s2, u2], a}}, Axes -> True,PlotRange ->All], {{v2, -1}, -0.1, -5}, {{s2, -1}, -0.1, -5}, {{u2, -1}, -0.3,  -5}, TrackedSymbols :> True, SynchronousUpdating -> False,ContinuousAction -> False]
]

The options TrackedSymbols\[RuleDelayed]True,SynchronousUpdating\[Rule]False,\ContinuousAction\[Rule]False aren't necessary anymore.

| improve this answer | |
$\endgroup$
  • $\begingroup$ That code seems to lock up as well. I copied it into a new session in a blank notebook. I did have to edit it slightly a backslash was inserted into the copy but it still didn't work. $\endgroup$ – Dominic Dec 19 '19 at 18:48
  • $\begingroup$ @Dominic Strange! I modified my answer, now it runs on v12! $\endgroup$ – Ulrich Neumann Dec 19 '19 at 19:57
  • $\begingroup$ That does seem to work Ulrich. Thanks for looking at this. It is a bit much though to need to enclose the Manipulate in a Module that way and add the extra code you added, unlike anything I've ever done in the past. $\endgroup$ – Dominic Dec 19 '19 at 20:24
  • $\begingroup$ @Dominic The main problem seem to be the parameters myTriangle, cobArea which are redefined in every step Manipulate is called(code without Module) . That's why Module or DynamicModule are advisable. $\endgroup$ – Ulrich Neumann Dec 20 '19 at 8:39
1
$\begingroup$

I'm using V11.3, so I don't have TriangleMeasurement, which arrived in V12. However, the following code works well on V11.3 and I don't see why it wouldn't work just as well on V12.

With[{o = {0, 0}, a = {1, 4}},
  Manipulate[
    b = {1, s2};
    c = {u2, v2};
    Dynamic @
      Column[
        {Graphics[
           {{EdgeForm[Black], FaceForm[], Triangle @ {a, b, c}},
            Line /@ {{o, c}, {o, b}, {o, a}},,
            Text["a", Offset[{2, 4}, a]],
            Text["b", Offset[{5, 0}, b]],
            Text["c", Offset[{-5, 0}, c]]},
           Axes -> True, PlotRange -> 5, ImageSize -> Medium],
         Row[{"Area = ", Area[Triangle @ {a, b, c}]}]}],
    {{u2, -1}, -0.3, -5, 0.1, Appearance -> "Labeled"},
    {{v2, -1}, -0.1, -5, 0.1, Appearance -> "Labeled"},
    {{s2, -1}, -0.1, -5, 0.1, Appearance -> "Labeled"},
    TrackedSymbols :> {v2, s2, u2}]]

demo

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.