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?

  • \$\begingroup\$ I don't understand. What's a "displaced line"? Are its X and Y coordinates related by a one-to-one function? \$\endgroup\$
    – Anko
    Mar 31 '14 at 16:02
  • \$\begingroup\$ @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. \$\endgroup\$
    – dragons
    Mar 31 '14 at 16:28
  • 1
    \$\begingroup\$ 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? \$\endgroup\$
    – Anko
    Mar 31 '14 at 17:27
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Anko
    Mar 31 '14 at 18:12
  • 1
    \$\begingroup\$ Use linear interpolation to find the height. You're interpolating between the two nearest X data points. \$\endgroup\$
    – House
    Apr 7 '14 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.