Physics
- Force of gravity = mass * gravity acceleration
- Force of slide = force(gravity)*cos(plane angle)
- Force of friction(opposite to slide) = friction coefficient *force(gravity) * sin(plane angle)
Additional force(custom push) from top of view:
//horizontal application(from top of view) of setted in ui the force
cube.force_x = force.magnitude*Math.cos(Math.PI*force.angle/180+Math.PI)*-1;
cube.force_result = cube.force_slide + cube.force_friction + cube.force_x;
cube.acceleration_x = cube.force_result/ cube.mass; // from F = m*a
cube.init_velocity_x = 0; // set start point
//vertical(from top of view) application of setted in ui the force
cube.force_y = force.magnitude*Math.sin(Math.PI*force.angle/180);
cube.acceleration_y = cube.force_y/ cube.mass; // from F = m*a
cube.init_velocity_y = 0; // set start point
Start the simuluation by moving with the initial speed equal to zero, then with Δd=V(init)*time + (1/2)*acceleration*time^2
move points to delta and increase the init speed through acceleration.
The time is frame iteration, 1000/24, for example.
Code
Idea:
Sketch of UI:
Real screenshot:
Structure:
- objects_render is for buffers, program, shaders of WebGL
- glmjs are helping files, glmjs library(matrix operations) and helper file, where code for rotate object, move by glmjs.
- objects_logic files of plane, cube, time, force...
plane {
vertices; //array positions, colors
angle; //degree
inclane(angle) {
//inclane plane and cube
cube.inclane()
}
}
cube {
vertices;
mass; //kg
build_physics(); //calculate forces and accelerations
inclane(); //also
}
force {
vertices; //vizualiation, blue line
angle; //degree
magnitude; //newton
inclane();
}
time {
//some coefficients and iter of time
}
for example plane object:
As possible to see in the screenshot this simulation is using additional arrays for vertices, in example of the plane it is just a "backup" of original vertices, but for the cube: more easy just move cube in x,y(top of view),store this position and render it in another array with x,y + inclane...
Tried to test with real physics(I mean in the room with paper and matches) looks the similar. Also I added acceleration coefficient for "slow motion" because all happening so fast. But it is my philosophy interpretations...
Code here:
https://github.com/fakelaboratory/publish/tree/main/Newton's%20laws%20of%20motion
Test through browser:
https://fakelaboratory.github.io/publish/Newton's laws of motion/
Top comments (1)
Also have some idea about using the data in experiments:
play only one "preexperiment" with storing the data(time, what changing by time in each frame, frame like a matrices), then replay experiments with this stored data but with correction by coefficients...
For example we have a data about the angle 30 and the force 4 - without recalc of physics(by formulas), achieve new experiment but with "training" "restore" from data
Add to n frame k1, k2, k3, k4(and for all next frames);
Add to m frame l1, l2, l3, l4(and for all next frames);
Then replay from data...
I mean maybe someone interested to connect AI to physics.