Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Three.js and javascript programming - Stairs are made up of a series of steps , and each step is made up of a riser and

Three.js and javascript programming -

Stairs are made up of a series of steps, and each step is made up of a riser and a tread. The riser is the vertical part of the step and the tread is the horizontal part you step on (as labeled in the image below).

Write a function createStairs(riser, tread, width, nbrSteps) that returns a geometry for stairs made of nbrSteps many steps, where each step has specified width, and whose riser rises riser units and whose tread treads tread units (of course), and use your function is a program to render stairs. The geometry depicted below (sans labels) was created with the call createStairs(1, 2, 4, 5).

function createPyramid(n, rad, len) { var len2 = len / 2; var geom = new THREE.Geometry(); // push n + 1 vertices // first the apex... geom.vertices.push(new THREE.Vector3(0, len2, 0)); // and then the vertices of the base var inc = 2 * Math.PI / n; for (var i = 0, a = 0; i < n; i++, a += inc) { var cos = Math.cos(a); var sin = Math.sin(a); geom.vertices.push(new THREE.Vector3(rad * cos, -len2, rad * sin)); } // push the n triangular faces... for (var i = 1; i < n; i++) { var face = new THREE.Face3(i+1, i, 0); geom.faces.push(face); } var face = new THREE.Face3(1, n, 0); geom.faces.push(face); // and then push the n-2 faces of the base for (var i = 2; i < n; i++) { var face = new THREE.Face3(i, i+1, 1); geom.faces.push(face); } // set face normals and return the geometry geom.computeFaceNormals(); return geom; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions