AR application that recognizes 3D formulae and visualizes them in an AR environment
An algorithm to approximate implicit surfaces. This is used in this project to generate the 3D plots of the surfaces described by 3D formulae.
- Paper on Dual Contouring on Hermite Data
- Blog describing point generation in Dual Contouring
- Blog describing meshing points together after point generation
Dual Contouring comprises of 2 main steps:
- Point Generation
- Meshing of points
-
Sample points in 3D space at fixed and regular intervals, according to some function of all 3 axes,
$f(x, y, z)$ . The point will be on the surface if$f(x, y, z) = 0$ . -
Now traverse the samples in the form of 3D cubes/cells. Each cell considers 8 points at a time.
-
Each edge in the cell is checked for intersections, where an intersection has occurred if the sample al each end of the edge has a different sign.
$$\Large p \Rightarrow \text{"Surface passes through cell"}$$ $$\Large \exists (u, v) \in cell, \dfrac{f(u)}{||f(u)||} \neq \dfrac{f(v)}{||f(v)||} \Leftrightarrow p \mid u,v \in \mathbb{R}^3$$ -
For each edge with an intersection, "binary search" could be used to narrow the intersection point such that
$f(x, y, z) \approx 0$ -
Get normals of each intersection point on the surface
-
Differentiate using the limit definition
$$\Large \dfrac{\partial f(x, y, z)}{\partial x} = \underset{h \to 0^{+}}{\text{lim}} \dfrac{f(x + h, y, z) - f(x - h, y, z)}{2h}$$ -
Using the points of intersection and the normals at those points, a singular point within the cell is solved for, using the following formula
$$\Large \underset{x\in\mathbb{R^3}}{\text{min}}\space E[x] = \underset{i = 1}{\overset{k}{\sum}}(n_i \cdot (x - p_i))^2$$ $$\Large p_i \Rightarrow i^{\text{th}} \text{ point of intersection on an edge}$$ $$\Large n_i \Rightarrow \text{normal at }p_i$$ -
This can be represented as matrix operations
-
In the end, you must solve for
$x$ , which gives the location of the point with least error, corresponding to all normals on intersection points in the cell.$$\Large Ax = b$$ -
NOTE : If all normals on intersection points in the cell point in the same direction, there may be infinite solutions for
$x$ , even residing outside the cell. -
To fix this, we can add a small bias towards the "Center of Mass" or average of intersection points within the cell.
- From the perspective of an edge in sample space, if there is an intersection through it, there must exist a point generated on the surface of the implicit surface in all the 4 cells that share that edge
-
This is true because if an edge has an intersection, it will have contributed to generation of a point within the cells that share that particular edge.
-
In order to take care of backface culling, the quad must be meshed together in clockwise direction from the perspective of the point on the edge which is outside the surface.
-
If the inside of the surface also must be defined, then define the quads in clockwise and anti-clockwise manner, regardless of the perspective of the points.