EXAMPLE OF BODY SLIDING DOWN AN INCLINED PLANE IN PROCESSING
Let's create a simulation of a body sliding down an inclined plane.
The body is located on an inclined plane that is turned at some angle alpha in relation to the horizontal plane. The force of the earth's gravity Q acts on the body, and it can be decomposed into 2 components: Fa, which is in the direction parallel to the inclined plane, and FN, the normal component, which is in the direction normal to that inclined plane. The base reaction force N is compensated with this normal component because it is in the same direction, but in the opposite direction and does not affect the motion. The frictional force opposes the motion and has the direction of the inclined plane, but is in the opposite direction of the velocity vector.
In order for the body to start descending, the condition must be met:
In order for the body to start descending, the condition must be met:
Fa >= Ftr
The force of friction is a passive force and exists only if there is an active force that tends to cause the movement of the body and always has the same direction as the velocity of the body, but the opposite direction. In this case, the active force is the component in the direction of the base from the weight of the body, denoted by Fa.
The force of friction on the one hand depends on the type of surface and its influence is measured by the coefficient of friction, and on the other hand, it also depends on the intensity of the normal force on the surface N. The force of friction is therefore calculated:
The force of friction on the one hand depends on the type of surface and its influence is measured by the coefficient of friction, and on the other hand, it also depends on the intensity of the normal force on the surface N. The force of friction is therefore calculated:
Ftr = μ * N;
where is
μ - coefficient of friction,
N - normal force acting on the plane
In order to create a simulation, let's see a right-angled triangle that represents the ground on which the body slides in the direction of the hypotenuse.
the legs of the triangle are known and we will mark the opposite one with H (height), and the adjacent one with L.
The angle alpha can be determined by:
the legs of the triangle are known and we will mark the opposite one with H (height), and the adjacent one with L.
The angle alpha can be determined by:
alpha = atan(H/L);
We will create the simulation in a moving coordinate system related to the body (X1 O1 Y1)
A moving coordinate system can be obtained by translating the XOY coordinate system first by H-height/2-h/2/cos(fi) and then by rotating it by an angle fi.
Let's open a new sketch, add setup and draw methods. In them we can set the background color background(100) and create triangle and body (rectangle) shapes.
In order to be able to create a triangle, it is necessary to first define and initialize the height H, as well as the length L. Within the setup method, we can calculate the angle of inclination via the atan( H/L):
To create the body, as well as the triangle, we use processing's PShape class
(see reference: https://processing.org/tutorials/pshape)
The variables w and h represent the width and height of the body. Fill colors are set for these two shapes, using the setFill() method and using the color() method, which creates a color based on RGB values.
Next, we move the koo system using translations as shown in the following code:
To create the body, as well as the triangle, we use processing's PShape class
(see reference: https://processing.org/tutorials/pshape)
The variables w and h represent the width and height of the body. Fill colors are set for these two shapes, using the setFill() method and using the color() method, which creates a color based on RGB values.
Next, we move the koo system using translations as shown in the following code:
If we run the application we will see:
The next thing to do is rotate by an angle fi, and move the initial position by translation by 50px:
rotate(fi);
translate(50,0);
translate(50,0);
We will also draw the coordinate axes to follow how the moving system moves: Now the code looks like in the following picture:
Adding movement to the body
To introduce body motion, we need to add the following variables:
PVector position;
PVector v;
PVector a;
static final float G=9.81;
float m=1;
PVector v;
PVector a;
static final float G=9.81;
float m=1;
The position vector determines the center point of a body sliding on an inclined plane. The (v) is the speed of the body, a is the acceleration, G is the gravitational constant and m is the mass whose value is set to 1kg.
Inside the setup() method, the following code should be added:
Inside the setup() method, the following code should be added:
//Creation of acceleration, velocity and position vectors required for body movement
a=new PVector(1,0);
v=new PVector(0,0);
position=new PVector(50,0);
a=new PVector(1,0);
v=new PVector(0,0);
position=new PVector(50,0);
Inside the draw() method, add the following:
//movement
v.add(PVector.div(a,frameRate));
position.add(v);
translate(polozaj.x,polozaj.y);
v.add(PVector.div(a,frameRate));
position.add(v);
translate(polozaj.x,polozaj.y);
The value of the acceleration intensity a is first divided by the constant frameRate, in order to obtain the change in speed for the time interval between two calls to the draw() method. This value is added to the velocity vector, which will increase its intensity. Finally, the change in position is defined by the value v, so the add method is used for the vector addition of the position and the velocity vector v.
Read more about vectors on the page: Vectors in Processing.
Read more about vectors on the page: Vectors in Processing.
The complete sketch can be seen in the following image, where the movement code has been added, underlined by red lines:
The "draw" function is shown below:
In the image below, you can see what the animation of a body sliding down an inclined plane looks like.
Animation not working? Please refresh the page
← scroll horizontal →
Processing example: Inclined plane 2
The previous example of a body sliding down a steep plane can be further developed, so that by clicking on the control point, we select it, and then with mouseDragged() we change its height, and thus the angle of inclination of the inclined plane changes. The following data should also be displayed: Sliding speed, angle of inclination, friction force-intensity, as well as the coefficient of friction. The animation is shown below, and the solution (code) is on the next page.
Animation not working? Please refresh the page
← scroll horizontal →
Read the explanation and complete analysis of the example on the page: Analysis of sliding of a body down an inclined plane example