The first step is to render a circle. The process works as follows.
The intuition:
Say you want to draw a circle on a canvas. The display only recognizes triangles. Say you draw a triangle with vertices: (0, 0), (50, 0), (0, 50). The graphics library can render better approximations of a circle with more pizza slices.
Draw_Circle Function:
The parameter cx, cy, and r is fed into the draw circle function.
Draw triangles using the graphics library functions begin(triangle_fan), vertex(x,y), and end().
Use the following trigonometric identities cos(angle), sin(angle).
The next step would be to implement movement. Planets accelerate and have velocity on top of their position coordinates.
The intuition:
Say you want to implement an acceleration and velocity feature every time the canvas updates.
For each planet:
Planets don’t move linearly, they affect the planets around them given their relative distance and mass. This push and pull phenomenon is described by Newton's Orbital Mechanics.
The intuition:
Say we have the Sun and three other planets. We can describe the planet being moved as p and other planets as other. We can show the position of p after some dt as follows:
set acceleration of x and y directions to 0.
for every other planet p1, p2, p3… pn, not including our planet pi:
first find the distance r
calculate the acceleration (nudge) from every other planet and add it to ax and ay
outside the for loop:
nudge the planet's velocity for some delta t, and nudge the planet's position for some delta t to get our new and updated position with respect to a tiny change in time.
observations:
*planets fling out once they accelerate too close into the orbit
*planets move faster the closer they get to the Sun
*the Sun wobbles due to the gravitational pull of planets that are closer and have more mass!
todo:
# add a border collision function # symmetrical simulation # object cluster # start from scratch # make it 3D # need a camera with an fov position and direction # need a Shader program with vertex array objects and vertex buffer objects # render a sphere # Gravity is the pull factor of masses towards each other. This is not accurate. It was, until Einstein's relativity theory. # Gravity isn’t a force at all. When you stand still, the ground pushes you up. This is called the normal force, and it stops you from following the natural curvature of space time towards Earth’s center. According to Einstein, gravity is a phenomenon of gravity curving space time.Forces, like the normal force, only act to resist the path of the geometry of space time, like the ground halting your fall. Space tells matter how to move. Matter tells space how to curve. # Visualizing curved space time # Implement Flamm’s paraboloid # Add solar system and black holes
Reference: Simulating Gravity in C++ - kavan Learn by Building - real projects for physics, robotics & graphics


