0
$\begingroup$

I am trying to generate two lines (with 2 points each) that are dynamically updated with a plot as background. I have come quite far, but do not manage to add the plot as background.

    initialLocations={{-5, 5}, {-1, 3},{-5,-1},{5,6}}

    DynamicModule[
    {p1=initialLocations[[1]],
    p2=initialLocations[[2]],
    p3=initialLocations[[3]],
    p4=initialLocations[[4]]},
    {
    LocatorPane[Dynamic[{p1,p2,p3,p4}],
    Dynamic[
    Graphics[{
    Red,Line[{p1,p2}],
    Blue,Line[{p3,p4}]},
    PlotRange->10,Axes->True,ImageSize->Medium]],
     Dynamic[{p1,p2,p3,p4}]
    }
                 ]

I would like to add a plot as background, such as:

Plot[Sin[x],{x,0,10}]

I tried to pack everything in "Show[]" but failed and also struggled to match the coordinate systems of the plot and the lines.

$\endgroup$

1 Answer 1

1
$\begingroup$

Maybe something like this:

DynamicModule[
  {a1 = {1, 1}, a2 = {-1, -1}, b1 = {-1, 1}, b2 = {1, -1}},
  LocatorPane[
    Dynamic[{a1, a2, b1, b2}], 
    Dynamic[
      Show[
        Graphics[{Blue, Line[{a1, a2}], Red, Line[{b1, b2}]}],
        Plot[Sin[x], {x, -2, 2}]]]]]
$\endgroup$
1
  • $\begingroup$ Thanks! Exactly what I was looking for. $\endgroup$
    – Niki
    Jul 24, 2022 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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