মূল বিষয়বস্তু
কম্পিউটার প্রোগ্রামিং
Course: কম্পিউটার প্রোগ্রামিং > Unit 5
Lesson 5: বল- নিউটনের গতিসূত্রসমূহ
- চ্যালেঞ্জ: ভাসমান বেলুন
- অনেকগুলো অবজেক্টের গতি
- চ্যালেঞ্জ: দেয়ালে বল
- মহাকর্ষ এবং ঘর্ষণ মডেল
- চ্যালেঞ্জ: গতিরোধকারী
- বায়ু এবং আবর্ত ঘর্ষণ
- চ্যালেঞ্জ: ডুবন্ত কাঠ
- মহাকর্ষীয় আকর্ষণ
- চ্যালেঞ্জ: নকশা উৎপাদক
- পারস্পরিক আকর্ষণ
- চ্যালেঞ্জ: পারস্পরিক বিকর্ষণ
- প্রকল্প: বাস্তুসংস্থান তৈরি
© 2023 Khan Academyব্যবহারের শর্তাদিগোপনীয়তার নীতিমালাকুকি নোটিশ
বায়ু এবং আবর্ত ঘর্ষণ
যখন কোন বস্তু তরল বা বায়বীয় পদার্থের মধ্যে গতিশীল থাকে তখন ঘর্ষণের উৎপত্তি হয়। এইভাবে সৃষ্ট ঘর্ষণ বলের নাম প্রবাহী ঘর্ষণ। ঘর্ষণ কয়েক প্রকারের হয়ে থাকে যেমন: স্থিতি ঘর্ষণ, পিছলানো ঘর্ষণ, আবর্ত ঘর্ষণ। কিন্তু এগুলির ফলাফল মূলত একই হয়ে থাকে (যা বস্তুকে ধীর করে দেয়)। তবে ক্ষেত্র বিশেষে আমাদের ঘর্ষণ বলের সূত্রের হিসাব কিছুটা পরিবর্তিত হবে। আমরা সূত্রটি দেখি:
সূত্রটিকে সরল করার জন্য এটিকে ভেঙে দেখি যে ProcessingJS এর একটি কার্যকরী সিমুলেশনের জন্য আমাদের কি প্রয়োজন।
- F, start subscript, d, end subscript refers to drag force, the vector we ultimately want to compute and pass into our
applyForce()
function. - -1/2 is a constant: -0.5. This is fairly irrelevant in terms of our ProcessingJS world, as we will be making up values for other constants anyway. However, the fact that it is negative is important, as it tells us that the force is in the opposite direction of velocity (just as with friction).
- rho is the Greek letter rho, and refers to the density of the liquid, something we don’t need to worry about. We can simplify the problem and consider this to have a constant value of 1.
- v refers to the speed of the object moving. OK, we’ve got this one! The object’s speed is the magnitude of the velocity vector:
velocity.mag()
. And v, squared just means v squared or v, times, v. - A refers to the frontal area of the object that is pushing through the liquid (or gas). An aerodynamic Lamborghini, for example, will experience less air resistance than a boxy Volvo. Nevertheless, for a basic simulation, we can consider our object to be spherical and ignore this element.
- C, start subscript, d, end subscript is the coefficient of drag, exactly the same as the coefficient of friction (μ). This is a constant we’ll determine based on whether we want the drag force to be strong or weak.
- v, with, hat, on top Look familiar? It should. This refers to the velocity unit vector, i.e.
velocity.normalize()
. Just like with friction, drag is a force that points in the opposite direction of velocity.
সূত্রের প্রত্যেকটি অংশ বিশ্লেষণ করার পর আমরা এই সাধারণ সিমুলেশনের জন্য সূত্রটিকে সরল করেছি যা নিচে দেওয়া করা হল:
or:
// Part 1 of our formula (magnitude): v^2 * Cd
var c = 0.1;
var speed = velocity.mag();
var dragMagnitude = c * speed * speed;
// Part 2 of our formula (direction): v unit vector * -1
var drag = velocity.get();
drag.normalize();
drag.mult(-1);
// Magnitude and direction together!
drag.mult(dragMagnitude);
এসো আমরা এই বলকে
Mover
অবজেক্টে যোগ করি। যখন আমরা ঘর্ষণের উদাহরণটি লিখেছিলাম, ঘর্ষণের বলটি তখনও উপস্থিত ছিল। যখনই কোন বস্তু গতিশীল থাকে, ঘর্ষণ তার গতি রোধ করে। এখন, এসো আরেকটি নতুন উপাদান যোগ করি যা হল—একটি “liquid”(তরল) মাধ্যম যা ভেদ করে Mover
অবজেক্ট গতিশীল হয়। Liquid
অবজেক্টটি একটি আয়তক্ষেত্র হবে এবং এটির অবস্থান, প্রস্থ, উচ্চতা এবং “ড্র্যাগের (প্রতিবন্ধকের) সহগ”—ইত্যাদি আমাদের জানা থাকবে, অবজেক্টটি কি এই মাধ্যমে সহজভাবে (বায়বীয় মাধ্যমের মত) চলতে পারবে নাকি এটি কঠিন হবে? এর সাথে, একটি ফাংশন থাকতে হবে যার সাহায্যে এটি পর্দায় নিজেকে আঁকবে (এবং আরও দুইটি ফাংশন, যা আমরা একটু পরেই দেখবো)।var Liquid = function(x, y, w, h, c) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.c = c;
};
Liquid.prototype.display = function() {
noStroke();
fill(50);
rect(this.x, this.y, this.w, this.h);
};
এখন মূল প্রোগ্রামে একটি নতুন
Liquid
অবজেক্টের অস্তিত্ব তৈরি হবে। লক্ষ্য কর যে, সহগটি ছোট (0.1), নইলে অবজেক্টটি তাড়াতাড়ি থেমে যাবে (কোন এক সময় তুমি এমনটিই চাইতে পারেন)।var liquid = new Liquid(0, height/2, width, height/2, 0.1);
এখন একটি মজার প্রশ্ন: আমরা কীভাবে
Mover
এবং Liquid
অবজেক্টের মধ্যে সমন্বয় সাধন করবো? অন্যকথায়, আমরা নিচের মত করতে চাই:যখন একটি mover একটি liquid (তরল) এর মধ্যে দিয়ে যায় তখন এটি একটি ড্র্যাগ (প্রতিবন্ধক) বল অনুভব করে।
…অথবা অবজেক্ট অরিয়েন্টেডের ক্ষেত্রে (ধরে নিচ্ছি আমরা
Mover
অবজেক্টের অ্যারেতে i
সূচক নিয়ে লুপ করছি):// Mover কি তরল (liquid)?
if (liquid.contains(movers[i])) {
// ড্র্যাগ (প্রতিবন্ধক) বলের হিসাব
var dragForce = liquid.calculateDrag(movers[i]);
// Mover এ ড্র্যাগ (প্রতিবন্ধক) বল প্রয়োগ
movers[i].applyForce(dragForce);
}
উপরের কোডটি থেকে বোঝা যায় যে আমাদের
Liquid
অবজেক্টে আরও দুইটি ফাংশন যোগ করতে হবে: (1) Mover
অবজেক্ট Liquid
অবজেক্টের ভেতরে আছে কিনা তা যাচাই করার জন্য একটি ফাংশন এবং (2) Mover
অবজেক্টের উপর ড্র্যাগের (প্রতিবন্ধক) বল হিসাব করার জন্য আরেকটি ফাংশন।প্রথমটি সহজ; আমরা একটি কন্ডিশনাল স্টেটমেন্ট ব্যবহার করে যাচাই করতে পারি যে অবস্থান ভেক্টর liquid (তরল) দিয়ে তৈরি আয়তক্ষেত্রের মধ্যে আছে কিনা।
Liquid.prototype.contains = function(m) {
var p = m.position;
return p.x > this.x && p.x < this.x + this.w &&
p.y > this.y && p.y < this.y + this.h;
};
যদিও
drag()
ফাংশনটির জন্য আগে থেকেই কোড লেখা আছে; তবুও, এটা একটু জটিল। এটি শুধুমাত্র আমাদের সূত্রের একটি প্রয়োগ। ড্র্যাগ বল হল বেগের বিপরীত দিকে ড্র্যাগের সহগ গুণ Mover
এর গতির বর্গের সমতুল্য।Liquid.prototype.calculateDrag = function(m) {
// Magnitude is coefficient * speed squared
var speed = m.velocity.mag();
var dragMagnitude = this.c * speed * speed;
// Direction is inverse of velocity
var dragForce = m.velocity.get();
dragForce.mult(-1);
// Scale according to magnitude
dragForce.normalize();
dragForce.mult(dragMagnitude);
return dragForce;
};
অবশেষে
Liquid
অবজেক্টের সাথে এই দুইটি ফাংশন যোগ করার পর, আমরা এখন সম্পূর্ণ কোড মূল প্রোগ্রামে বসাতে প্রস্তুত:Running the program, you should notice that we are simulating balls falling into water. The objects only slow down when crossing through the blue area at the bottom of the window (representing the liquid). You’ll also notice that the smaller objects slow down a great deal more than the larger objects. Remember Newton’s second law?
A = F / M
. Acceleration equals force divided by mass. A massive object will accelerate less. A smaller object will accelerate more. In this case, the acceleration we’re talking about is the “slowing down” due to drag. The smaller objects will slow down at a greater rate than the larger ones.এই "প্রাকৃতিক সিমুলেশন" কোর্সটি নেওয়া হয়েছে Daniel Shiffman (ড্যানিয়েল শিফম্যান) এর লেখা "The Nature of Code" (কোডের প্রকৃতি) থেকে এবং এটি ক্রিয়েটিভ কমন্সের এট্রিবিউশন-নন কমার্শিয়াল 3.0 আনপোরটেড লাইসেন্সের অধিনস্ত।
আলোচনায় অংশ নিতে চাও?
কোন আলাপচারিতা নেই।