What is the Pseudo-Hillbert curve equivalent for hexogonal and triangular tesselations? - tesselation

Triangles, squares and hexagons can all be used to fill a surface (tessellation).
For now let's assume the surface has a limited number of tiles (triangles, squares or hexagons)
The goal is to define a line that touches each tile so that points that are close to each other or the line (1D) are also close to each other on the surface (2D).
The solution for a square based tesselation you have the (Pseudo)-Hillbert curve. Below is an example of a second order pseado-hillbert curve.
Explained in this fantastic video
I was wondering what the equivalent (if any) of the pseudo-hillbert curve for tesselations based on triangles or hexagons are. I am looking for a full tesselation so no holes as in a Sierpinsky Triangle.
I found this great resource
And for triangles using a Peano curve.

Related

Is there any "Geometry Contour Line Algorithm"?

I want to find & draw contour lines like this.
Data is just List of (x,y,z) and only a few points (about 40~60) in there.
(x and y are position and z is height)
How can i find this contour line and point?
As a first approximation, you can admit that your function is piecewise planar over a triangulation of the data points.
The Delaunay triangulation technique can be used, but in this case, given the regular polar arrangement, I guess that a simple rule based on the polar arguments could do.
Interpolating inside the triangles and obtaining the horizontal sections is a simple matter. Unfortunately, this will produce a gross approximation and you will probably notice artifacts due to the coarseness of the polylines.
A possible cure is to smooth the polylines as a postprocessing step, for instance turning them to polyBeziers.
Another method, which I prefer, is to use a higher order interpolation method. For C1 continuity, you can compute estimates of the gradient at the given points and fit quadratic functions on the triangles. Then subdivide the triangles in sub-triangles, interpolate the function at the sub-vertices, and switch to the planar model in these sub-triangles.
As that looks like an irregular grid, you should first build a mesh around it (for instance, from a Voronoi tesellation).
For every triangle, take the maximum and minimum heights of its vertices and find out the heights of the contour lines in that range (for instance, if you are drawing contour lines every 10 units and the heights of a triangle go from 11.5 to 34.2, the contour lines passing through that triangle are at heights 20 and 30).
Then approximating the height function inside the triangle as a linear function, find out where those contour lines lay and draw them.
The data for the contour plot could be generated with a two-dimensional simplification of the marching cubes algorith, which is described here. In the simplification, squares are used instead of cubes and four sampled values are used for the interpolation instead of the the eight corners of the cubes.
The simplification is also termed marching squares.

Creating a circular arc tangent to two curves with specified radius

The operation mentioned in the title is common in many Computer Aided Design (CAD) softwares such as AutoCAD, where it is called fillet. However, I found it is really difficult to implement this function in my own program.
The method I thought of is to use the condition that the distances of the arc center to the tangent lines of the curves are equal to the specified radius. Considering that actual curves are defined with piece-wise nonlinear functions, and the contact points could be anywhere on the curves, it is not easy to get the solution. Anyone good ideas?
Given that you don't describe in enough details the characteristics of the curves, it's hard to come with a specific/specified algo, but let's try a descriptive approach:
take a circle of the given radius and roll it on one curve until the circle touches the other one.
I assume you can parametrize you curves.
To "roll the circle" along the curve you need the tangent (or better said the normal, which of course is normal to the tangent) in the point "rolling track curve"-to-circle tangent point. You have this normal, you know the radius, you can compute your circle. You have the circle, you can see if/where it intersects the other curve.
The idea of "rolling" is to bracket your solution (parameter of the tangent-point on one curve) between a point when the circle does not intersect the other curve and another point where it intersects (possible in more than 1 point).
Once you have the bracket, go with a bisection method (binary search) between the two positions until your circle becomes "tangent enough" to the other curve (i.e the intersection points with the other curve are so close that they fall below your acceptable epsilon).
You will now have two points (one on each curves) and the circle that realizes the solution: just keep the arc on this circle corresponding what make sense (based on the convergence or divergence of the two tangents).
To find the arc center you need two robust and strategic algorithms:
Curve offset
Curve intersection
What AutoCAD does to find the arc center is to offset the two curves of the arc radius distance and intersect them. Depending on the curve offset direction you can easily switch between all possible solutions to the problem.
At this point, trimming the curves at tangent points will be trivial.

converting 2D perlin-noise into brick wall texture?

I would like to know how to make straight textures using 2D noise, to make stone squares of irregular sizes all jointed together (same as pic1): If there is a mathematical way to quantize 2D noise into orthogonal straight noise or jointed stone squares, please tell me the trick! (for a graphics shader brick wall texture generator)
if it is a mathematical impossibility, please tell me why?
You could try using 2D noise, but sampling adjacent points as though it was 1D noise, getting a series of strips of values. Then break those values into discrete groups, and whenever you run into a difference in group number, there's your break between bricks. And you would always have breaks between each horizontal strips.
To make a procedural 2d/3d similar to square stones, it would be easier to use a voronoi base, because it is already the concept of cells... if each cell has square borders it will make 2d/3d square cells.
voronoi compares the proximity of pixels to central points around it, it makes lines tangent to the points, as cell borders. i am not sure how to make them 90 degrees, but there must be a way.

