Finding shape preserving positioning of a 'piston' I have a chain of rods that are setup in a default, ideal orientation.  Points are labelled with a 'p' prefix, their lengths with an r:

I then stretch them to reach a desired end location, but they lose their shape:

I'd like to see if there's a better 'result' that tries to respect the shape of the original setup, with the following constraints:


*

*r1, r2 and r3 can't change length

*p1 and p4 are fixed


My intuition here says that I could build an equation for p2 based on the circle described by p1 and r1, and do the same thing for p4 and r3.  I have an equation for p3 and p2 (satisfying length), but I'm unsure how to use the math to describe "maintaining the shape".  

As in your bottom drawing you know p2 is on the left circle and p3 is on the right.  Put p1 at the origin and measure the angle of the p1p2 segment by $\theta$ with $0$ to the right and increasing counterclockwise.  The position of p2 is then $(r1\cos \theta, r1\sin \theta)$  You can put p4 on the positive $x$ axis.  Also define $\phi$ as the angle of p3p4 measured the same way.  The position of p3 is $(p4+r3\cos \phi,r3\sin \phi)$.  For a given $\theta$ there will be $0,1,$ or $2$ points that p3 can be to maintain the length r2.  Probably the best measure of similarity is to compare the two angles of the linkage from start to finish.  You might add the absolute differences, but you have to watch out for wrapping around.
