There are two occasions when it's okay to touch someone that you don't know well:
1) They said you can.
2) They are about to get hurt and you can prevent it. Do not overlook the importance of this in a gym where spotting is of the essence and other mishaps may occur. This also includes other first aid type situations.
Otherwise, noooo touchie. Closer relationships tend to evolve a freer exchange of contact, but casual acquaintances should be more reserved than close friends.
When in doubt, use a flip chip! Designed for yoga, they work for any other occasion where hands-on assist may be desired at some times and not at other times. If the hands-off side is up, just stay well out of reach from the person. Some people have risky reflexes. This is an excellent tool for anyone with body-contact issues or who presents events with variable contact. It makes consent crystal clear without requiring any awkward conversation or explanation.