Мещерский 47.11

Материал из Department of Theoretical and Applied Mechanics
Перейти к: навигация, поиск

Мещерский Задача 47.11

Визуализация 3D-задачи по динамике на JavaScript

Исполнитель: Ершов Александр

Группа 23632/2 Кафедра Теоретической механики

Условие задачи

Каток A массы M1, скатываясь без скольжения по наклонной плоскости вниз, поднимает посредством нерастяжимой нити, переброшенной через блок B, груз C массы M2. При этом блок B вращается вокруг неподвижной оси O, перпендикулярной его плоскости. Каток A и блок B — однородные круглые диски одинаковой массы и радиуса. Наклонная плоскость образует угол α с горизонтом. Определить ускорение оси катка. Массой нити пренебречь.

Решение

[math] Φ_i = -m_i a_i[/math]
[math]M_i = -J_i ε_i[/math]
Для блока А:
[math] Φ_A = m_1 a_A[/math]
[math]M_A = -J_{CA} ε_A = \frac{m_{1} R_{1}^2}{2} \frac{a_A}{R}[/math]
Для блока В:
[math]M_B = -J_sB ε_B = \frac{m_{1} R_{1}^2}{2} \frac{a_A}{R}[/math]
Для груза С:
[math] Φ_C = m_2 a_C = m_2 a_A[/math]

[math]\sum\ δA_{i} = m_1 g sinα δS_A - Φ_1 δS - M_A δφ_A - M_B δφ_B - m_2 g δS_C - Φ_2 δS_C = 0[/math]
[math]m_1 g sinα δS_A - m_1 a_A δS_A - \frac{m_{1} R a_A δS_A}{2 R} - \frac{m_{1} a_A δS_A}{2} - m_2 g δS_A - m_2 a_A δS_A = 0[/math]
[math]a_A = \frac{m_1 g sinα - m_2 g}{m_1 + \frac{m_1}{2} + \frac{m_1}{2} + m_2} = \frac{m_1 g sinα - m_2 g}{2 m_1 + m_2}[/math]

Ответ: [math]a_A = \frac{m_1 g sinα - m_2 g}{2 m_1 + m_2}[/math]

Визуализация

Код программы

