Simulating Physics!

I tried do this for a while now and I have to admit it was more challenging than I thought. I had to revise some topics on physics just to get a clear handle on theories I was trying to simulate. Overall, it was a fun project and I am glad it came out just well.

My intentions were to simulate physics based environment where object would be acted upon my real-world-like physical forces. I know there are libraries out there that does this for us and also provide better performance and speed. But, I wanted to try it on my own.

Here's how I divided my work:

1. The Core
The Core package consisted mostly of physical quantities such as Position, Velocity and Acceleration. They mostly had the simple mathematics in them, that did most of the dirty works.

2. The Environment
The environment provides room for existence to the elements and it was my main engine where the elements were added and were acted up. Environment had its own properties like gravity, air frictions and boundary.

This piece of code represents general work in this module:

```for element in self.elements:
if element != selectedParticle:
element.animate()
element.draw(self.screen)
self.handleCollision(element)```

3. The Element
Element was my abstract representation of real-world object which had properties like mass, color, velocity, position and many others. Elements were added to the environment and where subjected to forces in the environment.

4. Objects
I started with a Circle, that represented a ball like object, and worked my way up-to simulating square blocks. Circles, besides representing a real-world ball, acted as pressure-points for other objects. Pressure-points were useful because these were the actual points that worked as points for exchanging forces upon collision which simulated all sorts of interesting properties like translation and rotation easily.

For example a bar consisted of two pressure points at either end. This would allow us to easily simulate bar-like properties especially rotation experienced due to difference in direction of force at either end of the bar.

The point of collision besides those pressure points could be interpolated easily. Square had a similar layout. It had these bars as its edges, protecting it from all angles.

4. Collision Handling
Collision Handling was modeled using the principle of conservation of linear momentum combined with law of conservation of energy. There was a small problem I face while implementing this approach to my models. The problem was the behavior of  objects upon interaction while there velocity neared zero. There was only one force acting that time, and it was gravity which was constantly pulling objects downwards. This was a problem, because when the objects were on top of each other, the object would collapse, unrealistically, because they had no force left in them to counteract gravity. There was a simple workaround to the problem, but it was not a wise one. Whenever two object came in contact with one another, a small force(in all four direction) would always be acting to prevent collapsing thus separating objects apart.

This was the model I went with. I am planning to share the code in near future as well. Here's a small video of the program in action:

It's not much, but it was a fun :) Let me know if you have any suggestions or feedback. Thanks!

BusyNote! - What is it?

I recently uploaded a small app called BusyNote on PlayStore. So, in this post I am going to talk about what it is, what it does, and also share some useful resources that I used to make the app.

BusyNote is basically an app to let people know that you are currently busy and you are not currently available for cellular contact. So, when activated this app just detects missed calls and sends pre-defined notification to callers letting them know you are in a "situation" and can't answer the phone. The need to the app was initially personal. When I was on my bike, I couldn't answer my calls (obviously) and this was a problem when I was travelling during late hours and the caller was generally my parents worried and trying to reach me. So, I thought why not make an app to help my situation. And here-we-are!

The app is available on PlayStore and you can find it from this link: BusyNote

Useful resources

Here are some resources that I used to build this app.

1. Ormlite

Object Relational Mapping Lite (ORM Lite) provides some lightweight functionality for persisting Java objects to SQL databases while avoiding the complexity and overhead of more standard ORM packages. It supports a number of SQL databases using JDBC and also supports Sqlite with native calls to Android OS database APIs. It is very handy and very easy to use.

2. Android Circle Button

Android Circle Button is a widget for android, easily available via gradle. The widget is very stylish and looks good on mobile phones. I used a modified version of the widget to support "Texts" and also added small extra features.

3. Android Sliding Up Panel

Android Sliding Up Panel is a widget by Umano Team, and I loved it. It is available on github and you can easily import it to your project via Gradle.  It provides simple way to add a draggable sliding up panel to your Android application.
Hope you find these resources useful. Also, don't forget to try the app (follow this link) and give it some love ;)

Please let me know what you thought of it or if you have any such feedbacks. Thanks!