I need to visualize Menelaus' theorem for a triangle with moving locators for each of six points. So the vertexes of the triangle can move in any possible way, and the three points on the sides of the triangle can not - they should be fixed on the side.
I've tried manipulating stuff, but I cant merge the Manipulate
with
Locator[Dynamic[pa1, (pa1 = ToTheLine[#, pb, pc]) &]]
So I've come to this:
ToTheLine[p_, lb_, le_] :=
{
p[[1]],
If[le[[1]] == lb[[1]],
p[[2]],
lb[[2]] - (lb[[1]] - p[[1]])*(le[[2]] - lb[[2]])/(le[[1]] - lb[[1]])]
}
DynamicModule[{
pa = {-5, 0}, pb = {5, 0}, pc = {0, 10},
pa1 = (pb + pc)/2, pb1 = (pa + pc)/2, pc1 = (pb + pa)/2},
(* point pa1 is labeled as D and is on side BC of the triangle,
similar definition for the others *)
Graphics[{
Locator[Dynamic[pa]], (* point A *)
Locator[Dynamic[pb]], (* point B *)
Locator[Dynamic[pc]], (* point C *)
Locator[Dynamic[pa1, (pa1 = ToTheLine [#, pb, pc]) &]],
Locator[Dynamic[pb1, (pb1 = ToTheLine [#, pc, pa]) &]],
Locator[Dynamic[pc1, (pc1 = ToTheLine [#, pb, pa]) &]],
Text[Style["A", 20, "Label"], Dynamic[pa + {0, 1}]],
Text[Style["B", 20, "Label"], Dynamic[pb + {0, 1}]],
Text[Style["C", 20, "Label"], Dynamic[pc + {0, 1}]],
Text[Style["D", 10, "Label"], Dynamic[pa1 + {0, 1}]],
Text[Style["E", 10, "Label"], Dynamic[pb1 + {0, 1}]],
Text[Style["F", 10, "Label"], Dynamic[pc1 + {0, 1}]],
Thick, Red,
Line [{Dynamic[pa], Dynamic[pb], Dynamic[pc], Dynamic[pa]}],
Thin, Black,
Line [{Dynamic[pa], Dynamic[pc1]}],
Line [{Dynamic[pb], Dynamic[pa1]}],
Line [{Dynamic[pc], Dynamic[pb1]}],
Line [{Dynamic[pa1], Dynamic[pb1]}],
Line [{Dynamic[pb1], Dynamic[pc1]}]},
PlotRange -> 20.
Axes -> True.
ImageSize -> 600]]
The function ToTheLine
just gets locator coords and puts the points on a line defined by two other points.
When I drag a point on the side and then drag vertex, the point doesnt stay on side anymore. I tried Locator[Dynamic[pc1, (pc1 = ToTheLine [#, Dynamic[pb], Dynamic[pa]]) &]]
, which uses correct coords for A and B, but there is some error there.
How can I solve this problem? Is there a far more elegant solution?