我试图在Three.js中创建一个蛋网。我使用LatheGeometry编写了下面的代码,但是我错过了正确的等式。有人可以帮忙吗?
var r0 = 40
var r1 = r0/4;
var inc = Math.PI/r0;
points = [];
points.push( new THREE.Vector2( 0.0001, -r0/2 ) );
for ( var i = 0; i <= r0; i ++ ) {
var def = i<r0/2 ? 0 : r1*Math.sin((i-r0/2)*inc);
points.push( new THREE.Vector2( Math.sqrt(r0*i-i*i), i+def-r0/2 ) );
}
points.push( new THREE.Vector2( 0.0001, -r0/2 ) );
var geometry = new THREE.LatheGeometry( points, 30 );
var material = new THREE.MeshPhongMaterial( { color: 0xFFFF20 } );
Ovo = new THREE.Mesh( geometry, material );
Ovo.position.set(0, 20.1, 0);
scene.add( Ovo );
答案 0 :(得分:8)
你可以像这样创建一个“蛋”几何:
// points - (x, y) pairs are rotated around the y-axis
var points = [];
for ( var deg = 0; deg <= 180; deg += 6 ) {
var rad = Math.PI * deg / 180;
var point = new THREE.Vector2( ( 0.72 + .08 * Math.cos( rad ) ) * Math.sin( rad ), - Math.cos( rad ) ); // the "egg equation"
//console.log( point ); // x-coord should be greater than zero to avoid degenerate triangles; it is not in this formula.
points.push( point );
}
geometry = new THREE.LatheBufferGeometry( points, 32 );
three.js r.76