johnxnguyen / newton Goto Github PK
View Code? Open in Web Editor NEWAn N Body Gravity Simulator.
An N Body Gravity Simulator.
Currently the Size
struct holds two non-negative integers to represent width and height. While this makes sense in most situations, its use within the Rectangle
struct leads to some undesirable side effects.
When we divide a Rectangle
into quadrants, we try to do so as evenly as possible. However this is not always possible since the Size
using integral numbers. Consider a Rectangle
instance with a width of 5 and a height of 5. Dividing this into quadrants leads to four sub-rectangles each with a width and height of 2.5. Since the width and height must be represented as an integer, these sub-rectangles must be adjusted to round off their width and height.
As such, instead of four equal quadrants, we now have 4 quadrants of varying sizes (the smallest would be 2 x 2, the largest is 3 x 3, and the two remaining quadrants are 2 x 3 and 3 x 2).
The use of integers for the width and height of Size
is necessary to provide well defined boundaries between the quadrants. In other words, it is not a suitable solution to allow the width and height of Size
to be floating point values.
Instead, to guarantee that dividing a rectangle produces 4 equal sized quadrants, I propose to restrict the width and height of a Rectangle
to be a power of two. This would require a few changes, namely:
Size
instance given an exponent of two (e.g. `Size::new(e: 5)' would produce a size with width and height equal to 32).When simulating a large number of bodies (> 20,000) it can happen that the program terminates due to an OutOfBounds
error. This happens when trying to determine which quadrant a body belongs to, but the body is not contained within the current space.
The error message reports that one of the coordinates of the body's position is very slightly larger than a whole number (e.g. 32.00005). It is likely that the last step in the path chosen in the tree is incorrect due to inaccurate comparisons of floating point numbers. Currently we're using f32
to store position coordinates, perhaps f64
would solve this issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.