I would argue that implementation ideas never come out of thin air. Experience counts for a lot. And not necessarily even your own experience. Having mentors, be they teachers, people on forums (or SO for that matter) or even books/code can be a big help in your own development and give you something to draw upon when trying to find inspiration.
If you struggle to come up with logical solutions, don't stop. Keep going. Don't hesitate to completely screw up. As long as you figure out why you screwed up, you've already won half the battle.
And don't hesitate to look for inspiration in "unlikely" places. For example, I didn't really comprehend functional programming for a long time. But it all fell into place when I studied lambda calculus. But also the other way around: There were parts of linear algebra I only fully started to comprehend when I started programming CG applications and physical simulations.
So long story short, for me my current work is massively influenced by past experience, but also by all the other stuff I read/learn every day from a wide variety of resources.