# Three.js shape from random points

I have a N number of random points (in this case 20), with a X,Y and Z constrains.

How can I create ANY (preferably closed) shape (using Three.js library) , given and starting only from N random points.

There are probably many variants, please share yours.

``````var program = new Program(reset,step)
function reset() {
scene.clear()
}
function step() {

}

program.startup()

var numpoints = 20;
var dots = []; //If you want to use for other task

for (var i = 0 ; i < numpoints ; i++){
var x = Math.random() * (80 - 1) + 1    //Math.random() * (max - min) + min
var y = Math.random() * (80 - 1) + 1
var z = Math.random() * (80 - 1) + 1

var dotGeometry = new THREE.Geometry();
dots.push(dotGeometry);
dotGeometry.vertices.push(new THREE.Vector3( x, y, z));
var dotMaterial = new THREE.PointsMaterial( { size: 3, sizeAttenuation: false, color: 0xFF0000 } );
var dot = new THREE.Points( dotGeometry, dotMaterial );

}
``````

Triangulation, Voronoi, I don't care, just show me ANY ideas you have, will help me learn a lot! You can create a polyhedron which is the convex hull of a set of 3D points by using a pattern like so:

``````var points = [
new THREE.Vector3( 100, 0, 0 ),
new THREE.Vector3( 0, 100, 0 ),
...
new THREE.Vector3( 0, 0, 100 )
];

var geometry = new THREE.ConvexGeometry( points );

var material = new THREE.MeshPhongMaterial( {
color: 0xff0000,
} );

mesh = new THREE.Mesh( geometry, material );
``````

You must include the following in your project

``````<script src="/examples/js/geometries/ConvexGeometry.js"></script>
``````

three.js r.78