Since cam simulation involves finding the “best” place on a spline to place a sliding connector, there are bound to be small problems caused by the cam shape. I realized that this can actually cause terrible problems when a cam is using an open spline. The simulation difficulties can result in a sliding connector jumping to an unlikely-to-be-valid position. I’ll explain more…

For a sliding connector on the end of a link, the simulator calculates the position of that sliding connector by calculating a circle around the other end of the link using the link length as the radius. Then all of the points on the spline that intersect with that circle are found using some “simple” spline-circle intersection calculations. As far as I can tell, the number of intersections tops out at around 5 but the code has no limit and finds them all no matter how many or few. The next step in the process is to determine where the sliding connectors was expected to be by following a line through the previous two points and extrapolating a third expected point. This is never the right point but it a useful approximation to use when picking which of the intersection points is the one to pick for the new sliding connector position.

Imagine the following mechanism rotating clockwise in these two steps of the simulation:

You can see that the sliding connector C jumped a long ways. The new position is one of two valid intersection points and one of them is much closers to the expected point than the other. The other would move C much further around onto the bottom curve of the cam. This is what a correctly running simulation should do if we are allowed to have the sliding connector “fall” to the new position. If that follower were a pin in a slot, this would still work in real life although the sliding connector would have followed the spline path rather quickly to this new position. Real life has what we perceive as an infinite number of steps between movements of time while our simulator only has 30ths of a second! Either way, this cam works as expected.

Now imagine the next cam shape also rotating clockwise with that sliding connector being a pin in a slot: