Skip to content

turbodt/SimplicialPolyhedron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simplicial Polyhedron

What is it?

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.

Methods

constructor

const p = new SimplicialPolyhedron(dim = 2, envDim = 3)

where

  • dim stands for the dimension of the polyhedron
  • envDim stands for the dimension of the Euclidian space where polyhedron is embedded.

Working Actually, only works for dimension 0 and maximal dimension.

length

p.length(dim)

Returns the number of simplexes of dimension dim.

getCoordinatesOf

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.

setCoordinates

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})

setMaximalSimplexes

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)

forEachPoint

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
})

forEachMaximalSimplex

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
})

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published