Following Aristotle, medieval natural philosophers believed that knowledge was ultimately based on perception and observation; and like Aristotle, they also believed that observation could not explain the "why" of any perception. To arrive at the "why," natural philosophers offered theoretical explanations that required the use of the imagination. This was, however, only the starting point. Not only did they apply their imaginations to real phenomena, but expended even more intellectual energy on counterfactual phenomena, both extracosmic and intracosmic, extensively discussing, among other themes, the possible existence of other worlds and the possibility of an infinite extracosmic space. The application of the imagination to scientific problems during the Middle Ages was not an empty exercise, but, as I shall show, played a significant role in the development of early modern science.