It's a JS class that allows you to work with a simplicial polyhedron.
Furthermore it allowes to connect to THREE.js and manage buffer geometries as easy as just manipulate the polyhedron.
- constructor
- length
- getCoordinatesOf
- setCoordinates
- setMaximalSimplexes
- forEachPoint
- forEachMaximalSimplex
const p = new SimplicialPolyhedron(dim = 2, envDim = 3)
where
dim
stands for the dimension of the polyhedronenvDim
stands for the dimension of the Euclidian space where polyhedron is embedded.
Working Actually, only works for dimension 0 and maximal dimension.
p.length(dim)
Returns the number of simplexes of dimension dim
.
p.getCoordinatesOf(simplex)
where simplex = [p0,p1,...,pn]
is an array containing the points that define the n-simplex.
Returns an array of length (n+1)
containing the coordinates of the points.
p.setCoordinates()
Set the points and their coordinates. Examples are auto-explicative about the argument format.
The following examples set the same points of a square:
p.setCoordinates([[0,0],[1,0],[0,1],[1,1]])
p.setCoordinates([0,0],[1,0],[0,1],[1,1])
p.setCoordinates([0,0,1,0,0,1,1,1])
p.setCoordinates(0,0,1,0,0,1,1,1)
p.setCoordinates([{x:0,y:0},{x:1,y:0},{x:0,y:1},{x:1,y:1}])
p.setCoordinates({x:0,y:0},{x:1,y:0},{x:0,y:1},{x:1,y:1})
p.setMaximalSimplexes()
Set the maximal simplexes of the polyhedron. Examples are auto-explicative about the argument format.
With points as example above, the following examples set the same two 2-simplexes that triangulate an square:
p.setMaximalSimplexes([[0,1,3],[0,3,2]])
p.setMaximalSimplexes([0,1,3],[0,3,2])
p.setMaximalSimplexes([0,1,3,0,3,2])
p.setMaximalSimplexes(0,1,3,0,3,2)
p.forEachPoint( callback )
Loop over points and for each one calls back a callback function passed as argument. Callback function expects three parameters:
- Coordinates of the point.
- The point (i.e. a number).
- The polyhedron itself.
Examples:
p.forEachPoint( (X,point) => console.log('Point '+p+' has coordinates', X) )
// translation
const t = [2,-1,4]
p.forEachPoint( X => t.forEach( (x,i) => X[i] += x))
// twist
p.forEachPoint( X => {
const x = X[0]
X[0] = X[1]
X[1] = x
})
p.forEachMaximalSimplex( callback )
Loop over maximal simplexes and for each one calls back a callback function passed as argument. Callback function expects three parameters:
- The simplex, i.e. an array with points defining it.
- The index of the simplex.
- The polyhedron itself.
Examples:
p.forEachMaximalSimplex( (face,i) => console.log('The '+(i+1)+'th face are defined by points', face))
// change orientation
p.forEachMaximalSimplex( face => {
const a = face[p.dimesion]
face[p.dimesion] = face[p.dimesion-1]
face[p.dimesion-1] = a
})