2
$\begingroup$

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} ] 
$\endgroup$
0

1 Answer 1

3
$\begingroup$

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 = #; &)}] 

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you that's really helpful! Would there be a way to have the z slider move as you move the locator so that the line going from the dotted line to the locator stays verticle? $\endgroup$ Commented Dec 15, 2020 at 14:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.