Текущая версия |
Ваш текст |
Строка 88: |
Строка 88: |
| | | |
| {{#widget:Iframe |url=http://tm.spbstu.ru/htmlets/Shvarev/4.html |width=1100 |height=500 |border=0 }} | | {{#widget:Iframe |url=http://tm.spbstu.ru/htmlets/Shvarev/4.html |width=1100 |height=500 |border=0 }} |
− |
| |
− |
| |
− | <div class="mw-collapsible mw-collapsed">
| |
− | '''Текст программы на языке JavaScript:''' <div class="mw-collapsible-content">
| |
− | Файл '''"4.js"'''
| |
− | <syntaxhighlight lang="javascript" line start="1" enclose="div">
| |
− |
| |
− | function main()
| |
− | {
| |
− | var scene = new THREE.Scene();
| |
− | var camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000);
| |
− | var render = new THREE.WebGLRenderer();
| |
− | render.setClearColor(0x87CEFA, 1);
| |
− | render.setSize(800, 400);
| |
− |
| |
− | var axes = new THREE.AxisHelper(20);
| |
− | scene.add(axes);
| |
− |
| |
− | /**
| |
− | var planeGeometry = new THREE.PlaneGeometry(105,68,50,1);
| |
− | */
| |
− | var planeGeometry = new THREE.PlaneGeometry(1000,500,50,1);
| |
− | var planeMaterial = new THREE.MeshLambertMaterial({color:0x068000});
| |
− | var plane = new THREE.Mesh(planeGeometry, planeMaterial);
| |
− | plane.position.x=0;
| |
− | plane.position.y=0;
| |
− | plane.position.z=-0.11;
| |
− |
| |
− | scene.add(plane);
| |
− |
| |
− | var ballGeometry = new THREE.SphereGeometry( 0.11, 16, 16 );
| |
− | var ballMaterial = new THREE.MeshBasicMaterial( {color: 0xffff00,wireframe:true} );
| |
− | var ball = new THREE.Mesh( ballGeometry, ballMaterial );
| |
− | scene.add( ball );
| |
− | ball.castShadow = true;
| |
− |
| |
− |
| |
− | var cylinderGeometry = new THREE.CylinderGeometry(0.11,0.11,1,16);
| |
− | var cylinderMaterial = new THREE.MeshLambertMaterial({color:0xffff00});
| |
− | var cylinder = new THREE.Mesh(cylinderGeometry, cylinderMaterial)
| |
− | cylinder.position.x=0;
| |
− | cylinder.position.y=0;
| |
− | cylinder.position.z=0;
| |
− | scene.add(cylinder);
| |
− | cylinder.castShadow = true;
| |
− |
| |
− | var trajectoryGeometryB = new THREE.SphereGeometry(0.05, 16, 16);
| |
− | var trajectoryMaterialB = new THREE.MeshBasicMaterial( {color: 0x000000,wireframe:true} );
| |
− |
| |
− | var trajectoryGeometryC = new THREE.SphereGeometry(0.05, 16, 16);
| |
− | var trajectoryMaterialC = new THREE.MeshBasicMaterial( {color: 0xFF0000,wireframe:true} );
| |
− |
| |
− | var traMaterialB = new THREE.MeshBasicMaterial({color: 0xffffff});
| |
− | var traGeometryB = new THREE.CircleGeometry( 0.05, 16);
| |
− |
| |
− | var traMaterialC = new THREE.MeshBasicMaterial({color: 0xFF9900});
| |
− | var traGeometryC = new THREE.CircleGeometry( 0.05, 16);
| |
− |
| |
− |
| |
− | /**
| |
− | var cubeGeometry = new THREE.CubeGeometry(4,4,4);
| |
− | var cubeMesh = new THREE.MeshLambertMaterial({color:0xff0000, wireframe:false});
| |
− | var cube = new THREE.Mesh(cubeGeometry, cubeMesh);
| |
− | cube.position.x=-4;
| |
− | cube.position.y=3;
| |
− | cube.position.z=0;
| |
− | scene.add(cube);
| |
− |
| |
− |
| |
− | var cylinderGeometry = new THREE.CylinderGeometry(4,4,5,16);
| |
− | var cylinderMaterial = new THREE.MeshLambertMaterial({color:0xaaee00});
| |
− | var cylinder = new THREE.Mesh(cylinderGeometry, cylinderMaterial)
| |
− | cylinder.position.x=10;
| |
− | cylinder.position.y=10;
| |
− | cylinder.position.z=0;
| |
− |
| |
− | scene.add(cylinder);
| |
− | */
| |
− |
| |
− |
| |
− |
| |
− |
| |
− | var spotLight = new THREE.SpotLight(0xffffff);
| |
− | spotLight.position.set(0,0,1500);
| |
− | scene.add(spotLight);
| |
− |
| |
− |
| |
− | spotLight.castShadow = true;
| |
− |
| |
− |
| |
− |
| |
− | render.shadowMapEnabled = true;
| |
− | plane.receiveShadow = true;
| |
− |
| |
− | /**
| |
− | cube.castShadow = true;
| |
− | cylinder.castShadow = true;
| |
− | */
| |
− |
| |
− |
| |
− |
| |
− | var a = new THREE.Vector3( 5, 2, -1 );
| |
− | var b = new THREE.Vector3( -1, 1, 1 );
| |
− |
| |
− | var c = new THREE.Vector3();
| |
− | c.crossVectors( a, b );
| |
− |
| |
− | camera.position.x= -30;
| |
− | camera.position.y= 0;
| |
− | camera.position.z= 60;
| |
− | camera.lookAt(c);
| |
− |
| |
− | camera.lookAt(scene.position);
| |
− | $("#webGL").append(render.domElement);
| |
− |
| |
− |
| |
− |
| |
− | var controls = new function() {
| |
− | this.WindPowerX = 0;
| |
− | this.WindPowerY = 0;
| |
− | this.WindPowerZ = 0;
| |
− | this.Mass = 0.45;
| |
− | this.Radius = 0.11;
| |
− | this.Height = 0.22;
| |
− | this.Viscosity = 0.000178;
| |
− | this.AirDensity = 1.2754;
| |
− | this.g = 9.8
| |
− | this.Vx = 15;
| |
− | this.Vy = 0;
| |
− | this.Vz = 5;
| |
− | this.OmegaX = 0;
| |
− | this.OmegaY = 0;
| |
− | this.OmegaZ = -10;
| |
− | }
| |
− | var gui = new dat.GUI();
| |
− | gui.add(controls, 'WindPowerX',-10,10);
| |
− | gui.add(controls, 'WindPowerY',-10,10);
| |
− | gui.add(controls, 'WindPowerZ',-10,10);
| |
− | gui.add(controls, 'Mass',0.41,0.45);
| |
− | gui.add(controls, 'Radius',0.01,0.21);
| |
− | gui.add(controls, 'Height',0.1, 1);
| |
− | gui.add(controls, 'Viscosity',0.00001, 0.001)
| |
− | gui.add(controls, 'AirDensity',1, 1000)
| |
− | gui.add(controls, 'g',0, 20)
| |
− | gui.add(controls, 'Vx',0,40);
| |
− | gui.add(controls, 'Vy',0,40);
| |
− | gui.add(controls, 'Vz',0,40);
| |
− | gui.add(controls, 'OmegaX',-10,10);
| |
− | gui.add(controls, 'OmegaY',-10,10);
| |
− | gui.add(controls, 'OmegaZ',-10,10);
| |
− |
| |
− |
| |
− | contr = new THREE.OrbitControls(camera);
| |
− | contr.dumping = 0.2;
| |
− |
| |
− |
| |
− |
| |
− | /**contr = new THREE.TrackballControls(camera);
| |
− | contr.rotateSpeed = 1.0;
| |
− | contr.zoomSpeed = 1.2;
| |
− | contr.panSpeed = 0.8;
| |
− | contr.noZoom = false;
| |
− | contr.noPan = false;
| |
− | contr.staticMoving = true;
| |
− | contr.dynamicDampingFactor = 0.3;
| |
− | contr.keys = [65,83,68];
| |
− | */
| |
− |
| |
− |
| |
− | /**window.addEventListener('resize',onWindowResize,false);
| |
− | function onWindowResize()
| |
− | {
| |
− | camera.aspect = window.innerWidth/window.innerHeight;
| |
− | camera.updateProjectionMatrix();
| |
− | render.setSize(window.innerWidth,window.innerHeight);
| |
− |
| |
− | renderer();
| |
− | }
| |
− | */
| |
− |
| |
− | var stats = initStats();
| |
− | var step = 0;
| |
− |
| |
− |
| |
− | Vx = 0;
| |
− | Vy = 0;
| |
− | Vz = 0;
| |
− | Mass = 0;
| |
− | Viscosity = 0;
| |
− | dt = 0.01;
| |
− | Radius = 0;
| |
− | g = 0;
| |
− | WindX = 0;
| |
− | WindY = 0;
| |
− | WindZ = 0;
| |
− | AirDensity = 0;
| |
− |
| |
− | Height = 1;
| |
− |
| |
− | var VxB =controls.Vx;
| |
− | var VxC =controls.Vx;
| |
− | var VyB =controls.Vy;
| |
− | var VyC =controls.Vy;
| |
− | var VzB =controls.Vz;
| |
− | var VzC =controls.Vz;
| |
− |
| |
− | OmegaXB = controls.OmegaX;
| |
− | OmegaXC = controls.OmegaX;
| |
− | OmegaYB = controls.OmegaY;
| |
− | OmegaYC = controls.OmegaY;
| |
− | OmegaZB = controls.OmegaZ;
| |
− | OmegaZC = controls.OmegaZ;
| |
− |
| |
− |
| |
− | pppB = 0;
| |
− | pppC = 0;
| |
− | kkk = 0;
| |
− |
| |
− | function renderer()
| |
− | {
| |
− | /**
| |
− | cube.rotation.x+=controls.rotationSpeed;
| |
− | cube.rotation.y+=controls.rotationSpeed;
| |
− | cube.rotation.z+=controls.rotationSpeed;
| |
− |
| |
− | cylinder.position.x = 20+(10*(Math.cos(step)));
| |
− | cylinder.position.y = 2+(10*(Math.abs(Math.sin(step))));
| |
− |
| |
− |
| |
− | */
| |
− |
| |
− | if (pppB == 0)
| |
− | {
| |
− | VxB+=controls.Vx;
| |
− | VyB+=controls.Vy;
| |
− | VzB+=controls.Vz;
| |
− | WindX = controls.WindPowerX;
| |
− | WindY = controls.WindPowerY;
| |
− | WindZ = controls.WindPowerZ;
| |
− |
| |
− | OmegaXB = controls.OmegaX;
| |
− | OmegaYB = controls.OmegaY;
| |
− | OmegaZB = controls.OmegaZ;
| |
− |
| |
− |
| |
− | pppB = 1;
| |
− |
| |
− | }
| |
− |
| |
− | UxB = VxB - WindX;
| |
− | UyB = VyB - WindY;
| |
− | UzB = VzB - WindZ;
| |
− |
| |
− | Mass=controls.Mass;
| |
− | Radius=controls.Radius;
| |
− | Viscosity = controls.Viscosity;
| |
− | g = controls.g;
| |
− |
| |
− | AirDensity = controls.AirDensity;
| |
− |
| |
− |
| |
− | if (ball.position.z >= 0)
| |
− | {
| |
− |
| |
− | /**
| |
− | VxB += (-6*Math.PI*Viscosity*Radius*VxB/Mass + 2*Math.PI*AirDensity*Radius*Radius*Radius*(UyB*OmegaZB - UzB*OmegaYB)/Mass)*dt;
| |
− | VyB += (-6*Math.PI*Viscosity*Radius*VyB/Mass + 2*Math.PI*AirDensity*Radius*Radius*Radius*(UzB*OmegaXB - UxB*OmegaZB)/Mass )*dt;
| |
− | VzB += (-6*Math.PI*Viscosity*Radius*VzB/Mass - g + 2*Math.PI*AirDensity*Radius*Radius*Radius*(UxB*OmegaYB - UyB*OmegaXB)/Mass)*dt;
| |
− |
| |
− | OmegaXB += -6*Math.PI*Viscosity*Radius*OmegaXB*Radius/Mass;
| |
− | OmegaYB += -6*Math.PI*Viscosity*Radius*OmegaYB*Radius/Mass;
| |
− | OmegaZB += -6*Math.PI*Viscosity*Radius*OmegaZB*Radius/Mass;
| |
− |
| |
− | */
| |
− |
| |
− | VxB += (2*Math.PI*AirDensity*Radius*Radius*Radius*(UyB*OmegaZB - UzB*OmegaYB)/Mass)*dt;
| |
− | VyB += (2*Math.PI*AirDensity*Radius*Radius*Radius*(UzB*OmegaXB - UxB*OmegaZB)/Mass )*dt;
| |
− | VzB += (-g + 2*Math.PI*AirDensity*Radius*Radius*Radius*(UxB*OmegaYB - UyB*OmegaXB)/Mass)*dt;
| |
− |
| |
− | ball.position.x += VxB*dt;
| |
− | ball.position.y += VyB*dt;
| |
− | ball.position.z += VzB*dt;
| |
− |
| |
− |
| |
− |
| |
− | ball.rotation.x += OmegaXB*dt;
| |
− | ball.rotation.y += OmegaYB*dt;
| |
− | ball.rotation.z += OmegaZB*dt;
| |
− |
| |
− | var trajectoryB = new THREE.Mesh(trajectoryGeometryB, trajectoryMaterialB);
| |
− | trajectoryB.position.x = ball.position.x;
| |
− | trajectoryB.position.y = ball.position.y;
| |
− | trajectoryB.position.z = ball.position.z;
| |
− |
| |
− | scene.add( trajectoryB );
| |
− |
| |
− |
| |
− | var traB = new THREE.Mesh( traGeometryB, traMaterialB);
| |
− | traB.position.x = ball.position.x;
| |
− | traB.position.y = ball.position.y;
| |
− | traB.position.z = 0;
| |
− | scene.add(traB);
| |
− |
| |
− | document.getElementById("td1").innerHTML = ball.position.y ;
| |
− | document.getElementById("td2").innerHTML = ball.position.x ;
| |
− |
| |
− | }
| |
− |
| |
− | requestAnimationFrame(renderer);
| |
− |
| |
− | contr.update();
| |
− |
| |
− | render.render(scene,camera);
| |
− |
| |
− |
| |
− |
| |
− |
| |
− | }
| |
− |
| |
− | alpha1 = 0;
| |
− | alpha2 = 0;
| |
− | alpha3 = 0;
| |
− | rot1 = 0;
| |
− | rot2 = 0;
| |
− | rot3 = 0;
| |
− |
| |
− | function renderer2()
| |
− | {
| |
− |
| |
− |
| |
− | if (pppC == 0)
| |
− | {
| |
− | VyC+=controls.Vy;
| |
− | VxC+=controls.Vx;
| |
− | VzC+=controls.Vz;
| |
− | WindX = controls.WindPowerX;
| |
− | WindY = controls.WindPowerY;
| |
− | WindZ = controls.WindPowerZ;
| |
− |
| |
− | OmegaXC = controls.OmegaX;
| |
− | OmegaYC = controls.OmegaY;
| |
− | OmegaZC = controls.OmegaZ;
| |
− |
| |
− |
| |
− | pppC = 1;
| |
− |
| |
− | }
| |
− |
| |
− | UxC = VxC - WindX;
| |
− | UyC = VyC - WindY;
| |
− | UzC = VzC - WindZ;
| |
− |
| |
− | Mass=controls.Mass;
| |
− | Radius=controls.Radius;
| |
− | Viscosity = controls.Viscosity;
| |
− | g = controls.g;
| |
− | Height = controls.Height;
| |
− | AirDensity = controls.AirDensity;
| |
− |
| |
− | var cylinderGeometry = new THREE.CylinderGeometry(2*Radius,2*Radius, Height, 16);
| |
− |
| |
− | cylinder.geometry = cylinderGeometry;
| |
− |
| |
− |
| |
− | if (cylinder.position.z >= 0)
| |
− | {
| |
− | /**
| |
− | VxC += (-6*Math.PI*Viscosity*Radius*VxC/Mass + 2*Math.PI*AirDensity*Radius*Radius*Radius*(UyC*OmegaZC - UzC*OmegaYC)/Mass)*dt;
| |
− | VyC += (-6*Math.PI*Viscosity*Radius*VyC/Mass + 2*Math.PI*AirDensity*Radius*Radius*Radius*(UzC*OmegaXC - UxC*OmegaZC)/Mass )*dt;
| |
− | VzC += (-6*Math.PI*Viscosity*Radius*VzC/Mass - g + 2*Math.PI*AirDensity*Radius*Radius*Radius*(UxC*OmegaYC - UyC*OmegaXC)/Mass)*dt;
| |
− |
| |
− | OmegaXC += -6*Math.PI*Viscosity*Radius*OmegaXC*Radius/Mass;
| |
− | OmegaYC += -6*Math.PI*Viscosity*Radius*OmegaYC*Radius/Mass;
| |
− | OmegaZC += -6*Math.PI*Viscosity*Radius*OmegaZC*Radius/Mass;
| |
− | */
| |
− | /**
| |
− | VxC += (2*Math.PI*AirDensity*Radius*Radius*Radius*(UyC*OmegaZC - UzC*OmegaYC)/Mass)*dt;
| |
− | VyC += (2*Math.PI*AirDensity*Radius*Radius*Radius*(UzC*OmegaXC - UxC*OmegaZC)/Mass )*dt;
| |
− | VzC += (-g + 2*Math.PI*AirDensity*Radius*Radius*Radius*(UxC*OmegaYC - UyC*OmegaXC)/Mass)*dt;
| |
− | */
| |
− |
| |
− |
| |
− | alpha1 = (cylinder.rotation.x - rot1)/(2*Math.PI);
| |
− | alpha2 = (cylinder.rotation.y - rot2)/(2*Math.PI);
| |
− | alpha3 = (cylinder.rotation.z - rot3)/(2*Math.PI);
| |
− |
| |
− | rot1 = cylinder.rotation.x;
| |
− | rot2 = cylinder.rotation.y;
| |
− | rot3 = cylinder.rotation.z;
| |
− |
| |
− | VxC += (2*AirDensity*Radius*(2*Radius*Height*Math.cos(alpha1) + Math.PI*Radius*Radius*Math.sin(alpha1) )*(UyC*OmegaZC - UzC*OmegaYC)/Mass)*dt;
| |
− | VyC += (2*AirDensity*Radius*(2*Radius*Height*Math.sin(alpha2) + Math.PI*Radius*Radius*Math.cos(alpha2))*(UzC*OmegaXC - UxC*OmegaZC)/Mass )*dt;
| |
− | VzC += (-g + 2*AirDensity*Radius*(2*Radius*Height*Math.cos(alpha3) + Math.PI*Radius*Radius*Math.sin(alpha3))*(UxC*OmegaYC - UyC*OmegaXC)/Mass)*dt;
| |
− |
| |
− | cylinder.position.x += VxC*dt;
| |
− | cylinder.position.y += VyC*dt;
| |
− | cylinder.position.z += VzC*dt;
| |
− |
| |
− | cylinder.rotation.x += OmegaXC*dt;
| |
− | cylinder.rotation.y += OmegaYC*dt;
| |
− | cylinder.rotation.z += OmegaZC*dt;
| |
− |
| |
− |
| |
− |
| |
− | var trajectoryC = new THREE.Mesh(trajectoryGeometryC, trajectoryMaterialC);
| |
− | trajectoryC.position.x = cylinder.position.x;
| |
− | trajectoryC.position.y = cylinder.position.y;
| |
− | trajectoryC.position.z = cylinder.position.z;
| |
− |
| |
− | scene.add( trajectoryC );
| |
− |
| |
− | var traC = new THREE.Mesh( traGeometryC, traMaterialC);
| |
− | traC.position.x = cylinder.position.x;
| |
− | traC.position.y = cylinder.position.y;
| |
− | traC.position.z = 0;
| |
− | scene.add(traC);
| |
− |
| |
− | document.getElementById("td3").innerHTML = cylinder.position.y ;
| |
− | document.getElementById("td4").innerHTML = cylinder.position.x;
| |
− |
| |
− | }
| |
− |
| |
− | requestAnimationFrame(renderer2);
| |
− |
| |
− | contr.update();
| |
− |
| |
− | render.render(scene,camera);
| |
− |
| |
− | }
| |
− |
| |
− | this.start = renderer;
| |
− | this.start2 = renderer2;
| |
− |
| |
− |
| |
− |
| |
− | }
| |
− | function initStats()
| |
− | {
| |
− | var stats = new Stats();
| |
− | stats.setMode(0);
| |
− | stats.domElement.style.position='absolute';
| |
− | stats.domElement.style.left = '0px';
| |
− | stats.domElement.style.top = '0px';
| |
− | $("#Stats").append(stats.domElement);
| |
− | return stats;
| |
− | }
| |
− |
| |
− |
| |
− |
| |
− | </syntaxhighlight>
| |
− | </div>
| |
| | | |
| == Обсуждение результатов и выводы == | | == Обсуждение результатов и выводы == |