Колебания в цилиндре

Материал из Department of Theoretical and Applied Mechanics
Версия от 11:57, 22 декабря 2017; 10.208.2.49 (обсуждение)

(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Постановка задачи[править]

Определить движение однородного стержня массы М, скользящего внутри цилиндра радиуса R. Внутри однородного стержня движется точка массы m с постоянной скоростью v.

Решение[править]

Решаем, пользуясь уравнением Лагранжа 2-ого рода:

[math]\frac{d}{dt}\left(\frac{\partial T}{\partial\dot q_i}\right) - \frac{\partial T}{\partial q_i} = - \frac{\partial \Pi}{\partial q_i} [/math] , где

T - кинетическая энергия системы
П - потенциальная энергия системы
q - независимые обобщенные координаты

1) У данной системы одна степень свободы. В качестве обобщенной координаты возьмем угол отклонения стержня от заданного положения.

[math] q= \varphi [/math]

2) Выразим кинетическую и потенциальную энергию через эту координату и найдем производные, необходимые для решения уравнения Лагранжа:

[math] T= T1 + T2 [/math]

[math] T= \frac{1}{2}\ θ\ ω ^{2} + \frac{1}{2}\ m\ V ^{2} [/math]

[math] θ= \frac{1}{2}\ M\ R ^{2} [/math]

[math] T= \frac{1}{4}\ M\ R ^{2} \dot\varphi ^{2} + \frac{1}{2}\ m\ V ^{2} [/math]

[math] \Pi = m \ g\ x \sin(\varphi )\ [/math]


3)Продифференцировав энергии по обобщенной координате и ее производной, получаем уравнение:

[math] \frac{1}{2}\ M\ R ^{2} \ddot\varphi = m \ g\ v\ t \cos(\varphi )\ [/math]

4)Решив это дифференциальное уравнение, с нулевыми начальными условиями и зафиксированным углом наклона стержня, получим уравнение движения:

[math] φ = \arctan \frac {v\ t} {\\\sqrt {\\\frac {M\ R ^{2}} {3\ m}}}\ [/math]

Визуализация процесса[править]

Для моделирования колебаний данного маятника используются cледующие библиотеки:

  • three.js
  • dat.gui.js
  • stats.js



Текст программы на языке JavaScript:

