Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I write a function to simulate a trajectory,code as below:

PlaneSimulation[px_, py_] := Manipulate[
Module[
{L1, L2, θ1, θ2, c2, s2, c1, s1, RobotInverse, 
RobotAera, RobotTrajectory},
L1 = 35; L2 = 16;
c2 = (-L1^2 - L2^2 + px^2 + py^2)/(2 L1 L2);      
s2 = -Sqrt[1 - (c2^2) ];
c1 = -((-L1 px - c2 L2 px - s2 L2 py)/(px^2 + py^2)); 
s1 = -((s2 L2 px - L1 py - c2 L2 py)/(px^2 + py^2));
θ2 = ArcTan[c2, s2] // Simplify;
θ1 = ArcTan[c1, s1] // Simplify;
RobotInverse = Graphics[
 {Line[{{0, 0}, {L1 Cos[θ1], 
     L1 Sin[θ1]}, {L1 Cos[θ1] + 
      L2 Cos[θ1 + θ2], 
     L1 Sin[θ1] + L2 Sin[θ1 + θ2]}}],
  Blue, PointSize[Medium],
  Point[{L1 Cos[θ1], L1 Sin[θ1]}],
  Green, PointSize[Medium], 
  Point[{L1 Cos[θ1] + L2 Cos[θ1 + θ2], 
    L1 Sin[θ1] + L2 Sin[θ1 + θ2]}]}, 
 Axes -> True, PlotRange -> {{-60, 60}, {-60, 60}}, 
 AspectRatio -> Automatic];
RobotAera = 
ParametricPlot[{L1 Cos[θ1] + L2 Cos[θ1 + θ2],
   L1 Sin[θ1] + 
   L2 Sin[θ1 + θ2]}, {θ1, -(5/9) \[Pi], 
  5/9 \[Pi]}, {θ2, -(5/6) \[Pi], 5/6 \[Pi]}, 
 AspectRatio -> Automatic, ImageSize -> 450];
RobotTrajectory = 
ParametricPlot[{px /. t -> u, py /. t -> u}, {u, 0.01, t}];
Show[{RobotInverse, RobotAera, RobotTrajectory}]],
{t, 0, 18}]

Call the function:

Circle:

PlaneSimulation[30 + 10 Cos[20 \[Degree] t], 
25 + 10 Sin[20 \[Degree] t]]

Sine:

PlaneSimulation[30 + 10 Sin[20 \[Degree] t], t + 10]

However,the graphic of RobotTrajectory cannot show correctly?

share|improve this question

1 Answer 1

up vote 4 down vote accepted
PlaneSimulation[px_, py_] := 
  Manipulate[
   Module[{L1, L2, θ1, θ2, c2, s2, c1, s1, RobotInverse,  RobotAera, RobotTrajectory},
    L1 = 35; L2 = 16;
    c2 = (-L1^2 - L2^2 + px^2 + py^2)/(2 L1 L2);
    s2 = -Sqrt[1 - (c2^2)];
    c1 = -((-L1 px - c2 L2 px - s2 L2 py)/(px^2 + py^2));
    s1 = -((s2 L2 px - L1 py - c2 L2 py)/(px^2 + py^2));
    θ2 = ArcTan[c2, s2] // Simplify;
    θ1 = ArcTan[c1, s1] // Simplify;
    RobotInverse = 
     Graphics[{Line[{{0, 0}, {L1 Cos[θ1],  L1 Sin[θ1]}, {L1 Cos[θ1] + 
               L2 Cos[θ1 + θ2], L1 Sin[θ1] + L2 Sin[θ1 + θ2]}}], Blue,
               PointSize[Medium], Point[{L1 Cos[θ1], L1 Sin[θ1]}], Green, 
               PointSize[Medium], Point[{L1 Cos[θ1] + L2 Cos[θ1 + θ2], 
                                         L1 Sin[θ1] + L2 Sin[θ1 + θ2]}]}, 
              Axes -> True, PlotRange -> {{-60, 60}, {-60, 60}}, 
              AspectRatio -> Automatic] /. t -> w;
    RobotAera = 
     ParametricPlot[{L1 Cos[θ1] + L2 Cos[θ1 + θ2], L1 Sin[θ1] + L2 Sin[θ1 + θ2]}, 
                    {θ1, -(5/9) π, 5/9 π}, {θ2, -(5/6) π, 5/6 π}, 
                    AspectRatio -> Automatic, ImageSize -> 450];
    RobotTrajectory =  ParametricPlot[{px, py} /. t -> u, {u, 0.01, w}, 
                                       PlotStyle -> Red, PlotLabel -> px];
    Show[{RobotInverse, RobotAera, RobotTrajectory}]], {w, 0, 18}];
PlaneSimulation[30 + 10 Cos[20 ° t], 25 + 10 Sin[20 ° t]]

Mathematica graphics

share|improve this answer
    
,Thanks,but I wonder why add the pattern ` t -> w` can achieve good result? –  tangshutao May 5 at 4:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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