I hope that this is not the wrong place for my question, however, when I don't have anywhere else to go, SO never lets me down.
I am looking for a way to convert any given polygon on a map, to a serpentine line string. I would like to pass the polygon as a geography data type (it could be a poly string) which then takes the polygon, and generates a line string covering the entire area of the polygon.
The below images illustrates perfectly what I want to achieve in the sense that I want to provide the blue polygon and I want the green path to be returned either as a collection of points or a geography data type:
Taken from https://robotics.stackexchange.com/questions/14539/generate-a-coverage-path-given-a-polygon-region
I have scoured the internet and cannot seem to find any code examples around how to get this done. I would like to do this in C# preferable but I am not too fussy about the language. Second to C# I can look at using SQL too or even Python as a last resort.
I have read countless articles on Path planning but they all seem to be overkill in terms of what I want to achieve.
Could anybody point me in any direction as to how I can achieve this? Any information or samples will be highly appreciated.
I have thought about breaking the polygon down to its boundary lines and draw a serpentine line string across it by manually checking if a given point is within the bounds of the polygon. Surely there has to be a more efficient way to achieve this? Maybe a ready made API of some sort?
Related
I'm going through OpenGL 3.3+ tutorial written in C++ and I'm converting my code to C# (using OpenTK). In the tutorial there's a VectorBufferObject using vector<BYTE> to hold data for buffer. Unfortunately I did not manage to achieve same functionality using List<byte>, because I was unable to convert Vector3 to byteArray the way it could be used by DrawArrays function.
But well, I've decided to store List<float> instead and following the tutorial I store all floats (3 for position + 2 for texture coords for each vertice) in a single List of VectorBufferObject.
Apart from not rendering textures properly (my mistake I believe, not important at the moment really) it should work just fine, BUT - it should render a cube and a pyramid rotating - it does render a triangle and a rectangle. I've checked it with PolygonMode.Line and I can tell that the rectangle is made of more than 2 triangles (it has box-type lines going across, not a single one that should be there when drawn with 2 triangles)). I therefore suspect they are drawn one over another. I can't figure out why really.
Below is source code of relevant classes. Please ask if there is a need for more information.
#EDIT
Despite my huge hope of following the tutorial, I'd consider an alternative, not overly complicated alternative to that solution.
RenderingEngine.cs
http://pastebin.com/gtnX4ESg
VectorBufferObject.cs
http://pastebin.com/veGwybp7
Static_Geometry.cs
http://pastebin.com/K1bJ8z8u
I am getting coordinates - lat/lon and I want to check if these coordinates are in the continental United States or not. Is there a easy way to do it in C#? I can convert the coordinates into MGRS or UTM.
Thanks!
Oh wow, they have it just for you:
http://econym.org.uk/gmap/states.xml
All the coords of the US states!
Build up a polygon and apply any polygon-contains-point algorithm.
The classic algorithm is ray-casting, and its even pretty simple. Let me know if you have any trouble with it.
Now, you have two options:
Use the data to build a polygon for each state, and check a point with each one of them. If none match, it is not in the US.
However, there is a problem with that approach - I don't know how the data was gathered, but its possible that there are very little gaps between states, or even slight overlaps. So if you only care if its generally in the US or not, I suggest the second approach:
Use the data to build a polygon for each state, and an algorithm to combine those polygons to one (like union). Save that polygon and use that as with the 1st approach.
say I have these boxes, some of which are black and some white.
The image shows a U shape drawn with the black boxes. Now say I have a matrix of 1s and 0s (it can be a huge matrix) like this:
111111111111111111
111111111111111111
111111111111111111
111111111101111111
111111111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111100000011111111
111111111111111111
which shows zeros forming roughly the shape shown in the image. The image and the matrix are just examples. The image is a screen shot of a software where we should draw patterns, which would then need to be located in given matrices (inside simple text files).
What I'm looking for is a guidance on how to get started on this, cuz I have never programmed anything related to pattern recognitions, which this problem clearly seems to be related to. This is all that I have to do, a pattern given, to be matched with matrix of 0s and 1s. I dont think I can write it on my own in a few days, I'm writing code in c# vs 2013, so hoping I can find some libraries that would let me achieve this with minimal dependencies. Thanks
I think you need to provide a bit more information on what exactly you're looking for. Are the shapes all letters or arbitrary shapes?
Whatever you're looking for I'd start with emguCV. It's a pretty comprehensive library that isn't too difficult to use.
EmguCV has a lot of OCR (optical character recognition) functions which should be able to pick out letters pretty well.
I don't have as much experience using it for arbitrary shape detection but I think SURF detection, something which emguCV also does, might be a good way to go. It attempts to match a given image with features in another image.
People never draw at the exact same place and scale as your stored data.
The things you want are often done with neural networks (its also in aforge).
But it might be hard to A understand it and B use it in your code.
So maybe you could try it like this, get the first position, then record the delta position.
Try to find long lines, and their next direction; store the general direction changes.
above sample would be "down right up", you might also store some length info.
Then there is some math to check how much different sets are, for example string comparisons distance of strings (like in php the levenshtein function); cant think of a levenshtein func in c# dough i dont think c# is that rich with string functions but once you see that i'm sure you can derive something for C#.
I'm trying to make a truncated icosahedron, though with more subdivision (so more hexagons)
In the game I use it, eacht pentagon and hexagon is a separate object. So after generating the icosahedron, I just use the generated points to place either a pentagon or a hexagon on it (instead of doing the find-middles-of-each-triangle-thing, I do this since I need them to be separate object anyway.) I have some questions about it though, and google doesn't really help, so I'm hoping there are some smart smath-knowing people here :D
Here we go:
Am I assured that the length of each sides is equal?
Since each hexa/petagon is a separate object, I need to rotate them to get them positioned properly, any help with this?
Assuming I have hexa/petagons with a radius of 1 (one), how far for the middle do I have to position them? (Basecly, whats the relationship between the radius of my hexa/pentagons and the radius of my truncated icosahedron.)
Here's my first test, I generated a icosahedron and then on each point put a pentagon model, which I rotate so it's pointing away from the middle. As you can see they still need to be rotated to fit together (question 2) and their distance to the middle has to the tweaked aswell (question 3).
I'll continue on working on this too, though all help will be appreciated! (I'm making this in Unity, using c#, so if you give sample code, it would be really really awesome if you use that.)
Thanks a lot!
Well, not the answer to your questions but maybe worth thinking about:
Wouldn't it be easier to start with a ready made Blender, Maya, ... model of a soccer ball like for example this one on Blend Swap, change it to fit your needs. Or do it on your own as there are a couple of YouTube tutorials. Then you will have far more options like LOD, materials. You can design it in Blender with each pentagon/hexagon as single object and so it will be imported in Unity.
I want to create tiles out of a equirectangular image. So I want the image to be split into 4 lateral faces+up and bottom. Does anyone know any library that I can import into my c# project and which is able to do something like this?
Depending on your original image format, System.Drawing.Bitmap.Clone(Rectangle, PixelFormat) should do the trick.
More information here.
EDIT:
First, let me say that this is not going to answer your question either (not even close), you're seeking a library that already exists for this purpose and I don't know of one personally.
Equirectangular projection is the same as plate carrée (wow, that's humbling), so it's a very simple projection to work with in code.
Here is an example of it's use in a GIS application. I don't know what your purposes are, but the math is the same.
One way to do it is to deproject each pixel then draw it on a new image, but understand that to do this you will still require some sort of projection because you're changing from 3 dimensions to 2 dimensions.
I wasn't able to find a good example, but an easier or faster way might be to first use a matrix transform (again, to change projections), then cut the image into the regions you need.
Like I said, this isn't an asnwer, but if nothing else it will give you more keywords to goggle for.