Файл "Generalwork2.js"

  1 (function () {
  2 
  3 	
  4         var stats = initStats();
  5 		
  6         // create a scene, that will hold all our elements such as objects, cameras and lights.
  7         var scene = new THREE.Scene();
  8 
  9         // create a camera, which defines where we're looking at.
 10         var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
 11 
 12         // create a render and set the size
 13         var renderer = new THREE.WebGLRenderer();
 14 		
 15 
 16         renderer.setClearColor(new THREE.Color(0xEEEEEE, 1.0));
 17         renderer.setSize(window.innerWidth, window.innerHeight);
 18         renderer.shadowMapEnabled = true;
 19 
 20 	var OrbitControls= new THREE.OrbitControls(camera);
 21 		OrbitControls.autoRotate = false;
 22 		var clock = new THREE.Clock();
 23 	
 24 		
 25         var planeGeometry = new THREE.PlaneGeometry(150,60);
 26         var planeMaterial = new THREE.MeshBasicMaterial({color:0xE1EfE1});
 27         var plane = new THREE.Mesh(planeGeometry,planeMaterial);
 28         plane.receiveShadow  = true;
 29 
 30         // rotate and position the plane
 31         plane.rotation.x=-0.5*Math.PI;
 32         plane.position.x=10
 33         plane.position.y=-4
 34         plane.position.z=0
 35 
 36         // add the plane to the scene
 37         scene.add(plane);
 38 		
 39 		var sphereGeometry = new THREE.SphereGeometry(2/5, 20, 20);
 40         var sphereMaterial = new THREE.MeshLambertMaterial({color: 0xffdddd,transparent:false,opacity:0.2});
 41         var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
 42 
 43         // position the sphere
 44         sphere.position.x =0;
 45         sphere.position.y =0;
 46         sphere.position.z =0;
 47         // add the sphere to the scene
 48         scene.add(sphere);
 49  
 50 		//create a stick
 51 		var stickGeometry = new THREE.CylinderGeometry(1/2,1/2,7.7);
 52 		var stickMaterial = new THREE.MeshLambertMaterial({color: 0x7777ff,transparent:true,opacity:0.7});
 53         var stick = new THREE.Mesh(stickGeometry, stickMaterial);
 54 		
 55        // stick.castShadow = true;
 56 		
 57         stick.position.x=0;
 58         stick.position.y=0;
 59         stick.position.z=0;
 60 
 61         // add the cube to the scene
 62         scene.add(stick);
 63 
 64         // create a cube
 65 		
 66         var cylinderGeometry = new THREE.CylinderGeometry(4,4,10,30,10, true );
 67         var cylinderMaterial = new THREE.MeshLambertMaterial({color: 0xb3a1aa});
 68 		cylinderMaterial.side = THREE.DoubleSide;
 69         var cylinder = new THREE.Mesh(cylinderGeometry, cylinderMaterial);
 70 		cylinder.castShadow=true;
 71      //   cylinder.castShadow = true;
 72 
 73         // position the cylinder
 74 		cylinder.rotation.x=-0.5*Math.PI;
 75         cylinder.position.x=0;
 76         cylinder.position.y=0;
 77         cylinder.position.z=0;
 78 
 79         // add the cube to the scene
 80         scene.add(cylinder);
 81 
 82 		var group = new THREE.Object3D();
 83             group.add(sphere);
 84 			group.add(stick);
 85             scene.add(group);
 86 			
 87 		var arrowHelper = new THREE.ArrowHelper(new THREE.Vector3( 0, 1.0, 0.0 ), group.position, 10, 0xacd1c5);
 88 		scene.add( arrowHelper );
 89 		var arrowHelper2 = new THREE.ArrowHelper(new THREE.Vector3( 1.0, 0, 0.0 ), group.position, 10, 0xacd1c5 );
 90 		scene.add( arrowHelper2 );
 91 		var arrowHelper3 = new THREE.ArrowHelper(new THREE.Vector3( 0, 0, 1.0 ), group.position, 10, 0xacd1c5 );
 92 		scene.add( arrowHelper3 );
 93 		
 94 
 95         // position and point the camera to the center of the scene
 96         camera.position.x = 5;
 97         camera.position.y = 10;
 98         camera.position.z = 30;
 99         camera.lookAt(scene.position);
100 		
101 		
102 		
103         // add spotlight for the shadows
104 		var ambientLight=new THREE.AmbientLight(0x0c0c0c);
105 		//scene.add(ambientLight);
106         var spotLight = new THREE.SpotLight( 0xEEEEEE );
107         spotLight.position.set( 40, 60, 20 );
108         spotLight.castShadow = true;
109         scene.add( spotLight );
110 		
111 				var pointColor = "#65a54e";
112 				var pointLight1 = new THREE.PointLight(pointColor);
113 				pointLight1.distance = 20;
114 				scene.add(pointLight1);
115 				
116 				var sphereLight = new THREE.SphereGeometry(0.2);
117 				var sphereLightMaterial = new THREE.MeshLambertMaterial({color:0x65a54e});
118 				var sphereLightMesh = new THREE.Mesh(sphereLight, sphereLightMaterial);
119 				sphereLightMesh.castShadow = true;
120 
121 				sphereLightMesh.position = new THREE.Vector3(6, 5, -10);
122 				pointLight1.position = sphereLightMesh.position;
123 				scene.add(sphereLightMesh);
124 				
125 				
126 				var pointLight2 = new THREE.PointLight(0xff000d);
127 				pointLight2.distance = 20;
128 				scene.add(pointLight2);
129 				
130 				var sphereLight2 = new THREE.SphereGeometry(0.2);
131 				var sphereLight2Material = new THREE.MeshLambertMaterial({color:0xff000d});
132 				var sphereLight2Mesh = new THREE.Mesh(sphereLight2, sphereLight2Material);
133 				sphereLight2Mesh.castShadow = true;
134 
135 				sphereLight2Mesh.position = new THREE.Vector3(3, 8, 8);
136 				pointLight2.position = sphereLight2Mesh.position;
137 				scene.add(sphereLight2Mesh);
138 				
139 				var pointLight3 = new THREE.PointLight(222672);
140 				pointLight3.distance = 20;
141 				scene.add(pointLight3);
142 				
143 				var sphereLight3 = new THREE.SphereGeometry(0.2);
144 				var sphereLight3Material = new THREE.MeshLambertMaterial({color:222672});
145 				var sphereLight3Mesh = new THREE.Mesh(sphereLight3, sphereLight3Material);
146 				sphereLight2Mesh.castShadow = true;
147 
148 				sphereLight3Mesh.position = new THREE.Vector3(-8, 8, 6);
149 				pointLight3.position = sphereLight3Mesh.position;
150 				scene.add(sphereLight3Mesh);
151 				
152 				var pointLight4 = new THREE.PointLight(0x634ea5);
153 				pointLight4.distance = 20;
154 				scene.add(pointLight4);
155 				
156 				var sphereLight4 = new THREE.SphereGeometry(0.2);
157 				var sphereLight4Material = new THREE.MeshLambertMaterial({color:0x634ea5});
158 				var sphereLight4Mesh = new THREE.Mesh(sphereLight4, sphereLight4Material);
159 				sphereLight4Mesh.castShadow = true;
160 
161 				sphereLight4Mesh.position = new THREE.Vector4(6, 7, 4);
162 				pointLight4.position = sphereLight4Mesh.position;
163 				scene.add(sphereLight4Mesh);
164 				
165 				var pointLight5 = new THREE.PointLight(0xff000d);
166 				pointLight5.distance = 20;
167 				scene.add(pointLight5);
168 				
169 				var sphereLight5 = new THREE.SphereGeometry(0.2);
170 				var sphereLight5Material = new THREE.MeshLambertMaterial({color:0xff000d});
171 				var sphereLight5Mesh = new THREE.Mesh(sphereLight5, sphereLight5Material);
172 				sphereLight5Mesh.castShadow = true;
173 
174 				sphereLight5Mesh.position = new THREE.Vector3(-9, 4, -2);
175 				pointLight5.position = sphereLight5Mesh.position;
176 				scene.add(sphereLight5Mesh);
177 				
178 				var pointLight6 = new THREE.PointLight(0x4e9fa5);
179 				pointLight6.distance = 20;
180 				scene.add(pointLight6);
181 				
182 				var sphereLight6 = new THREE.SphereGeometry(0.2);
183 				var sphereLight6Material = new THREE.MeshLambertMaterial({color:0x4e9fa5});
184 				var sphereLight6Mesh = new THREE.Mesh(sphereLight6, sphereLight6Material);
185 				sphereLight6Mesh.castShadow = true;
186 
187 				sphereLight6Mesh.position = new THREE.Vector3(-4, 5, 12);
188 				pointLight6.position = sphereLight6Mesh.position;
189 				scene.add(sphereLight6Mesh);
190 				
191 				var pointLight7 = new THREE.PointLight(0xa54e9f);
192 				pointLight7.distance = 20;
193 				scene.add(pointLight7);
194 				
195 				var sphereLight7 = new THREE.SphereGeometry(0.2);
196 				var sphereLight7Material = new THREE.MeshLambertMaterial({color:0xa54e9f});
197 				var sphereLight7Mesh = new THREE.Mesh(sphereLight7, sphereLight7Material);
198 				sphereLight7Mesh.castShadow = true;
199 
200 				sphereLight7Mesh.position = new THREE.Vector3(-1, 8, -7);
201 				pointLight7.position = sphereLight7Mesh.position;
202 				scene.add(sphereLight7Mesh);
203      
204         // add the output of the renderer to the html element
205         $("#WebGL-output").append(renderer.domElement);
206 
207         // call the render function
208         renderer.render(scene, camera);
209 		var step = 1;
210 		var stepg=0.8;
211 		var d=1;
212 		var g=1;
213         var oldContext = null;
214 
215         // setup the control gui
216 		var omega,phi,c,time,dt,m , M;
217         var controls = new function () {
218             // we need the first child, since it's a multimaterial
219 			this.orbit=false
220             this.radiusTop = 4;
221             this.radiusBottom = 4;
222             this.height = 10;
223 
224             this.segmentsX = 30;
225             this.segmentsY = 10;
226 
227             this.openEnded = true;
228 			this.opacity = stickMaterial.opacity;
229 			
230 			this.pointColor = pointColor;
231             this.intensity = 0;
232             this.distance = 100;
233 			
234 			this.visible = cylinderMaterial.visible;
235 			this.side = "front";
236 			this.c=1;
237 			
238 			this.m=2
239 			this.M=10
240 			
241 			
242 			this.redraw=function() 
243 			{
244 			dt=0.01;
245 			time=0;
246 			delta=0;
247 			phi=Math.PI/3;
248 			c=controls.c;
249 			stick.rotation.z=phi;
250 			sphere.position.x=-2.9
251 			sphere.position.y=1.7
252 			}
253 
254         }
255 
256 
257 
258 	
259         var gui = new dat.GUI();
260 		
261 		gui.add(controls, 'opacity', 0, 1).onChange(function (e) {
262             stickMaterial.opacity = e
263         });
264 		
265 		gui.add(controls, 'm', 0.1, 10);
266 		gui.add(controls, 'M', 0, 10);
267 		gui.add(controls, 'orbit', false).onChange(function (e) {
268             OrbitControls.autoRotate = e;
269 			})
270 		gui.add(controls, 'redraw');
271 
272 		
273 		
274 
275 		controls.redraw();
276     
277         render();
278 		controls.redraw();
279 		
280 
281 		function render() {
282 					
283 			sphere.position.x+= d*0.034;
284 			sphere.position.y-= d*0.02;
285 			if (sphere.position.x>3.1) {d=-1}
286 			if (sphere.position.x<-3) {d=1}
287 			
288 			
289 			
290 			time+=dt;
291 			delta=(-d)*(Math.atan(0.04*time/4*Math.sqrt(controls.M/3*controls.m)))*dt;
292 			phi+=delta;
293 			group.rotation.z=phi;
294 			
295 			
296 			var x = clock.getDelta();
297 			OrbitControls.update(x);
298 					
299 			stats.update();
300 			requestAnimationFrame(render);
301             renderer.render(scene, camera);
302         }
303        
304 		
305 		  function initStats() {
306 
307             var stats = new Stats();
308             stats.setMode(0); // 0: fps, 1: ms
309             // Align top-left
310             stats.domElement.style.position = 'absolute';
311             stats.domElement.style.left = '0px';
312             stats.domElement.style.top = '0px';
313 
314             $("#Stats-output").append(stats.domElement);
315 
316             return stats;
317         }
318 
319        
320     });
321 window.onload = init;