Algorithm to produce rounded edges and corners in a 3D mesh

Starting with a 3D mesh, how would you give a rounded appearance to the edges and corners between the polygons of that mesh?
Without wishing to discourage other approaches, here's how I'm currently approaching the problem:
Given the mesh for a regular polyhedron, I can give the mesh's edges a rounded appearance by scaling each polygon along its plane and connecting the edges using cylinder segments such that each cylinder is tangent to each polygon where it meets that polygon.
Here's an example involving a cube:
Here's the cube after scaling its polygons:
Here's the cube after connecting the polygons' edges using cylinders:
What I'm having trouble with is figuring out how to deal with the corners between polygons, especially in cases where more than three edges meet at each corner. I'd also like an algorithm that works for all closed polyhedra instead of just those that are regular.
I post this as an answer because I can't put images into comments.
Sattle point
Here's an image of two brothers camping:
They placed their simple tents right beside each other in the middle of a steep walley (that's one bad place for tents, but thats not the point), so one end of each tent points upwards. At the point where the four squares meet you have a sattle point. The two edges on top of each tent can be rounded normally as well as the two downward edges. But at the sattle point you have different curvature in both directions and therefore its not possible to use a sphere. This rules out Svante's solution.
Selfintersection
The following image shows some 3D polygons if viewed from the side. Its some sharp thing with a hole drilled into it from the other side. The left image shows it before, the right after rounding.
.
The mass thats get removed from the sharp edge containts the end of the drill hole.
There is someething else to see here. The drill holes sides might be very large polygons (lets say it's not a hole but a slit). Still you only get small radii at the top. you can't just scale your polygons, you have to take into account the neighboring polygon.
Convexity
You say you're only removing mass, this is only true if your geometry is convex. Look at the image you posted. But now assume that the viewer is inside the volume. The radii turn away from you and therefore add mass.
NURBS
I'm not a nurbs specialist my self. But the constraints would look something like this:
The corners of the nurbs patch must be at the same position as the corners of the scaled-down polygons. The normal vectors of the nurb surface at the corners must be equal to the normal of the polygon. This should be sufficent to gurarantee that the nurb edge will be a straight line following the polygon edge. The normals also ensure that no visible edges will result at the border between polygon and nurbs patch.
I'd just do the math myself. nurbs are just polygons. You'll have some unknown coefficients and your constraints. This gives you a system of equations (often linear) that you can solve.
Is there any upper bound on the number of faces, that meet at that corner?
You might you might employ concepts from CAGD, especially Non-Uniform Rational B-Splines (NURBS) might be of interest for you.
Your current approach - glueing some fixed geometrical primitives might be too inflexible to solve the problem. NURBS require some mathematical work to get used to, but might be more suitable for your needs.
Extrapolating your cylinder-edge approach, the corners should be spheres, resp. sphere segments, that have the same radius as the cylinders meeting there and the centre at the intersection of the cylinders' axes.
Here we have a single C++ header for generating triangulated rounded 3D boxes. The code is in C++ but also easy to transplant to other coding languages. Also it's easy to be modified for other primitives like quads.
https://github.com/nepluno/RoundCornerBox
As #Raymond suggests, I also think that the nepluno repo provides a very good implementation to solve this issue; efficient and simple.
To complete his answer, I just wrote a solution to this issue in JS, based on the BabylonJS 3D engine. This solution can be found here, and can be quite easily replaced by another 3D engine:
https://playground.babylonjs.com/#AY7B23

Merge overlapping triangles into a polygon

I've got a bunch of overlapping triangles from a 3D model projected into a 2D plane. I need to merge each island of touching triangles into a closed, non-convex polygon.
The resultant polygons shouldn't have any holes in them (since the source data doesn't).
Many of the source triangles share (floating point identical) edges with other triangles in the source data.
What's the easiest way to do this? Performance isn't particularly important, since this will be done at design time.
Try gpc, or the General Polygon Clipper Library.
Imagine the projection onto a plane as a "view" of the model (i.e. the direction of projection is the line of sight, and the projection is what you see). In that case, the borders of the polygons you want to compute correspond to the silhouette of the model.
The silhouette, in turn, is a set of edges in the model. For each edge in the silhouette, the adjacent faces will have normals that either point away from the plane or toward the plane. You can check this be taking the dot product of the face normal with the plane normal -- look for edges whose adjacent face normals have dot products of opposite signs with the projection direction.
Once you have found all the silhouette edges you can join them together into the boundaries of the desired polygons.
Generally, you can find more about silhouette detection and extraction by googling terms like mesh silouette finding detection. Maybe a good place to start is here.
I've also found this[1] approach, which I will be trying next.
[1] 2d outline algorithm for projected 3D mesh

Resources