Pathing algorithm for a continuous search space? - algorithm

I'm currently making an RTS game in unity and I need a way to calculate the shortest path between two points on a continuous 2d plane where there are certain obstacles.
I have a start position, an end position, and a function that can test whether a position is valid. I need an algorithm that returns a sequence of points to move through in order to get to the destination.
Most of the pathing algorithms like A* and IDA* that I know of require discretized search spaces. I would divide the plane into a grid myself but I fear that it would result in zig zag patterns that look really unnatural when moving along the diagonal. Is there a way to alleviate this problem or a different pathing algorithm I can use? It doesn't even have to find the absolute shortest path, just a path that makes sense.

One approach might be to discretize the search space by considering only points interesting for planing - points on the boundaries of the obstacles, for example only the corners of bounding boxes, and then use any of the algorithms you already know.
Another option would be to compute on a grid and then smoothen the best path found on the grid.

You could create a zig-zaggy path then use Pure Pursuit to smooth it.

Related

Shortest distance between two point on surface

I'm working on my bachelor thesis (on Computer Science) and right now I'm having a problem about finding shortest path between two points on 3D triangular mesh that is manifold. I already read about MMP, but which computes distance function $d(x)$ between given point and vertex $x$ on mesh.
I got to know that the problem I'm solving is named Geodesics but What I really couldn't find is some good algorithm which uses A* for finding shortest path between two given points on two given vertices.
I 'invented' also algorithm which uses A* by using Euclidian Distance Heuristics and correction after finding new Point on any Edge..
I also have edges saved in half-edge structure.
So my main idea is this:
We will find closest edge by A* algorithm and find on this edge point with minimalizing function $f(x) + g(x)$ where $f$ is our current distance and $g$ is heuristics(euclidean distance)
Everytime we find new edge, we will unfold current mesh and find closest path to our starting point
So now my questions:
Do you know some research paper which talks about this problem ??
Why nobody wrote about algorithm that uses A* ??
What are your opinions about algorithm I proposed ?
Here are some papers and tools related to finding geodesics (or approximations) on a surface mesh:
A Survey of Algorithms for Geodesic Paths and Distances
You Can Find Geodesic Paths in Triangle Meshes by Just Flipping Edges (code)
The Vector Heat Method
(code)
You can find more papers in the survey paper.
I implemented the algorithm you mentionned (MMP) a long time ago and it's quite difficult to get it right and quite time consuming since the number of splits along an edge grows quite fast.
I am no expert in the matter so read with prejudice. Also sorry this is more of a comment than answer...
First You should clarify some things:
the mesh is convex or concave?
are the path always on surface or can fly between faces on the outside (if concave) but never inside?
are the start/end points on edges of faces or can be inside?
Assuming concave, points on edges and only surface paths...
I think the graph A* approach is unusable as there is infinite possible paths between point and any edge of the same face so how you test all of them?
If you really want A* then you can do something similar to raster A*
so resample all your edges to more points
so either n points or use some density like 10 points per average edge length or some detail size.
use graph A* on resampled points (do not handle them as edges anymore)
However this will produce only close to shortest path so in order to improve the accuracy you should recursively resample the edges near used point with higher and higher density until the distance between resampled points get smaller than accuracy.
Another option would be using something similar to CCD (cyclic coordinate descent) so:
create plane that goes through your 2 points and center of your mesh
create path that goes through all intersection of plane and faces between the 2 points (use the shorter on from the 2 options)
iterativelly move intersections back and forward and use greedy approach to get the result
However this might get stuck in local minima... You could use search/fitting approaches instead but those will get very slow with increasing number of faces
I got the feeling you might also do this using RANSAC ...
From my point of view I think the first A* approach is the most promising, you just need linked list of points per each edge and one cost counter per each its point from this you can simply encode even the recursive improvement of accuracy. It can be done even in-place so no reallocation needed in the recursion ... And also the algo is not complicated so you should have no problems implementing it, and the result is guaranteed which is not the case with other approaches I mention... Another pros is that it can be used even if start/endpoint does not belong to edge...

Ray tracing: Bresenham's vs Siddon's algorithm

