# Functional Objects

Function
Mechanism in which an arm C carrying a pen rotates around a pivot D which joins two links, one attached to rotating arm A, the other to rotating arm B. Care needed to ensure mechanism is viable AR + AB + BR < AD + BD and that the linkage remains valid.
double by Kit :
Randomly set the parameter values

Path Step size Scale Max Cycles Line Width Line Color Padding

## Function code

```    function fn(t,p,scale) {
if (check==1 )
if(!triangle (AD,BD,AB+AR+BR))
if(!triangle (AD,BD,AB-AR-BR))

{alert("mechanism invalid"); throw("mechanism impossible")}
d=AB;
Ax=AR*cos(t*Ar+Ap);Ay=AR*sin(t*Ar+Ap);
Bx=BR*cos(t*Br+Bp);By=BR*sin(t*Br+Bp);
dx=d-(Bx+Ax); dy=By-Ay;
Cl=Math.sqrt(dx*dx+dy*dy);
AB=Math.atan2(dy,dx)*180/Math.PI;
if (check==1)
if(!triangle(Cl,AD,BD)) {alert("not a triangle: " + Cl +" "+AD+" "+BD); throw("not a triangle");}
Aa=(AD*AD + Cl*Cl -BD*BD) /(2*Cl*AD) *180/Math.PI;
AC=(Aa+AB);
Px=AD*cos(AC);Py=AD*sin(AC);
Cx=CR*cos(t*Cr+Cp); Cy=CR*sin(t*Cr+Cp);
X= Px+Ax+Cx; Y= Py+Ay+Cy;
//            console.log(d,Cl,AD,BD,triangle(Cl,AD,BD),)
return [scale*X,scale*Y]
}
```