| Author |
Comment/Response |
Frank Rotello
|
04/25/99 09:30am
Attached is a Mathmatica program that uses a FOR loop to animate a linkage mechanism. But there is an error that states Graphics::gprim: primitive Null encountered. Whats going on?
(* Mathematica program to draw and animate the position of the mechanism in
Ex. 1; also draw the curves for the centers of mass of links 2 and 4*)
Apply [Clear, Names [ ''Global`*'']];
(* Set system parameters and the number (nox) of positions to draw *)
In[22]:=
fi=N[Pi/4]
AB= .15
BC=.4
CD=.37
CE=.23
xd = .3
yd = .45
Lc =CD
EF= CE
La= 0.3
Lb=.45
pi= N [Pi]
nox=24
(* draw nox position of the mechanism *)
Out[22]=
0.785398
Out[23]=
0.15
Out[24]=
0.4
Out[25]=
0.37
Out[26]=
0.23
Out[27]=
0.3
Out[28]=
0.45
Out[29]=
0.37
Out[30]=
0.23
Out[31]=
0.3
Out[32]=
0.45
Out[33]=
3.14159
Out[34]=
24
In[35]:=
For[increment = 1, increment<=nox, increment++,
fi=(increment-1)*pi*2/nox;
(* the position of the joint B *)
yb= AB*Sin[fi];
xb= AB*Cos[fi];
(*the position of the joint C *)
xd = La ;
yd =Lb;
eq23a=( xc -xb )^2 + ( yc-yb)^2- BC^2;
eq23b=( xc-xd )^2+ ( yc-yd )^2-CD^2;
solution=Solve [ {eq23a==0,eq23b==0},{xc,yc}];
(* there are two possible solutions for C *)
xc1=xc/.solution[[1]];
yc1=yc/.solution[[1]];
xc2=xc/.solution[[2]];
yc2=yc/.solution[[2]];
(*Use the constraints to select the leftmost solution *)
If [xc1<xc2,xcs=xc1;ycs=yc1,xcs=xc2;ycs=yc2];
(*Determine first the parameters m and n *);
m= ( ycs - yd )/ ( xcs -xd );
n = ycs -m xcs;
(* define the equations from where xe and ye are computed *)
eq24 = ( xe- xcs )^2 + ( ye -ycs )^2 - CE^2;
eq27 = ye - m xe - n;
solution = Solve [ { eq24==0, eq27==0}, {xe,ye} ];
(*there is only one possible solution (repeated twice) for E *)
xe1= xe/. solution [[1]];
ye1 = ye /. solution[[1]];
xe2=xe /. solution [[2]];
ye2= ye/.solution[[2]];
(* Set the constraint to select the point E *)
If [ xe1<= xcs , xes = xe1 ; yes = ye1 , xes= xe2 ; yes = ye2];
xfs = - Lc;
eq28 = ( xes - xfs )^2 + ( yes - yf )^2 - EF^2;
solution = Solve [ eq28 == 0 , yf ];
yf1 = yf /. solution [[1]];
yf2=yf /. solution[[2]];
(* set the constraint *)
If [ yf1 < yes, yfs= yf1, yfs = yf2 ];
(* determine the position of the c.o.m.'s of links 2 and 4 *)
l2x [ increment ] = ( xb+ xcs )/2;
l2y [ increment ] = ( yb + ycs ) / 2;
l4x [ increment ] = ( xfs + xes ) / 2;
l4y [ increment ] = ( yfs + yes ) / 2;
(* Plot point at all joints and c.o.m.'s of links 2and 4 *)
markers=Table [ {
Point [ {0,0 }],
Point [ { xb , yb }],
Point [ { xcs , ycs }],
Point [ { xd , yd }],
Point [ { xes , yes }],
Point [ { xfs , yfs }],
Point [ { l2x [ increment ], l2y [ increment] }],
Point [ { l4x [ increment ], l4y [ increment ] }],
}];
(* assign letters to all the points *)
name = Table [ {
Text [ '' A'' , {0,0} , { -1 ,0 } ],
Text [ '' B'' , { xb, yb } , { -1 , 0 } ],
Text [ '' C'' , { xcs, ycs} , { -1 , -1} ],
Text [ '' D'' , { xd , yd } , {-1 , 0} ],
Text [ ''E '' , { xes , yes } , { 1 ,0} ],
Text [ ''F '' , { xfs , yfs } , { 1 ,0 } ],
Text [ ''H '' , { l2 x[increment], l2y[increment] } , { 1,0} ],
Text [ ''P '' , { l4x[increment] , l4y[increment] } , { 1,0 } ],
}];
(* compose the graph *)
graph [ increment ] = Graphics [
{{ RGBColor [ 1, 0, 0 ],
Line [ { {0,0}, {xb,yb} } ] } ,{ RGBColor [ 0,0,1 ] ,
Line [ { {xb,yb} , {xcs,ycs},{xd,yd},{xes,yes} } ] },
{ RGBColor [ 0,0,0 ] ,
Line [ { {xes,yes},{xfs,yfs} } ] },
{ RGBColor [ 0,0,1 ],
PointSize [ 0.02 ] , markers },
{ name } } ];
(* draw the graph in order to animate the mechainsm *)
Show [graph [increment], AspectRatio-> Automatic, PlotRange->
{{-.42, .362}, {-.2,.75}}];
] (* End of the FOR loop *)
Graphics::''gprim'': ''Unknown \!\(Graphics\) primitive \!\(Null\) encountered.''
From In[35]:=
URL: , |
|