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:

This is going to work even though it should not work. The sliding connector C will move down to the curve at the bottom. A few things come to mind when looking at this issue; The first thing is that detecting this particular situation would mean testing for the distance along the cam and detecting a large change. But what is large and what is ok? For a closed spline, the distance along the spline test would be more complicated.

This problem was very noticeable when I designed a vertical sliding garage door – the kind of door that follows a track vertically to a bend to horizontal. When one of the sliders moved off the bottom end of the track, it flipped up to be above the slider that was above it instead of below it off the end of the track. I am going to add code to detect an angle change of more than 180 degrees in order to detect that error. I might also try to examine the distance along the spline for each step of the simulation but then a reversing action might upset that test. It’s frankly a very difficult problem to solve!

I added a picture of the vertical sliding garage door. It has some features that are particular to the tutorial I’m working on but the main issue should be obvious; If the door is moved down instead of up, the slider “M” at the bottom left will want to move off the spline but will actually be moved up above slider “L” since that is the only place the silumator can put it.

Oh yeah, I’m still working on that tutorial. I have the video recorded but now I need to do a voice-over since I didn’t talk while I made the mechanism. We’ll see how that goes!