Mathematica Asked by user76275 on February 7, 2021
I am trying to have a locator move along a manipulated line but every time I manipulate the variables the locator doesn’t move across the new line. How can I get the locator to move across the line even after I manipulate it? Also when I try to move the manipulator it just goes to the bottom of the graph and doesn’t work. I’m not really sure how tracking function is supposed to work so I know that’s why that part doesn’t work.
Here is my code:
Manipulate[
Plot[
1/(4 f) (x - h)^2 + k,
{x, -16, 16},
PlotRange -> {{-16, 16}, {-16, 16}},
AspectRatio -> 1/1,
Epilog ->
{
PointSize[.02],
Line[{{h, k + f}, {z, 1/(4 f) (z - h)^2 + k}, {z, k - f}}],
Point[{{h, k + f}, {z, 1/(4 f) (z - h)^2 + k}, {z, k - f}}],
Dashed, InfiniteLine[{h, k - f}, {1, 0}]
}
],
{{p, {z, 1/(4 f) (z - h)^2 + k}}, Locator,
TrackingFunction -> (p = {First@#,
1/(4 f) (z - h)^2 + k@First@#}; &)},
{{z, 0}, h - 16, h + 16},
{{f, 1/4}, -8, 8},
{{h, 0}, -16, 16},
{{k, 0}, -16, 16}
]
I assume the locator coincides with the middle point of the lines and it stays on the curve. Since p
depends on other controls, we need to use TrackingFunction
in all controls to update p
:
f0[x_, f_, h_, k_] := 1/(4 f) (x - h)^2 + k
Manipulate[Plot[f0[x, f, h, k], {x, -16, 16},
PlotRange -> {{-16, 16}, {-16, 16}}, AspectRatio -> 1/1,
Epilog -> {PointSize[.02], Thick, Line[{{h, k + f}, p, {z, k - f}}],
Point[{{h, k + f}, p, {z, k - f}}], Dashed, Gray,
InfiniteLine[{h, k - f}, {1, 0}]}],
{{p, {z, 1/(4 f) (z - h)^2 + k}}, Locator,
TrackingFunction -> (p = {First@#, f0[First@#, f, h, k]}; &)},
{{z, 0}, h - 16, h + 16, TrackingFunction -> (p = {#, f0[#, f, h, k]};
z = #; &)},
{{f, 1/4}, -8, 8, TrackingFunction -> (p = {First@p, f0[First@p, #, h, k]};
f = #; &)},
{{h, 0}, -16, 16, TrackingFunction -> (p = {First@p, f0[First@p, f, #, k]};
h = #; &)},
{{k, 0}, -16, 16, TrackingFunction -> (p = {First@p, f0[First@p, f, h, #]};
k = #; &)}]
Answered by kglr on February 7, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP