NOC – Week 4: Forces – Katie Pellegrino

Assignment 4

Link to Assignment
Inspiration

For our assignment on applying forces to objects, I wanted to experiment with gravity and attempt a sketch for mutual attraction/repulsion. I was inspired by a scene in Blue Planet II in which sea turtles walk onto a beach to nest. I wanted to mimic how they appear to be attracted to each other’s walking, yet do not run into each other. In retrospect, I’m not sure if mutual attraction/repulsion is the best method to mimic this phenomena (especially without collision detection), however, it was super interesting to explore this concept in greater detail.

potato
Aerial view of sea turtles nesting on a beach. –BBC Blue Planet II–
Construction

The main sketch essentially does three main things. It first declares and sets up a class of Mover objects. Then in the ‘draw’ loop, it cycles through each mover in a ‘for’ loop, and then, for each mover, cycles through the mover objects again in a nested ‘for’ loop. Because each object should be attracted to the other, the nested ‘for’ loops allow each object to talk to each other object in order to define the amount of force that should be applied.

The amount of force applied is dependent on the object’s mass and the distance that they are from each other. Therefore, the ‘attract’ function, which is called for every object cycled through each object, essentially collects the objects’ distance from each other (magnitude of the vector made by subtracting the ‘currentPosition’ from the ‘targetPosition’) and the direction of the applied force by normalizing it. The method then determines the appropriate strength of the force by using the equation for gravity ((gravity constant * the mass of each object ) / distance squared) and multiplies this strength by the force vector (which previously only stored the direction). This force vector, which now has both direction and magnitude, is returned and applied to the object from the ‘for’ loop.

Finally, after the sketch has applied the force, it updates the objects and displays them. 

Part of my admiration of the image of the nesting turtles were the beautiful trails that they left behind in the sand. So I tried lowering the opacity of the background in my sketch to create this effect. My next goal was to consider switching the sketch from mutual attraction to mutual repulsion because the turtles were moving rather uniformly but not bumping into each other. Overall, however, neither mutual attraction or repulsion are a great method for making this phenomena happen because the turtles walk rather individually of each other. Perhaps the collision detection would’ve been a better implementation.

After concluding that the sketch was not going to mimic the nesting turtles, I decided to add a particle class just for fun. However, I didn’t apply their ‘update’ function so they are motionless figures. I think the stillness creates a nice contrast to the mutual attraction of the Movers class.

Final Remarks

Coding this sketch was quite confusing, but rewarding. I’m still interested in how to code a scene that mimics the nesting turtles, however, I learned a lot in this project about how to have objects interact with each other along with how to use gravitational attraction.

Leave a Reply