I need to implement an algorithm which involves building a complete graph using JavaScript functions as first step.
Are there any fast ways (like libraries or build-in functions I can use? Or may I get some suggestions on how to set up the data-structures efficiently and easily using JavaScript?
Further more, given n vertices, after building a complete graph,
for each iteration:
Try vertex-cover like thing,(if there'are odd number of vertices, just leave the last one alone) and then store the pairs of vertices for each edge in the vertex cover, and then remove the edges involved in that vertex cover, and then sort the vertices by orders that has biggest number of edges remaining to be removed
and then looping doing so, until no edges been left in the graph.
Thank you very much.
Related
Can any one help me to figure out how to fetch content of all vertex which are connected each other in javascript , I need all the values of all vertex which are connected
For example in below diagram I have a business vertex and there are two outgoing edges from business , what I need is all the contents of business vertex and video and image vertex
graph look like this
Gremlin provides a variety of ways that you might be able to handle this as your description of the desired results was a bit vague. However you will want to use a combination of traversing steps (out() step), filtering steps (has()/hasLabel()) combined with the path() step to get the list of vertices and then return the data using elementMap(). I have put a demonstration of this here:
https://gremlify.com/a78ox51u9os/1
I am working on a system to procedurally build meshes for "mines", right now I don't want to achieve visual perfection I am more focused on the basic.
I got the point in which I am able to generate the shape of the mines and from that generating the 2 meshes, one for the ground and one for the "walls" of the mine.
Now I am working on getting the UV mapping right but my problem is that the ground is really hard to map to UV coordinates properly and I am currently not able to get it right.
For the tessellation I am using a constrained version of the delaunay triangulation to which I added a sub-tessellation what simply splits the triangles at least once and keeps splitting them if the area of the triangle is greater than X.
Here a 2D rendering of the tessellation that highlight the contours, the triangles and the edges
Here the result of the 3D rendering (using three.js and webgl) with my current UV mapping applied (a displacement map as well, please ignore it for now).
I am taking a naive approach to the UV mapping, each vertex of a triangle in the grid is translated to values between 0 and 1 and that's it.
I think that, in theory should be right, but the issue is with the order of the vertexes that is creating a problem but if that would be the case the texture should be shown rotated or oddly not just oddly AND stretched like that.
Once I will get the UV mapping right, the next step would be to correctly implement the
I am currently writing this in javascript but any hint or solution in any language would be alright, I don't mind converting and/or re-engineering it to make it work.
My goal is to be able to procedurally build the mesh, send it to multiple clients and achieve the same visual rendering. I need to add quite a few bits and pieces after this other step is implemented so I can't rely on shaders on the client side because otherwise being able to place tracks, carts or something else on the ground would just be impossible for the server.
Once I will get these things sorted out, I will switch to Unity 3D for the rendering on the client side, webgl and three.js are currently being used just to have a quick and easy way to view what's being produced without the need of a client/server whole infrastructure.
Any suggestion?
Thanks!
I sorted out the issue in my code, it was pretty stupid though: by mistake I was adding 3 UV mappings per triangle and not 1 per point causing an huge visual mess. Sorted out that, I was able to achieve what I needed!
https://www.youtube.com/watch?v=DHF4YWYG7FM
Still a lot of work to do but starts to look decent!
I'm working on a way to turn the information from 3d-files into THREE geometries. I receive them formated like this:
{"N":"name of the block","V":[[0,1,2]..[N1,N2,N3]],"F":[[0,1,2]..[M1,M2,M3]],"P":[[O1,O2,P3,..,Op]..[..]]}
N should be obvious. It's the name of the geometry.
V is an array of vertices.
F is an array of triangular faces.
So far so good. That's easy to convert into THREE geometries. P is the tricky part. It's an array of polygons. A polygon is in this case a face consisting of a number of vertex indices bigger than four.
There's no actual restriction how many vertex indices may hold, apart from the minimum of five.
Is there any working way to convert a structure like this for THREEjs?
three.js supports a Face3 class only. It used to have a Face4 class, but you need something completely different to handle polygons. The short answer is no, three.js does not handle this out of the box.
A simple way to tackle it is to create a fan out of your polygons by fixing one vert, and looping through the rest, but this will work only on convex polygons.
https://en.wikipedia.org/wiki/Polygon_triangulation
Not a trivial problem.
I have lots of line segments (that represent various surfaces such as walls, ceilings and floors). I want to efficiently determine which lines are within the player's bounding box.
(Right now I'm cycling through all lines, and whilst correct, it is proving much too slow).
There are several kd-tree and other spatial indices in Javascript but they all store points rather than lines.
I actually only need to query by the x axis; it would suffice with a 1D range tree of some sort.
How can you efficiently store and retrieve shapes such as lines?
Once built, the index would not be added to.
In just 2 dimensions, where you have good control over the total spatial extend (i.e. know min and max, and these won't increase), grid based approaches such as plain grids or quadtrees work incredibly well. In particular, if you know your query radius (the players box size), a grid of exactly this size should work really well.
Many games also used what is called a BSP tree, a binary space partitioning tree. But for good performance, this tree is AFAIK usually precomputed when the level is built, and then just loaded with the map.
In this tutorial author displays a cube by defining its 6 faces (6*4 vertices) and then telling webgl about triangles in each face.
Isn't this wasteful? Wouldn't it be better to define just 8 vertices and tell webgl how to connect them to get triangles? Are colors shared by multiple vertices a problem?
To make my concern evident: if the author defines triangles with indices array, why does he need so many vertices? He could specify all triangles with just 8 vertices in the vertex array.
Author of the example here. The issue is, as you suspected, to do with the colouring of the cube.
The way to understand this kind of code most easily is to think of WebGL's "vertices" as being not just simple points in space, but instead bundles of attributes. A particular vertex might be be the bundle <(1, -1, 1), red>. A different vertex that was at the same point in space but had a different colour (eg. <(1, -1, 1), green>) would be a different vertex entirely as far as WebGL is concerned.
So while a cube has only 8 vertices in the mathematical sense of points in space, if you want to have a different colour per face, each of those points must be occupied by three different vertices, one per colour -- which makes 8x3=24 vertices in the WebGL sense.
It's not hugely efficient in terms of memory, but memory's cheap compared to the CPU power that a more normalised representation would require for efficient processing.
Hope that clarifies things.
You can use Vertex Buffer Objects (VBO). See this example. They create a list of Vertices and and a list of Indexes "pointing" to the vertices (no duplication of vertices).