The stars spent several hours being filmed in the vehicle along with a mystery actress who drove up and down a mile-long stretch of the A725 in Bellshill, Lanarkshire.
The trio were filmed inside the German coupe while having a conversation using a “Russian Arm” device which allows shooting from the side, front and back of a vehicle by placing the camera on an extended, moveable, arm.
Director Danny Boyle sat in the passenger seat of a blacked-out Mercedes people carrier which drove alongside the BMW, with a monitor on his lap allowing him to see all the action.
A 100-strong crew was involved in shooting the scenes following rehearsals at the nearby Bellshill Industrial Estate. Filming had earlier taken place at the Orb pub in the town.
Details of the shoot were revealed by the agency Transport Scotland, which agreed to close the stretch of road for several hours to accommodate filming and was allowed to photograph the shoot.
The Oscar-winner was said to have been heard at one point telling McGregor and Miller: “This is the real Scotland!”
The two actors took part in the night-time shoot days after filming scenes at the Scottish Parliament building at Holyrood and outside the Scottish Government’s headquarters in Leith.
Transport minister Humza Yousaf said: “The Scottish Government is keen to promote filming at Scottish locations, given the clear economic benefits it brings to the country and the support it offers our film and tourism industries.
“It’s not every day we are approached by a production company asking to film on the trunk road network, and when we heard it was for the sequel to cult-classic Trainspotting, we were keen to make it happen.
“It takes a great deal of coordination to accommodate filming requests. We are mindful of the impact of a road closure and aim to minimise any potential disruption to road users.
“We were delighted to welcome Danny Boyle and the cast on site to film on the A725.”
The script of Trainspotting 2, which is due to be released in January, is said to be “loosely” based on Porno, Irvine Welsh’s own follow-up to his best-selling novel.