I assume your O42 is 12 sections of track for a circle. That would be 3 for a right angle turn. On the inside corner of your 40" wall, try making the shelf bigger and "cut" the corner by using one and a half sections of curve or two sections of curve. Then add straights and complete your 'S' curve on the outside corner with the same two sections of track.
Also, why don't you loose lay your track on the floor to see how it will fit. You can even lay your shelf on the floor with the track on top. You may even be able to mount some of your track to the board before you put the shelf up.
George