No, it is not legal. There was no legal basis for your detention, especially if you indicated no intention to operate a vehicle. Your civil rights were violated -- both with the unlawful detention and with the physical abuse.
You need to contact a decent civil rights attorney to further examine your claims.
The Brett Law Firm, P.A.
My legal opinon is that unless you did something really bad to provoke the officers, it is a load of *&^% and you should contact a civil rights attorney. Maybe the police should be suspended for their own safety and the safety of others. If you cannot find one contact your local bar, the state bar, or the ACLU--police hate the ACLU. Please click on the websites, it does not cost anything.
I would add that many civil rights lawyers will take a case on a contingency basis - meaning there is no cost to you unless you win. Document you injuries with photographs, go see a doctor and get a report, write down the times and events as best you can remember, as well as the names of the officers, and see some civil rights attorneys.
Officers exceeding their authority are a problem for everyone - your case therefore can help others.