Текст программы на языке JavaScript:
  1 var renderer, scene, camera, stats, axes;
  2   var control, controls, controls1, spotLight;
  3   var plane1, plane2, plane3, block1, block2, torus, cube, arr1, arr2, arr3, arr4, cr1,cr2,cr3;
  4   var dt = 1/60;
  5   var g = 9.8;
  6   var length = 30;
  7   var cubeY = 25;
  8   /////    ЗАДАНИЕ ПАРАМЕТРОВ, УКАЗАННЫХ В ЗАДАЧЕ    /////
  9 
 10   function init()
 11   {
 12     scene = new THREE.Scene();  // создаем сцену
 13     camera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,0.1,1000);  // создаем камеру
 14 
 15     renderer = new THREE.WebGLRenderer();
 16     renderer.setClearColor(0XEEEEEE,1);
 17     renderer.setSize(window.innerWidth,window.innerHeight);
 18     renderer.shadowMap.enabled=true;
 19 
 20     axes = new THREE.AxisHelper(20);  // создаем координатные оси
 21     scene.add(axes);
 22 
 23 
 24 
 25     control = new THREE.OrbitControls(camera,renderer.domElement);
 26 
 27     controls = new function()  // создаем переключатели, позволяющие изменять входные параметры
 28     {
 29       this.alpha = Math.PI/6;
 30       this.blockRadius = 3;
 31       this.m1 = 3;
 32       this.m2 = 1;
 33       this.animate = false;
 34       this.showAcs = false;
 35       this.reset  = function() {
 36         controls1.t = 0;
 37         ReDraw();
 38       }
 39     }
 40 
 41     controls1=new function()   // вывод полученных в ходе решения задачи значений
 42     {
 43       this.t = 0.0;
 44       this.a = (controls.m1*g*Math.sin(controls.alpha)-controls.m2*g)/(2*controls.m1+controls.m2);
 45     }
 46 
 47     var gui = new dat.GUI();  // позволяем менять каждый из параметров в определенном диапазоне, в случае изменения вызываем функцию, перестраивающую выводимую на экран картинку
 48     gui.add(controls,'alpha', 0.1,Math.PI/3).onChange(controls.reset);
 49     gui.add(controls,'m1',1,20).onChange(controls.reset);
 50     gui.add(controls,'m2',1,20).onChange(controls.reset);
 51     gui.add(controls, 'animate');
 52     gui.add(controls, 'showAcs').onChange(ReDraw);
 53     gui.add(controls, 'reset');
 54     //gui.add(controls,'m',1,10).onChange(ReDraw);
 55     gui.add(controls1, 't').listen();
 56     gui.add(controls1, 'a').listen();
 57 
 58     ambientLight=new THREE.AmbientLight(0x000000);
 59     scene.add(ambientLight);
 60     document.getElementById("WebGL").appendChild(renderer.domElement);
 61     // Camera
 62     camera.position.x = -30;
 63     camera.position.y = 40;
 64     camera.position.z = 80;
 65     camera.lookAt(scene.position);
 66     // Ligth
 67     spotLight = new THREE.SpotLight( 0xffffff );
 68     spotLight.position.set( -40, 80, 50 );
 69     spotLight.castShadow = true;
 70     scene.add(spotLight );
 71 
 72     // Main Plane
 73     var planeGeometry2 = new THREE.PlaneGeometry(length,20);
 74     var planeMaterial2 = new THREE.MeshLambertMaterial({color: 0x6F482A, side: THREE.DoubleSide});
 75     plane1 = new THREE.Mesh(planeGeometry2,planeMaterial2);
 76     plane1.rotation.x = -0.5*Math.PI;
 77     plane1.position.x = -length/2;
 78     plane1.position.y = 0;
 79     plane1.position.z = 0;
 80     plane1.receiveShadow = true;
 81     scene.add(plane1);
 82 
 83     // Third Plane
 84     var planeGeometry2 = new THREE.PlaneGeometry(length,20,6,4);
 85     var planeMaterial2 = new THREE.MeshLambertMaterial({color: 0x6F482A, wireframe: true});
 86     plane2 = new THREE.Mesh(planeGeometry2,planeMaterial2);
 87     plane2.rotation.x = -0.5*Math.PI;
 88     plane2.position.set(length/2,0,0);
 89     scene.add(plane2);
 90 
 91     stats = initStats();
 92     Draw();
 93     renderScene();
 94 
 95     window.addEventListener('resize',onResize,false);
 96   };
 97 
 98   function ReDraw()  // функция, перерисовывающая всю картинку
 99   {
100     controls1.a = (controls.m1*g*Math.sin(controls.alpha)-controls.m2*g)/(2*controls.m1+controls.m2);
101     scene.remove(block1);
102     scene.remove(block2);
103     scene.remove(cube);
104     scene.remove(plane3);
105     scene.remove(torus);
106     scene.remove(cr1);
107     scene.remove(cr2);
108     scene.remove(cr3);
109     scene.remove(arr1);
110     scene.remove(arr2);
111     scene.remove(arr3);
112     scene.remove(arr4);
113     Draw();
114   }
115 
116   function Draw()
117   {
118 
119     // Second Plane
120     var planeGeometry3 = new THREE.PlaneGeometry(length/Math.cos(controls.alpha),20);
121     var planeMaterial3 = new THREE.MeshLambertMaterial({color: 0x6F482A, wireframe: false, side: THREE.DoubleSide});
122     plane3 = new THREE.Mesh(planeGeometry3,planeMaterial3);
123     plane3.rotation.set(-0.5*Math.PI,-controls.alpha,0);
124     plane3.position.set(length/2,0.5*length*Math.tan(controls.alpha),0);
125     plane3.receiveShadow = true;
126     scene.add(plane3);
127     // Block1
128     block1 = new THREE.Mesh(new THREE.CylinderGeometry(controls.blockRadius,controls.blockRadius,3,32), new THREE.MeshLambertMaterial({color: 0xA8A8A8, wireframe: false, side: THREE.DoubleSide}));
129     block1.rotation.set(-0.5*Math.PI,0,0);
130     block1.position.set(length,length*Math.tan(controls.alpha),0);
131     block1.castShadow = true;
132     scene.add(block1);
133     // Block2
134     block2 = new THREE.Mesh(new THREE.CylinderGeometry(controls.blockRadius,controls.blockRadius,3,32), new THREE.MeshLambertMaterial({color: 0xA8A8A8, wireframe: false, side: THREE.DoubleSide}));
135     block2.rotation.set(-0.5*Math.PI,0,0);
136     block2.position.x = length/2-controls1.a*controls1.t*controls1.t*Math.cos(controls.alpha)*0.5;
137     block2.position.y = block2.position.x*Math.tan(controls.alpha)+controls.blockRadius/Math.cos(controls.alpha);
138     block2.castShadow = true;
139     scene.add(block2);
140     // Thorus
141     torus = new THREE.Mesh( new THREE.TorusGeometry( 6, 0.1, 16, 100, controls.alpha ), new THREE.MeshBasicMaterial( { color: 0xff0000 } ) );
142     torus.position.set(0,0,9.9)
143     scene.add(torus);
144     // Cube
145     cube = new THREE.Mesh(new THREE.BoxGeometry(4, 4, 4), new THREE.MeshLambertMaterial({color: 0x7CA05A, wireframe: false}));
146     cube.position.set(length+controls.blockRadius,-cubeY+controls1.a*controls1.t*controls1.t,0);
147     scene.add(cube);
148     //More rope
149     cr1 = new THREE.Mesh(new THREE.CylinderGeometry(0.2,0.2,(length*Math.tan(controls.alpha)+cubeY),32), new THREE.MeshLambertMaterial({color: 0x000000, wireframe: false}));
150     cr1.rotation.set(0,0,0);
151     cr1.position.set(length+controls.blockRadius, (length*Math.tan(controls.alpha)+cube.position.y)/2, 0);
152     cr1.scale.y = (length*Math.tan(controls.alpha)-cube.position.y)/(length*Math.tan(controls.alpha)+cubeY);
153     cr1.castShadow = true;
154     scene.add(cr1);
155 
156     cr2 = new THREE.Mesh(new THREE.CylinderGeometry(0.2,0.2,1), new THREE.MeshLambertMaterial({color: 0x000000, wireframe: false}));
157     cr2.rotation.set(0,0,-Math.PI/2+controls.alpha);
158     cr2.position.set((length+block2.position.x-controls.blockRadius*Math.sin(controls.alpha))/2,(length*Math.tan(controls.alpha)+block2.position.y+controls.blockRadius*Math.cos(controls.alpha))/2, 0);
159     cr2.scale.y = (length-block2.position.x-controls.blockRadius*Math.sin(controls.alpha))/Math.cos(controls.alpha);
160     cr2.castShadow = true;
161     scene.add(cr2);
162 
163     function Curve2() {
164       THREE.Curve.call(this);
165     };
166     Curve2.prototype = Object.create(THREE.Curve.prototype);
167     Curve2.prototype.constructor = Curve2;
168     Curve2.prototype.getPoint = function(t) {
169       var tx = length+controls.blockRadius*Math.cos(controls.alpha+Math.PI*0.5-t*(controls.alpha+Math.PI*0.5));
170       var ty = length*Math.tan(controls.alpha)+controls.blockRadius*Math.sin(controls.alpha+Math.PI*0.5-t*(controls.alpha+Math.PI*0.5));
171       return new THREE.Vector3(tx,ty,0);
172     };
173     var path2 = new Curve2();
174     cr3 = new THREE.Mesh(new THREE.TubeGeometry(path2,20,0.2,8), new THREE.MeshBasicMaterial({color: 0x000000, wireframe: false}));
175     scene.add(cr3);
176 
177     //arrows
178     arr1 = new THREE.Mesh(new THREE.CylinderGeometry(0.3,0.3,4,32), new THREE.MeshBasicMaterial({color: 0xff0000, wireframe: false}));
179     arr1.rotation.set(0,0,0);
180     arr1.position.set(length+controls.blockRadius,cube.position.y+controls.m2*2+controls1.a*2,0);
181     arr1.scale.y = controls1.a;
182     if (!controls.showAcs) {arr1.visible = false}
183     else {arr1.visible = true}
184     scene.add(arr1);
185     arr2 = new THREE.Mesh(new THREE.CylinderGeometry(0,0.7,Math.sign(controls1.a)*2,32), new THREE.MeshBasicMaterial({color: 0xff0000, wireframe: false}));
186     arr2.rotation.set(0,0,0);
187     arr2.position.set(length+controls.blockRadius,cube.position.y+controls.m2*2+controls1.a*4,0);
188     if (!controls.showAcs) {arr2.visible = false}
189     else {arr2.visible = true}
190     scene.add(arr2);
191     arr3 = new THREE.Mesh(new THREE.CylinderGeometry(0.3,0.3,4,32), new THREE.MeshBasicMaterial({color: 0xff0000, wireframe: true}));
192     arr3.rotation.set(0,0,-1.5*Math.PI+controls.alpha);
193     arr3.position.set(block2.position.x-Math.sign(controls1.a)*(controls.blockRadius)*Math.cos(controls.alpha)-controls1.a*2*Math.cos(controls.alpha),block2.position.y-Math.sign(controls1.a)*(controls.blockRadius)*Math.sin(controls.alpha)-controls1.a*2*Math.sin(controls.alpha),0);
194     arr3.scale.y = controls1.a;
195     if (!controls.showAcs) {arr3.visible = false}
196     else {arr3.visible = true}
197     scene.add(arr3);
198     arr4 = new THREE.Mesh(new THREE.CylinderGeometry(0,0.7,-Math.sign(controls1.a)*2,32), new THREE.MeshBasicMaterial({color: 0xff0000, wireframe: false}));
199     arr4.rotation.set(0,0,-Math.PI/2+controls.alpha);
200     arr4.position.set(block2.position.x-Math.sign(controls1.a)*(controls.blockRadius)*Math.cos(controls.alpha)-controls1.a*4*Math.cos(controls.alpha),block2.position.y-Math.sign(controls1.a)*(controls.blockRadius)*Math.sin(controls.alpha)-controls1.a*4*Math.sin(controls.alpha),0);
201     if (!controls.showAcs) {arr4.visible = false}
202     else {arr4.visible = true}
203     scene.add(arr4);
204 
205     renderer.render(scene,camera);
206   }
207 
208   function renderScene()
209   {
210     if((block2.position.y <= controls.blockRadius) || (cube.position.y >= length*Math.tan(controls.alpha)-controls.blockRadius) || (((block2.position.y-block1.position.y)*(block2.position.y-block1.position.y)+(block2.position.x-block1.position.x)*(block2.position.x-block1.position.x)) <= 4*controls.blockRadius*controls.blockRadius)) {
211       controls1.t = 0;
212     }
213     if (controls.animate)
214     {
215       controls1.t+=dt;
216       ReDraw();
217     }
218 
219     stats.update();
220     requestAnimationFrame(renderScene);
221     renderer.render(scene,camera);
222   };
223 
224   function initStats()
225   {
226     var stats=new Stats();
227     stats.setMode(0);
228     stats.domElement.style.position='0px';
229     stats.domElement.style.left='0px';
230     stats.domElement.style.top='0px';
231     document.getElementById("Stats-output").appendChild(stats.domElement);
232     return stats;
233   };
234 
235   function onResize()
236   {
237     camera.aspect=window.innerWidth/window.innerHeight;
238     camera.updateProjectionMatrix();
239     renderer.setSize(window.innerWidth,window.innerHeight);
240   }
241 
242   window.onload = init;