# Addon for triangulation of implicit surfaces/ forms with holes

The THREEi addon is used to create indexed geometries for implicit surfaces and forms with holes. Update: August 8th

Added a version with limitation for infinite surfaces (e.g. cylinders) or cut surfaces by a limitation of the coordinate. It requires more code and execution effort, it is internal realised as an additional function. Description adjusted here. Update: September 24th Update: October 7th

Another variant of the sphere with holes was added. The rough side length of the triangles is to be indicated as with the cylinder. This allows the shapes to be joined together exactly. Update: October 18th

The algorithm for the sphere with holes previously contained no check whether the current front overlaps. In very many cases with few holes this is not a problem. But it can lead to errors in more complicated cases! The overlap check has been completed.
The older, simpler and less expensive version of the sphere with holes was saved separately: THREEi_ONLY_SphereWithSomeHoles.js Update 07th February 2020 InnerGeometry, combines sphere, cylinder and other - with holes

Algorithm based on E. Hartmann.

The algorithm was originally implemented in Pascal and visualized with POV-Ray.

The implementation of the algorithm with three.js/JavaScript deviates from the template in some places.

siehe / see

en:

The addon THREEi.js capsules in the section … ImplicitSurface - Triangulation … the functions

function triangulation( isf, dx, dy, dz, xs, ys, zs, d, e, fc, pc )
function triangulationBounds( isf, dx, dy, dz, xs, ys, zs, d, e, fc, pc, b )

These can be copied and directly integrated into your own projects.

The implicit surfaces are defined in separate js files. See examples folder.

EXAMPLE

``````// Example: implicit surface genus2:

const isf = ( x, y, z ) => ( 2*y*( y*y - 3*x*x )*( 1 - z*z ) + ( x*x + y*y )*( x*x + y*y ) - ( 9*z*z - 1 )*( 1 - z*z ) );// IMPLICIT SURFACE Function
const dx = ( x, y, z ) => ( -12*x*y*( 1 - z*z ) + 4*x*( x*x + y*y ) );// PARTIAL DERIVATE to x
const dy = ( x, y, z ) => ( 6*( y*y - x*x )*( 1 - z*z ) + 4*y*( x*x + y*y ) );// PARTIAL DERIVATE to y
const dz = ( x, y, z ) => ( -4*y*( y*y - 3*x*x )*z + 36*z*z*z - 20*z );// PARTIAL DERIVATE to z

const xs = 0; // x START POINT
const ys = 3; // y START POINT
const zs = 0; // z START POINT

const e = 0.001; // epsilon
const d = 0.08; // rough edge length of triangles
`````` There are two variants for calling the function in the THREEi addon.

``````const g = new THREE.BufferGeometry( );
g.createImplicitSurface = THREEi.createImplicitSurface;

// use version (A) with opt for infinite surfaces such as cylinders and cones or for cuts
/*opt optional object, all properties also optional
{
fc:  faces //( max. number of triangles )
pc:  positions // ( max. number of points )
b:   bounds //  array [ xMax, xMin, yMax, yMin, zMax, zMin ]
}
*/

// (A) parameters from implicitSurface example.js, with object of optional parameters, contains bounds
g.createImplicitSurface( isf, dx, dy, dz, xs, ys, zs, d, e, opt );

// (B) parameters from implicitSurface example.js with some default values
//g.createImplicitSurface( isf, dx, dy, dz, xs, ys, zs, d, e );
``````

Try it out: http://sandbox.threejs.hofk.de/ last section
or directly http://sandboxthreei.threejs.hofk.de/

9 Likes

Storm of applause! See original post above.  A small addition.

The calculation of the triangles of the implicit surfaces requires some effort. Therefore, it may be useful to export the result of the calculation as a complete three.js BufferGeometry definition.

The file triangulationImplicitSurfaceExportGeo.html serves this purpose. See folder Examples. If you press the export Def button, the JavaScript code is displayed and copied to the clipboard. The …32 arrays are shortened to the true length. This three.js BufferGeometry definition can be inserted into the file implicitSurfaceImport.html at the marked position. The definition can also easily be copied into your own projects.

1 Like

Is there any good way to get the formula using your plugin?

Some examples can be found there:
https://en.wikipedia.org/wiki/Implicit_surface

Short explanations only in German (you can simply translate them), see the formulas:
https://www.frassek.org/3d-flächen/implizite-flächen/

Thank you, ok Update: September 24th

See original post above. The Examples folder contains a simple inner geometry of cylinders with holes. See original post above. The Examples folder now contains both variants in one example.  Update: October 18 th

The algorithm for the sphere with holes previously contained no check whether the current front overlaps. The overlap check has been completed.

See original post above.  Update 07th February 2020 InnerGeometry, See original post above. Great work!
Also, have a look at Implisolid that we developed in 2016:

http://sohale.github.io/demos/implisolid-build/demo1/mp5_json_code.html

It is tailored for ThreeJS

Ideas and contributions are welcome