jonny-b said:
I'm a web developer.
I worked as web dev for one year. Iirc, such n-body problem appeared at least once, when the problem was to place some set of banners, available at two image sizes each, fitting a variable page size but picking larger images for more important banners.
I guess you'll often think back on me in the future, no matter what you work on.
But i don't want to be pedantic. It's just for good i'm sure. ; )
taby said:
@joej Are you familiar at all with linear regression?
Yes, a bit. I used it to calculate the average line from a point set. It worked using some least squares method, and i did not understand how exactly.
But then i found out it does not work well at all. It works best if the resulting line is aligned to the x or y axis. So i made an iterative solution, by rotating the point set to the line result of the former iteration. This kind of worked, but it was too slow. I saw this method often on the internet, but nobody pointed out it's accuracy depends on the orientation of input. It seemed most people were just unaware.
So i came up with a better solution: Calculate the averaged center of the points, then convert vectors from there to the points to angles, multiply all angles by two, calculate their averaged angle, finally divide the averaged angle by two, which gives the perfect average line i want in one step. We can get rid of trig by using complex numbers or vectors instead angles, and we can also have a weight for each point.
This is awesome. I use it to calculate curvature directions on meshes, crossfields, and all that remeshing stuff.
But it does not work in 3D. To do the same idea in 3D, we can use spherical harmonics. The third band of SH represents lines. But i found no way to extract the local maxima of the spherical function analytically. So i have to search for it with iterations, which is again slow. There must be a better way.
There was a thread here, about orienting bounding boxes to a good fit. Very similar problem, and @vilem otte gave some code to a solution based on matrices. I tried this, but could not get it to work.
Similar matrix math happens in my MPM fluid simulator. I do not fully understand the used math yet, but it somehow accumulates the adjacent velocity field to 3x3 matrix rows and columns, and then, doing a singular value decomposition we get a matrix which represents an ‘ellipsoid’ to describe the deformation of surrounding space due to pressure. That's awesome stuff, because SVD is pretty fast so we can do this for massive data.
I need to learn how this works in detail, so i can use it for other things… when i need it.
That's where i am.
@alvaro pointed out there exist regression methods which give accurate results in one step, iirc.
And David Eberly's codebase has many examples to fit certain shapes from points. Whenever i was stuck at math, his code did help me the most. I could not thank him enough, and would be still stuck at PacMan otherwise.
So i make my way, but i still lack many basics, like eigen vectors and values. And i lack experience with expressing problems in matrix form. I reinvent much more wheels than necessary.