# How to find the Y coordinate of a line moving up and down with given specific X coordinate?

I start with a horizontal line and I run midpoint displacement algorithm to generate some mountains, then I want to place some pillars on top of the mountain by randomly choosing the X coordinate, but I need the Y coordinate of the mountain so I can place the pillar, right?

Now the idea is that these mountains will keep changing and moving, some chunks might move up or down while moving left or down, at a constant motion.

Let's say I want to place a pillar on the mountain, so I get some X coord. How do I find the height of the mountain ledge that keeps moving?

• I don't understand. What's a "displaced line"? Are its X and Y coordinates related by a one-to-one function?
– Anko
Mar 31 '14 at 16:02
• @Anko First I start with a single horizontal line, then I run Midpoint Displacement Algorithm or another name would be Brownian Motion, two similliar techniques for generating terrain. My line for example looks like the machines in the hospitals that detects your heartbeat. Mar 31 '14 at 16:28
• If the function initially generating a Y height from your X input is fully random, you have to store the Y for every X, or you'll never find the Y again. (If it's pseudo-random, you could regenerate the outputs if you store the random seed.) Am I missing something?
– Anko
Mar 31 '14 at 17:27
• Now the answer is "depends on your mood". Store your terrain heights somewhere (a list of Ys or a dictionary from x to y, maybe?) and write or read them as needed.
– Anko
Mar 31 '14 at 18:12
• Use linear interpolation to find the height. You're interpolating between the two nearest X data points.
– House
Apr 7 '14 at 15:25