PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Sat Jul 21, 2018 5:39 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Sep 10, 2017 6:35 am 
Forum Newbie

Joined: Sat Oct 22, 2016 10:42 am
Posts: 17
See attached picture for reference. I'm working on a map generator and I would like to include altitude, where either brightness of color represents altitude, or there are nested curves that show where the altitude crosses a certain threshold. If I just added circles or polygons at random, it would lead into drastic drops in altitude instead of a smooth increase or decrease.

My idea is to store the highest and lowest points within an area and if two high points can be connected by a straight line without crossing the impact circle of a local low, they are considered connected (red lines in graph). Similarly, low points will be connected if they don't get intercepted by high points. Then the program should surround the highest points with blobs that start out as circles, and the edges of the circles can be pushed inwards by the influence of nearby lows. Each low has an impact radius within which it can push lines towards high points. Highs within the same altitude and which are connected will be surrounded by a continuous line or a blob. If a high inside a blob is higher than the other highs, it will in addition to be surrounded by a nested circle or as many as are needed to represent the height difference. Similarly, lows that are lower than the base altitude will be wrapped in blobs. There will be as many nested blobs as necessary to cover the difference in altitude.

The problem is, how to calculate where the curves go? I think I need to start with calculating how many steps (lines) are between highs and lows and drawing short walls that separate them. (Image 3) When I have all the short walls drawn, I would connect them to each other. I should figure out which points are close enough to interact without crossing an invisible line connecting two other points.

It doesn't necessarily have to use bezier curves since I don't have ImageMagick but I've read that there are resources available that allow drawing bezier curves with GD. I would be happy even with polygons. The presence of corners doesn't necessarily bother me.

pic3.png [ 67.79 KiB | Viewed 1404 times ]
impact_circle.png [ 169.92 KiB | Viewed 1404 times ]
altitude.png [ 157.16 KiB | Viewed 1404 times ]
PostPosted: Sun Sep 10, 2017 2:53 pm 
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
You can't do this well just by using high and low points. You need to know everything in between, and knowing it also gives you more control over the terrain.

You can start with high and low points, but in the next step calculate (however you want) all the elevation points everywhere on the map. There's also some degree of realism: local lows and highs aren't the same as global lows and highs.

As a simple example,
X  0         1         2
Y  012345678901234567890
00 001123344455556677788
1  112233444555566677778
2  223344555566677888888
3  444455556667778889999
4  556667788888889998887
5  667788999999999887765
6  889999988888889998877
7  999888888777888899999
8  888877665556677888888
9  777666655455667777778
10 555555444444556666677


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 5 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group