# How to combine ListPlot, Graphics, and Manipulate?

I have the following pieces of code and I wanted to overlay one on top of the other so that I can plot the point space of the end point. Another fix I could envision was being able to just trace that point.

Here is the code for the graphic of the mechanism:

Manipulate[
Graphics[{Thickness[0.02], Line[{{-1, 0}, {0, 0}}],
Line[{{0, 0}, {segment2*Cos[angle1], segment2*Sin[angle1]}}],
Line[{{segment2*Cos[angle1], segment2*Sin[angle1]},
{segment3*Cos[angle1 + angle2] + segment2*Cos[angle1],
segment3*Sin[angle1 + angle2] + segment2*Sin[angle1]}}]},
PlotRange -> {{-1, segment2 + segment3 + 1}, {-2, 2}}],
{angle2, 11*Pi/6, 13*Pi/9, Pi/45}, {angle1,20*Pi/180, -60 Pi/180, -Pi/45},
{segment2, 1, 3, .25}, {segment3, 1, 3, .25}]


Here is the code for the point space:

x1 = segment3*Cos[angle1 + angle2] + segment2*Cos[angle1]
y1 = segment3*Sin[angle1 + angle2] + segment2*Sin[angle1]
Points = Table[{x1, y1}, {angle2, 11* Pi/6, 13*Pi/9, -Pi/45},
{angle1, 20*Pi/180, -1*60* Pi/180, -Pi/45}]
With[{PointsPoints = Points },
Manipulate[ListPlot[PointsPoints], {segment2, 1, 3, .25}, {segment3,1, 3, .25}]]

• Is Show the answer? – Kuba Mar 1 '17 at 20:26
• Show doesn't work when I use it, it gives the error "cannot combine in show". But maybe Im using show wrong? What I did was give each of the manipulate functions names and then used those names in the show function. – Erin Mar 1 '17 at 20:38
• You can use Show to combine Graphics/Plots, not Manipulate. Try to gather all inside one Manipulate[ Show[ ListPlot[...], Graphics[...]],...] – Kuba Mar 1 '17 at 20:45
• Does anyone know of a way to trace the end point and leave a line of where it has traveled? – Erin Mar 2 '17 at 14:08

## 2 Answers

Manipulate[points = Table[{s3 Cos[a1 + a2] + s2 Cos[a1], s3 Sin[a1 + a2] + s2 Sin[a1]},
{a2, 11 Pi/6, 13 Pi/9, -Pi/45}, {a1, 20 Pi/180, - 60 Pi/180, -Pi/45}];
Graphics[{ListPlot[points][], Thickness[0.02], JoinForm["Round"], CapForm["Butt"],
{Line[#], Red, PointSize[Large], Point[#[[-1]]]} &@
{{-1, 0}, {0, 0}, {s2 Cos[an1], s2 Sin[an1]},
{s3 Cos[an1 + an2] + s2 Cos[an1], s3 Sin[an1 + an2] + s2 Sin[an1]}}},
PlotRange -> {{-1, s2 + s3 + 1}, {-3, 1}}, ImageSize -> 400],
Grid[{{Control@{{an2, 11 Pi/6, "angle2"}, 11 Pi/6, 13 Pi/9, Pi/45},
Control@{{s2, 1, "segment2"}, 1, 3, .25}},
{Control@{{an1, 20 Pi/180, "angle1"}, 20 Pi/180, -60 Pi/180, -Pi/45},
Control@{{s3, 1, "segment3"}, 1, 3, .25}}}],
{{points, {}}, None}, Alignment -> Center]  With[{PointsPoints = points}, Manipulate[
Show[Graphics@Point@PointsPoints,
Graphics[{Thickness[0.02], Line[{{-1, 0}, {0, 0}}],
Line[{{0, 0}, {segment2*Cos[angle1],
segment2*Sin[angle1]}, {segment2*Cos[angle1],
segment2*Sin[angle1]}, {segment3*Cos[angle1 + angle2] +
segment2*Cos[angle1],
segment3*Sin[angle1 + angle2] + segment2*Sin[angle1]}}]}]],
{angle2, 11*Pi/6, 13*Pi/9, Pi/45}, {angle1, 20*Pi/180, -60 Pi/180, -Pi/45},
{segment2, 1, 3, .25}, {segment3, 1, 3, .25}]]


here is a picture DynamicModule[{x1, y1, points},
Manipulate[
(x1 = segment3*Cos[angle1 + angle2] + segment2*Cos[angle1];
y1 = segment3*Sin[angle1 + angle2] + segment2*Sin[angle1];
points = {x1, y1};
);
Show[Graphics[{Red, PointSize[0.05], Point@Dynamic@points}],

Graphics[{Thickness[0.02], Line[{{-1, 0}, {0, 0}}],
Line[{{0, 0}, {segment2*Cos[angle1],
segment2*Sin[angle1]}, {segment2*Cos[angle1],
segment2*Sin[angle1]}, {segment3*Cos[angle1 + angle2] +
segment2*Cos[angle1],
segment3*Sin[angle1 + angle2] +
segment2*Sin[angle1]}}]}]], {angle2, 11*Pi/6, 13*Pi/9, Pi/45},
{angle1, 20*Pi/180, -60 Pi/180, -Pi/45}, {segment2, 1,3, .25}, {segment3, 1, 3, .25}]] finally i understand what you wanted in the first place :)

DynamicModule[{points, x1, y1, currentpoint},
Manipulate[
points =
Table[{segment3 Cos[a1 + a2] + segment2 Cos[a1],
segment3 Sin[a1 + a2] + segment2 Sin[a1]}, {a2, 11 Pi/6,
13 Pi/9, -Pi/45}, {a1, 20 Pi/180, -60 Pi/180, -Pi/45}];
x1 = segment3*Cos[angle1 + angle2] + segment2*Cos[angle1];
y1 = segment3*Sin[angle1 + angle2] + segment2*Sin[angle1];
currentpoint = {x1, y1};

Show[ListPlot[points, Axes -> None],
Graphics[{Red, PointSize[0.03], Point@Dynamic@currentpoint}],
Graphics[{Thickness[0.02], Line[{{-1, 0}, {0, 0}}],
Line[{{0, 0}, {segment2*Cos[angle1],
segment2*Sin[angle1]}, {segment2*Cos[angle1],
segment2*Sin[angle1]}, {segment3*Cos[angle1 + angle2] +
segment2*Cos[angle1],
segment3*Sin[angle1 + angle2] +
segment2*Sin[angle1]}}]}]], {angle2, 11*Pi/6, 13*Pi/9,Pi/45},
{angle1, 20*Pi/180, -60 Pi/180, -Pi/45}, {segment2, 1,3, .25}, {segment3, 1, 3, .25}]] • This is awesome and definitely a step forward but it doesnt update the points for different angles. How would I fix that? – Erin Mar 1 '17 at 21:18
• @Erin is this what you need? – Ali Hashmi Mar 1 '17 at 22:05
• I actually wanted to find a way to create a line drawn from the point but thank you! – Erin Mar 2 '17 at 13:33