Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
MapMagic World Generator
MapMagic World Generator
  • Project overview
    • Project overview
    • Details
    • Activity
  • Issues 157
    • Issues 157
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Requirements
    • Requirements
    • List
  • Operations
    • Operations
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Create a new issue
  • Issue Boards
  • Denis Pahunov
  • MapMagic World GeneratorMapMagic World Generator
  • Issues
  • #340

Closed
Open
Opened Jul 18, 2020 by Jason R. Surratt@jasonsurratt

Consider using Tobler's hiking function for calculating path finding cost surface

https://en.wikipedia.org/wiki/Tobler%27s_hiking_function

I tried replacing your existing cost function with Tobler's hiking function and found the results to be more pleasing for my use case. Clearly it wouldn't apply if you're creating roads for cars, etc. Given that the cost surface is simply another raster, it may make sense to feed in the cost surface as a WorldMatrix -- just musing.

My Tobler hack in Pathfinder.cs is below.

            if (passable)
            {
                //nNewWeight = weights.arr[pos] +
                //        diagonalFactor * distanceFactor +
                //        elevation * elevation * elevationFactor +
                //        dirDelta * straightenFactor;

                float dist = diagonalFactor * pixelSize;
                float deltaY = Mathf.Abs(nHeight - heights.arr[pos]) * heights.worldSize.y;

                // Tobler's hiking function
                // https://en.wikipedia.org/wiki/Tobler%27s_hiking_function
                // friction unit is seconds
                float m = deltaY / dist;
                nNewWeight = .6f * Mathf.Exp(3.5f * Mathf.Abs(m + 0.05f)) * dist + weights.arr[pos];

                if (nHeight * heights.worldSize.y < 25) nNewWeight = maxWeight + 1;
            }
            else
                nNewWeight = maxWeight + 1;
Edited Jul 20, 2020 by Jason R. Surratt
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: denispahunov/mapmagic#340