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.

Today,I want to use a point generate a circle,the main picture as below:

enter image description here

Given that I know the equation of circle, and the value of $L_1$,$L_2$.The coordinate of point $A$ is $(p_x,p_y)$.

I use the equations: $$p_x=L_1 cos(\theta_1)+L_2cos(\theta_1+\theta_2) \\ p_y=L_1 sin(\theta_1)+L_2sin(\theta_1+\theta_2)$$ to solve the results of $\theta_1,\theta_2$ as below:$$cos(\theta_2)=\frac{-L_1^2-L_2^2+p_x^2+p_y^2}{2 L_1 L_2} \\sin(\theta_2)=\pm \sqrt{1-cos^2(\theta_2)}$$

$$sin(\theta_1) =-\frac{sin(\theta_2) L_2 p_x-L_1 p_y - cos(\theta_2) L_2 p_y}{p_x^2+p_y^2}\\ cos(\theta_1) =-\frac{-L_1 p_y - cos(\theta_2) L_2 p_x - sin(\theta_2) L_2 p_y}{p_x^2+p_y^2} $$

My trial as below:

Manipulate[
  Module[{L1, L2, θ1, θ2, A, B, C1, D1, px, py},
    L1 = 35; L2 = 20;
  A = (-L1^2 - L2^2 + px^2 + py^2)/(2 L1 L2);
  B = Sqrt[1 - A^2 ];
  C1 = -((-L1 px - A L2 px - 
  B L2 py)/(px^2 + py^2));
  D1 = -((B L2 px - L1 py - A L2 py)/(
  px^2 + py^2));
  px = 50 + 15 Cos[20 ° t];
  py = 50 + 15 Sin[20 ° t];
  θ2 = ArcTan[B, A] // Simplify;
  θ1 = ArcTan[D1, C1] // Simplify;
 Graphics[
         {Line[{0, 0}, {L1 Cos[θ1], 
    L1 Sin[θ1]}, {L1 Cos[θ1] + 
    L2 Cos[θ1 + θ2], 
    L1 Sin[θ1] + L2 Sin[θ1 + θ2]}], Red, 
   Point[{L1 Cos[θ1] + L2 Cos[θ1 + θ2], 
    L1 Sin[θ1] + L2 Sin[θ1 + θ2]}]}, 
  Axes -> True]
], {t, 0, 18}
]

Edit

Thanks for Mr.Wizard's help.

Manipulate[
  Module[{L1, L2, θ1, θ2, c2, s2, c1, s1, px, py},
L1 = 35; L2 = 20;
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));
px = 50 + 15 Cos[20 ° t];
py = 50 + 15 Sin[20 ° t];
θ2 = ArcTan[c2, s2] // Simplify;
θ1 = ArcTan[c1, s1] // Simplify;
Graphics[
{Circle[{50, 50}, 15], 
 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[Large],
  Point[{L1 Cos[θ1], L1 Sin[θ1]}],
  Red, PointSize[Large], 
  Point[{L1 Cos[θ1] + L2 Cos[θ1 +θ2], 
   L1 Sin[θ1] + L2 Sin[θ1 + θ2]}]}, 
 Axes -> True, PlotRange -> {{-20, 80}, {-20, 80}}, 
 AspectRatio -> Automatic] /. z_Complex :> Re[z]],
 {t, 0, 18}]

It generates:

enter image description here

By manipulating the value of t,I found the length of shaft L1 and shaft L2 vary. This is contradictory because the length of L1 and L2 are constants. I don't know why.

share|improve this question

closed as off-topic by Yves Klett, rasher, belisarius, m_goldberg, bobthechemist May 3 at 11:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Yves Klett, rasher, belisarius, bobthechemist
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
You might want to define the variables L1 and L2, and use the correct syntax for the cosine and sine functions, which are Cos[ ] and Sin[ ]. Also, you cannot really assign Cos[theta]=. –  bill s May 3 at 4:29
    
@bills,I have edited my question and given the values of L1 and L2 –  tangshutao May 3 at 4:47
1  
One problem with the above formulation is that it produces values of c1, s1, c2, and c2 of magnitude greater than 1, but these quantities are supposed to represent the sines and cosines of angles. –  m_goldberg May 3 at 11:21
    
This question appears to be off-topic because the bad results stem at least in part from errors in the underlying math that must be corrected before consideration is given to the coding. –  m_goldberg May 3 at 11:26

1 Answer 1

up vote 5 down vote accepted

Two things I note:

  1. Line is used incorrectly; use e.g. Line[{{a,b}, {c,d}}] not Line[{a,b}, {c,d}]

  2. The coordinates in your Graphics expression are complex values. You must convert them.

I don't know if this works as you intend but it no longer produces an error:

Manipulate[
 Module[{L1, L2, θ1, θ2, A, B, C1, D1, px, py},
  L1 = 35; L2 = 20;
  A = (-L1^2 - L2^2 + px^2 + py^2)/(2 L1 L2);
  B = Sqrt[1 - A^2];
  C1 = -((-L1 px - A L2 px - B L2 py)/(px^2 + py^2));
  D1 = -((B L2 px - L1 py - A L2 py)/(px^2 + py^2));
  px = 50 + 15 Cos[20 ° t];
  py = 50 + 15 Sin[20 ° t];
  θ2 = ArcTan[B, A] // Simplify;
  θ1 = ArcTan[D1, C1] // Simplify;
  Graphics[{Line[{{0, 0}, {L1 Cos[θ1], 
        L1 Sin[θ1]}, {L1 Cos[θ1] + L2 Cos[θ1 + θ2], 
        L1 Sin[θ1] + L2 Sin[θ1 + θ2]}}], Red, 
     Point[{L1 Cos[θ1] + L2 Cos[θ1 + θ2], 
       L1 Sin[θ1] + L2 Sin[θ1 + θ2]}]}, Axes -> True] /. 
   z_Complex :> Re[z]
  ],
 {t, 0, 18}
]
share|improve this answer
    
,Thank you,I have found mistake that the circle trajactory must in the aera of point P. –  tangshutao May 3 at 13:23

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