I am in need of expert help here. I have just started learning how to use three.js, I’d like to know if there is any way that i can create other 3D shapes? especially pyramid. The shape is made up from a list of names in a periodic table as you can see in the link I’ve attached below.
From three.js examples you got the sphere and others. You just have to calculate the geometry differently. Some math.
// sphere
var vector = new THREE.Vector3();
for ( var i = 0, l = objects.length; i < l; i ++ ) {
var phi = Math.acos( - 1 + ( 2 * i ) / l );
var theta = Math.sqrt( l * Math.PI ) * phi;
var object = new THREE.Object3D();
object.position.setFromSphericalCoords( 800, phi, theta );
vector.copy( object.position ).multiplyScalar( 2 );
object.lookAt( vector );
targets.sphere.push( object );
}
@msyazwanmsaid
Do you already know how many sides our pyramid will have?
Some examples of explanatory pictures of the desired result will help to understand what a pyramid shape is.
The more details you put in explanation, the better help you’ll get.
Just some thoughts:
You’ve got a pyramid. 4 sides and 1 base. Sides are triangles, the base is a square.
There are 118 elements, so you need to know how to distribute them in the pyramid formation.
I’m not a mathematician, but I think that you’ll get such equation: x*x + 4 * y = 118.
In the first approximation you’ll get x = 5, y = 25, that’ll give 5 * 5 + 4 * 25 = 125 (the difference is 125 - 118 = 7, tolerable ).
So, we’ve got 25 items per side. Suppose, we need to place them in rows, usning arithmetic progression (n + 2), thus we’ll have 5 rows (1, 3, 5, 7, 9, numbers are amount of items in each row). If 1 item is 1x1, then we have a triangle with 5 units heitght and 9 units in its base.
We’ve got 4 sides, then we can put on them 100 items. The rest 18 items are for the base of the pytamid.
Use two loops to put items in the formation of triangle, using that arithmetic progression.
All that stuff is just from the scratch
It’s not that rocket science