Pathfinding, possibly B-Spline - c#

I'm writing a program in C# that will allow me to take in my current heading, my current location, and the next two points I want to come across along my path and I want to output the angle at which I should currently be turning to follow an arc that will allow me to go to the next two points in my path.
Is there a library that will let me do this? Also, I've done a little research, and it looks like something called B-Spline might be useful, but I've no idea how to implement it. Is there a library for that? Also, it appears that Bsplining requires 4 points, and disregards current heading, so that might be an issue.

You can do B-Spline interpolation with derivative constraints for the current heading. You only need at least two points for interpolation. I'm not sure if there is a C# library for that, but you can find whatever is out there on Google.
I do know that algorithms for doing this are made accessible in The NURBS Book, which one could easily implement in C#.

There are several methods for B-Spline interpolation, such as adaptive,uniform.
There is a javascript demo for it.
http://wangweiqiang.net/lib/b-spline/

Related

What's the fastest way to validate if a GeoJson Polygon contains a certain section, using .net

I have a Polygon (a sequence of 2D-points) loaded (I can parse from GPX, Google polyline and GeoJson) in my C# program. And I have around 1000 of 'segments' that also are GeoJson Linestrings.
Some of these segments are 'far away' off the track, while others could perfectly intersect with the track. My question is what the fastest way (ideally using an existing in memory library) would be to detect which segments are part of the overall track. (The points obviously don't have to match 100%, but can be a few meters off the track)
Consider the situation where I have a recorded GPS-track (of a car for example) and I want to check against a library of streets if that track has been driving through those streets. (ideally in the specified direction, if possible)
So, my main questions:
Is there an out of the box open source library available that has implemented this?
If not, I'm happy to contribute it, but then I'm looking for a good description of such an algorithm.
Further clarification
I have indeed found several options to work out if a point is inside , or on a polygon. (see here).
But the main challenge is to find out if someone has done this before in .net and to understand if there are out of the box possibilities for this.
Any help is appreciated.

Given a set of random points that are randomly linked, how to position them so that their link lines do not intersect?

I have a set of points, the coordinates are not predetermined and I can set them when I create them, but their links are predetermined. A point can have one or more links, but not zero.
I want to be able to generate a visual representation of these points at positions where these link lines between them will not intersect. From what I've learned in researching so far, I believe this will be somewhat similar to a planar graph, however there will be points with only one link, and I'm not sure planar graphs are able to represent these.
I'm not sure if there is a good way of doing what I am trying to do or not, but I'll admit that maths is not my strong suite. My 'best' idea so far is to somehow detect these intersections and then move points in a direction that somehow takes the intersection location into account to reposition them so that that particular intersection does not occur....and to loop and do this for every point until no more intersections are detected. However there could well be some sort of more efficient mathematical algorithm that I could use instead that I am simply unaware of.
I'm interested in all advice here, whether it is efficient or not.
This is not an easy problem. Here are the Google search results for “algorithm to draw a planar graph”. The Boost C++ Library has some support for drawing planar embeddings including an example. These of course use C++, not the C# you tagged the problem with.

Wanted: C# programming library for mathematics

What I need is: plots creation, stuff for interpolation, stuff for counting such things as
and
where L(x) is an interpolation built from some data (points) generated from original known function f(x). meaning we know original function. we have a range (-a, a) - known. We need library to help us calculate data points in range. we need to calculate L(x) a polinom using that data in that range.
I need this library to be free and opensource
Perhaps Math.NET can help you.
Check this other answer https://stackoverflow.com/questions/1387430/recommended-math-library-for-c-net, in particular several people think that MathDotNet is nice.
For plot creation, you may want excel interop (why not ?), or ILNumerics.NET.
But I don't understand the other requirements. You want to measure interpolation errors (in the max and L1 norm) from a function you don't know ? This is not a programming question, it is a math question.
I suggest you look at interpolation libraries (Math.NET contains one for instance, but many others also do) and see if they provide such things as "error estimation".
Otherwise, what you need is a math book which will explain you the assumptions on f that you need to estimate the interpolation error. It depends on what you know about the regularity of f and the interpolation method.
Edit, regarding additional information provided: There are closed form formulas for interpolation errors (here as a starting point). But any numerical integration routine (which Math.NET does not provide) will get what you want. Have a look at libraries other people pointed out, this link will get you started.
Since you seem to have regular functions (since you do polynomial interpolation), I'd go with simple Romberg integration, which is quite simple to implement in case you don't find a library that suits your need (I doubt it). Have a look at Numerical Recipes, 3rd edition for sample code.
What about using Mathematica?
Math.NET and ILNumerics.Net are both open source and will both solve your equations.

AI navigation around a 2d map - avoiding obstacles

I know my question seems pretty vague, but I can't think of a better way to put it, so I'll start off by explaining what I'm trying to do.
I'm currently working on a project whereby I've been given a map and I'm coding a 'Critter' that should be able to navigate its way around the map; the critter has various other functions, but those are not relevant to the current question. The whole program and solution is being written in C#.
I can control the speed of the critter, and retrieve its current location on the map by returning its current X and Y position, I can also set its direction when it collides with the terrain that blocks it.
The only problem I have is that I can't think of a way to intelligently navigate my way around the map; so far I've been basing it on what direction the critter is facing when it collides with the terrain, and this is in no way a good way of moving around the map!
I'm not a games programmer, and this is for a software assignment, so I have no clue on AI techniques.
Here's a link to an image of what the maps and critters look like:
Map and Critter image
I'm in no way looking for anyone to give me a full solution, just a push in the general direction on map navigation.
If the only knowledge of the environment that you have is the position of your critter and its velocity the best you can do is a wall following algorithm I think. If you can detect some of the other things in your environment you have many more options.
Some of the more popular algorithm types are...
A* Search (The classic)
Visibility Graphs
Voronoi Diagrams (similar to the above)
Potential Fields
Potential Fields is a fancy way of saying every obstacle or wall has a "repulsive force" while every goal has an "attractive force". The strength of the force is based on the distance from the object and the "severity" of the object. (A pit of lava is much more severe to travel through than a bumpy road) After constructing the force fields the naive algorithm boils down to following the path of least resistance. Better versions can detect local minima and maxima and escape those wells.
Critter
-----\ /-------\
\ / \
\/ \
Local Minima Trap \
\
\
Goal
A* Search
Take a look at the A* pathfinding algorithm. It's essentially the standard approach for stuff like this.
Amit Patel's write up on pathfinding for games has a pretty good introduction to A* as well as popular variants of the algorithm.
You'll find a C# implementation here, and here
Dynamic A*
Let's say the terrain you'll be searching is not known ahead of time, but rather is discovered as the agent explores its environment. If your agent comes across a previously unknown obstacle, you could just update the agent's map of the terrain and then re-run A* to find a new path to the goal that routes around the obstruction.
While a workable solution, rerunning the planning algorithm from scratch every time you find a new obstacle results in a sizable amount of redundant computation. For example, once you're around the obstacle, it might be that the most efficient route to the goal follows the one you were planning on taking before you discovered the obstacle. By just rerunning A*, you'll need to recompute this section of the previous path.
You can avoid this by using Dynamic A* (D*). Since it keeps track of previously computed paths, when the agent finds a new obstacle, the system only needs to compute new routes in the area around the obstacle. After that, it can just reuse existing paths.
I would use a goal-oriented approach. Your question states the goal is than explore the map and avoid obstacles, so that's what we make our goal. But how do we explore the whole map? We explore what is unexplored.
From the outset you have only one unexplored area, the square you are on. The rest of the map is marked as unexplored. You choose an unexplored location, and make it your goal to explore it. But how do you get there? You create a subgoal to explore the location next to it. And how do you do that - explore the square next to that, and so on, until your original goal is broken down into a sequence of explorations, starting from your current square and navigating to the target square.
As you hit obstacles and discover features of the map, some of the subgoals may need to be changed. E.g. when you hit a wall, the subgoal to explore that square has to be scrubbed and you create a new plan to find an alternate route. This is known as backtracking.
That's basically it for the high level description. I hope it helps!
I seem to be late at the party. If your critter have a GPS and the full map at hand, the right thing to do is definitely A*, and if the map is small enough a simple BFS would do as well if you don't feel like coding up A* (A* has quite a few corner cases you want to handle right).
However a different question is what if your critter only knows the direction of the goal and can only observe locally what is around it? What if your critter does not know the full map?
In this case you would want to implement the "bug algorithm" for navigation. Link: http://www.cs.cmu.edu/~./motionplanning/lecture/Chap2-Bug-Alg_howie.pdf
It's a cute piece of algorithm that works for all unknown maps, you would have a blast coding it I'm sure.

Boundary representation data structure

I've been reading about using the winged-edge data structure for storing a boundary representation. However, the linked site says that this is one of the oldest data structres for storing b-reps, are there newer better ones?
Secondly, is there an implementation of this in C#?
The datastructure used for a B-rep is very similar to those used for polygonal modeling - you just replace the edges with curves and the faces with surfaces.
The wikipedia page on polygonal meshes has several types listed, including winged edge. Personally I like half-edge meshes. The only thing they can't do well is non-manifold topology, which you may or may not need. If you do, look for radial edge topology.
There's also a freely available B-rep datastructure from OpenNurbs (McNeel, the makers of Rhino). That also gets you file IO, which is nice.
Boundary Representation Modelling Techniques by Ian Stroud will give you a survey of ways people have approached B-reps, along with a plethora of diagrams with all the Euler operators, and concrete data structures and algorithms for implementing B-reps imperatively.
Whether you want to move a few characters forward into F# or not, you may glean quite a bit of info from the source code for Wings3d (written in Erlang). Just don't get lost making spaceships and forget you were supposed to be coding!
Also the GML will allow you to investigate interactively what you can do with your B-reps, and the data structure is the code.
Not sure if this will help or not but there are Geometry objects in the XNA library for dealing with 3D Structures and what not. There may be something in there. However my guess is that it will either be Point based or Triangle based vs edge based.
But it might be a place to look.

Categories