When getting the vertices of an H3 cell using H3toGeoBoundary, how many possible vertex configurations can the GeoBoundary struct produce? I count four:
6 vertices: regular hexagon
5 vertices: regular pentagon
7 vertices: irregular hexagon (https://observablehq.com/#nrabinowitz/h3-index-inspector#85080013fffffff)
10 vertices: irregular pentagon (https://observablehq.com/#nrabinowitz/h3-index-inspector#85080003fffffff%0A%0A)
Is this list exhaustive or can other configurations exist? Would it also ever produce 0?
Your list is missing the 8 vertices case. Rather than using the generic term "irregular", it's more accurate to consider extra distortion vertices: At odd resolutions, cell edges that cross an edge of the icosahedron will have additional distortion vertices added to account for the change in projection plane (at even resolutions, the cells are aligned with the icosahedron edges and do not require this). With that explanation, the list looks like this:
5 vertices: even-resolution pentagon cell (8408001ffffffff)
6 vertices: standard hexagon cell (85283473fffffff)
7 vertices: hexagon cell with an icosahedron edge crossing one vertex and one edge (85080013fffffff)
8 vertices: hexagon cell with an icosahedron edge crossing two edges (850802a3fffffff)
10 vertices: odd-resolution pentagon cell (85080003fffffff)
Note that we still use "pentagon" and "hexagon" to describe these cells, because that's still topologically correct (a pentagon always has 5 neighbors, a hexagon always has 6).
Related
Given some rectangles inside of a larger rectangle, is there any algorithm to split the remaining space into rectangles, and preferably as few as possible?
One way to solve the problem is to reduce the rectangles to a mesh. Each rectangle corner becomes a vertex (x,y) and each rectangle's side is a line that references two vertices. Vertices that are on a line (eg two rectangle are touching) must split the line at that vertex. There may only be one line joining any two vertices. The bounding rectangle is included.
Once you have the rectangles converted to a mesh then for each vertices count the number of lines that use that vertex.
If a vertex has only 2 lines joining it and is not a bounding corner, then it must be extended, it will have two optional directions, horizontal and vertical. There is no rule in which direction is the best so pick a random direction. In that direction and moving away from the lines coming to the vertex add a vertex to the closest intersecting line. Continue the process until no vertices (apart from the bounding corners) have less than 3 lines connected to it.
Now start at the top left most vertex and trace the lines in a clockwise direction, each 4 lines is a rectangle when you get back to the starting vertex you have a new rectangle Use the min and max vertex coordinates in the x and y direction to define the size of the rectangle. For each line decrease its vertices line count by 1. When a vertex has a line count of zero remove the vertex; When all vertices are removed you are done.
This will create the minimum number of rectangles possible.
To know if a solution is the minimum rectangle count check that each vertex has ONLY 3 lines joining it (Your example image is the minimum number of rectangle because no vertex has more than 3 lines joining it)
The only exception to this rule is if the existing rectangles are touching at a corner. Only existing vertices may have 4 lines joining.
Using a bsp tree: insert each rectangle edge in the tree. This will partition the space into convex subsets. Since your input are rectangles, the convex subsets can only be rectangles (https://en.wikipedia.org/wiki/Binary_space_partitioning).
Note that the partition depends on the order in which you insert the edges.
I'm not sure though that this will give you the minimum number of rectangles, but you will get close.
I have two 3D convex, flat, polygons P0 and P1. I wish to detect if they collide. I will use the separating axis theorem. In this theorem a subset of the test axes are generated from the cross products of pairs edges in P0 and P1
axes = for all
| 0 <= n < N ; N is the count of edges on P0
| 0 <= m < M ; M is the count of edges on P1
Vector3.Cross(P0.Edge[n].Vector,P1.Edge[m].Vector);
However what is missing in all descriptions of the SAT I have found is what to do when the cross product of the two generating vectors is zero.
I'm of two minds. I can either
Discard this axis from the test set
Generate a random axis in the plane normal to the two edge vectors
Or perhaps there is another correct way to handle this problem.
You can safely discard it.
The reason is this: If the cross product is zero, it means the two edges are parallel. If the two edges are parallel, then the 4 faces that are adjacent to the two edges can be projected onto 2 dimensions using the vector of the two parallel edges as your Z, and collapsing this dimension: faces become edges, edges become vertices. You can picture these 4 faces as the edges of a polygon that has been extruded along the vector. In the 2D version of the separating axis theorem you only need to consider edges, not pairs of vertices.
So if there is a separating plane that intersects either of these two parallel edges, one of the adjacent faces will also be a separating plane, and these faces are considered separately in the algorithm. The algorithm only needs to find one separating axis, so the faces will take care of it.
You can visualize this fairly easily. Picture 2 non-intersecting convex figures with 2 parallel edges held close to each other. It's fairly easy to see that one of the 4 adjacent faces always forms a separating plane, and that this isn't the case if you rotate the figures so that the edges are no longer parallel.
Given a mesh consisting of a list of vertices (2D coordinates) and edges (as vertex pairs), like so:
So the edges are defined like this:
a: 2,3
b: 3,4
c: 4,8
d: 5,8
e: 6,7
etc..
Edges are orientation-neutral, i.e. the order of any two vertices that define an edge is random (edges are not clockwise or counter clockwise).
Polygons may be convex or concave, but they never overlap or self-intersect (edges never cross eachother).
Question: how do I generate a list of all polygons?
More specifically, in the above example I would need 4 polygons, like so:
(a,b,c,d,i)
(d,g,h)
(f,i,j,k)
(e,h,k)
The polygons have no orientation either, clockwise or counterclockwise does not apply, and in fact the order of the edges that define a polygon may be random as well. For example (a,i,d,b,c) for the 5-sided one would be fine as well.
Instead of defining polygons as a list of edges, it could also be a list of connected vertices, like so:
(2,3,4,8,5)
(6,5,8)
(2,5,7,1)
(7,6,5)
In this case, the order of the vertices cannot be random (the list of vertices should be a circular sequence) but orientation (clockwise or counterclockwise) is still irrelevant. So the 4-sided polygon could also be (5,2,1,7) or (1,7,5,2) et cetera.
What is an efficient (fast) way to construct a list of polygons, defined in either edges or vertices?
For each edge vw, generate two half-edges v->w and w->v. Partition these by head (the head of x->y is y). Within each partition, sort by angle (if you use a comparison sort, then there's a way to avoid trig).
For your sample graph, the result is
7->1, 2->1
1->2, 5->2, 3->2
2->3, 4->3
8->4, 3->4
7->5, 6->5, 8->5, 2->5
8->6, 5->6, 7->6
6->7, 5->7, 1->7
5->8, 6->8, 4->8
. Now, define a permutation where v->w maps to the half-edge following w->v in the list containing w->v (wrapping around if necessary). The cycles of this permutation are the polygons.
For example, 5->8 maps to 2->5 (after 8->5) maps to 3->2 (after 5->2) maps to 4->3 (after 2->3) maps to 8->4 (after 3->4) maps to 5->8 (after 4->8).
I have a volume mesh which is actually a tetrahedral mesh. I would like to calculate the cross-section of this mesh given a plane function, saying z = 0. I can imagine that the cross section of a tetrahedron is either a triangle or a quadrilateral. For the first case, triangle, once I calculate the 3 cross points I can get it; but for the second case, how can I make the quadrilateral become 2 triangles? My problem is I cannot determine the diagonal of the quadrilateral.
Intersect all tetrahedron edges by the plane. You will get 3 or 4 intersection points.
If 3 points then a single triangle.
If 4 points, they form a convex quadrilateral. Take any 3 points, that form a first triangle. The other triangle if formed of the fourth point and the two endpoints of the edge that has this point to its right.
Alternatively (for a more general solution), tag the intersection points with the indexes of the faces incident on the edge, and reconstruct the ring of labels.
Ex: edges are common to faces AB, CD, DA and BC; then the section is ABCD.
This answer outlines a general volume-plane intersection algorithm. It will return the vertices of the intersection in order, so it's easy to determine the diagonal of your quadrilateral.
I want to draw a Voronoi diagram with 9 sites and with
1. no vertex
2. 1 vertices
3. 4 vertices
4. 7 vertices.
How do I approach this question. The one with no vertex is easy, it can be done by collinear points.
What about the others.
A figure for each would be appreciated.
Simple examples are:
4 vertices: Tic-tac-toe configuration,
7 vertices: configuration of sites on 3 rays going from same
point equidistantly positioned. Vertices are ray origin point and 3 times by 2
vertices between rays.