I'm developping a tool for radiotherapy inverse planning based in a pencil-beam approach. An important step in these methods (particularly in dose calculation) is a ray-tracing from many sources and one of the most used algorithms is Siddon's one (here there is a nice short description http://on-demand.gputechconf.com/gtc/2014/poster/pdf/P4218_CT_reconstruction_iterative_algebraic.pdf). Now, I will try to simplify my question:
The input data is a CT image (a 3D matrix with values) and some source positions around the image. You can imagine a cube and many points around, all at same distance but different orientation angles, where the radiation rays come from. Each ray will go through the volume and a value is assigned to each voxel according to the distance from the source. The advantage of Siddon's algorithm is that the length is calculated on-time during the iterative process of the ray-tracing. However, I know that Bresenham's algorithm is an efficient way to evaluate the path from one point to another in a matrix. Thus, the length from the source to a specific voxel could be easily calculated as the euclidean distance two points, even during Bresenham's iterative process.
So then, knowing that both are methods quite old already and efficient, there is a definitive advantage of using Siddon instead of Bresenham? Maybe I'm missing an important detail here but it is weird to me that in these dose calculation procedures Bresenham is not really an option and always Siddon appears as the gold standard.
Thanks for any comment or reply!
Good day.
It seems to me that in most applications involving medical ray tracing, you want not only the distance from a source to a particular voxel, but also the intersection lengths of that path with every single voxel on its way. Now, Bresenham gives you the voxels on that path, but not the intersection lengths, while Siddon does.

Finding the closest point on a grid with obstacles

I have a game where you have to move around a map collecting gold and then move to the exit. I am currently trying to write an AI that will play this game but I want to know what algorithm I should use the find the closest instance of an object. For instance, the closest piece of gold or the closest unknown map square. The issue is that there are walls that the player cannot move through, so rather than just finding the closest object I need to find the one to which there is the shortest route. Is there an algorithm that can do this?
The algorithm you're looking for is called A* Search Algorithm. It is a best-first search algorithm that works by beginning at the starting point and building up a series of possible paths (excluding going through obstacles since those aren't possible paths), then scoring those paths to find the least cost one. In your case you'd need to customize the scoring by decreasing the cost based upon the objects along the path and increasing the cost by distance.
There's some information that will help you with it here:
There's a nifty interactive demo here (code also on github): http://qiao.github.io/PathFinding.js/visual/
Other resources:
https://harablog.wordpress.com/2011/09/01/rectangular-symmetry-reduction/
https://en.wikipedia.org/wiki/A*_search_algorithm
What is a good 2D grid-based path-finding algorithm?

Place a marker arbitrarily inside a polygon in Google Maps

There is a lot of documentation around how to detect if a marker is within a polygon in Google Maps. However, my question is how can I arbitrarily place a marker inside a polygon (ideally as far as possible from the edges)
I tried calculating the average latitude and longitude of the polygon's points, but this obviously fails in some non-concave polygons.
I also thought about calculating the area's center of mass, but obviously the same happens.
Any ideas? I would like to avoid trial-and-error approaches, even if it works 99% of the time.
There are a few different ways you could approach this, depending on what exactly you're overall goal is.
One approach would be to construct a triangulation of the polygon and place the marker inside one of the triangles. If you're not too worried about optimality you could employ a simple heuristic, like choosing the centroid of the largest triangle, although this obviously wont necessarily give you the point furthest from the polygon edges. There are a number of algorithms for polygon triangulation: ear-clipping or constrained Delaunay triangulation are probably the way to go, and a number of good libraries exist, i.e. CGAL and Triangle.
If you are interested in finding an optimal placement it might be possible to use a skeleton based approach, using either the medial-axis or the straight skeleton of the polygon. The medial-axis is the set of curves equi-distant from the polygon edges, while the straight skeleton is a related structure. Specifically, these type of structures can be used to find points which are furthest away from the edges, check this out for a label placement application for GIS using an approach based on the straight skeleton.
Hope this helps.

path finding in a simple grid, no obstacles

I want a simple algorithm in As3 that finds the shortest path in a simple grid, i need complete path not the only both points or the length.
check image here: http://screencast.com/t/GmR5YaO4L
so i need all the square numbers of the grid that comes in the path from A to B.
Although A* is kind of overkill when there are no obstacles, you might as well use it since I wrote a library for it in AS3: http://www.newarteest.com/flash/astar.html
EDIT: If you are anything less than 100% sure the pathfinding will never have obstacles then I still recommend A* because that gives you the most flexibility, but in your specific case it's pretty easy to find the path without obstacles because you only move once horizontally then vertically (or the other way around) as opposed to diagonally.
First subtract the x and y components of the positions to determine which way is longer and start moving in that direction. Then when the objects are in the same position on that axis, switch to moving in the other direction.
Depending on your needs you can easily build a loop or recursive function that finds the entire path before you traverse it, but it may be simpler to move the object in the correct direction without knowing the entire path ahead of time. While finding the path you need to loop through all the nodes anyway, so you could avoid having to loop through the nodes twice.

Resources