Also, the code has been amended right where this comment is:
// People like to draw shapes with kinks, which results
// in part of the polygon being treated as negative area.
// turf.unkinkPolygon can be used to find the kinks and
// separate the polygon into multiple polygons at the
// kinks, but it's a little fragile and hard to combine
// into a single unkinked polygon. [...]> turf.unkinkPolygon=(x)=>x;
Press F12, click 'Console', copy-paste the above one and press Enter.
Even more optimal: https://imgur.com/7gCEJ0T
I've had more extreme versions of this shape teleport off-screen, when starting them under water: https://imgur.com/ymVtTWq
And here's someone holding a balloon: https://imgur.com/8O4rib8
I believe it works because the sail consists of negative mass. The overall mass of the boat is therefore lower, but the part of the hull that's under water produces the same amount of bouyancy based on the area of displaced water. Because of the width of the hull, it's a stable equallibrium.
Interestingly, if the sail were to become submerged, it would create negative bouyancy and the boat would sink!
Any convex shape will tend to minimize the forces due to buoyancy and "horizontal" should always go less deep (or equal for a sphere) than "vertical"
It can be in a local minima of buoyancy without being a global minima. Similar to an un-sharpened pencil balanced on it's end.
(there are about 4 completed saw tooths above the screen)
My guess is that the object's mass and inertia is calculated in a way that is sensitive to the handedness of the drawing. The code probably takes the absolute value of the result so that right-handed and left-handed drawings both end up with positive mass. When you draw lobes though, the signedness alternates and cancels out, leading to less mass. With even numbers of lobes of near equal size, you end up with near zero mass.
The forces being computed on each primitive are probably representative of that primitive's true mass. Subsequently applying those same forces to a rigid body with significantly less mass therefore results in extreme acceleration. f=ma, f/m=a. f/0=explode.
Both of these algorithms basically sum up the "signed area" of the polygons. This means that if you circle something twice, it'll count twice, and the sign depends on the direction of the winding.
The confusing part is that when the polygon is drawn, it uses the "non-zero winding rule" to determine which part to fill. So the filled parts of the polygons are all parts that contribute non-zero parts to the area (eg. positive, negative, two time positive etc.).
So the weird behaviour is that the physics simulation doesn't use the same rules as the visualisation!
So the nice thing about these algorithms is that it works for arbitrary complex shapes as long as the path has no self-intersections.
If you want to add support for self-intersecting paths, you need to decide how to deal with intersections. Presumably you'd want the physics to match the visualisation, ie. use the non-zero winding rule also for centroid and area calculations. To do that, you would first need to split the polygon into non-intersecting parts, and then calculate the area separately for each part, and then sum up the absolute values of the individual parts.
Good catch with the discrepancy between the physics and the visualization. I wonder if there's a way to engineer a cool structure with a lot of invisible mass.
Do you have a notion of how the code actually computes bouyancy? Does it somehow slice the polygon into two at the water line and then compute center and area of both? Once again, it would be interesting to engineer an object that leverages any non-linear behaviors at the water line, perhaps like an object whose mass changes depending on its position and orientation.
Weight force (downward) is determined by the full polygon.
Buyancy force (upward) is determined by the part below the water line.
Lateral/angular motion results from the fact that the forces act on the centroids of the full polygon vs the centroid of the submerged polygon.
The script seems to use a JS library named "turf" to clip the polygon at the water line. Here's the line in the source:
var pp = turf.bboxClip(p, [-Infinity, yZero, Infinity, Infinity]).geometry.coordinates[0];
As far as I can tell, yZero is the water line, and pp is the part of the polygon that is submerged.
It was one of the grand challenges in the 00's, quietly solved by John Ratcliff. Then a few people solved it after him.
It's a fun algorithm. You basically slice and dice, like chopping a potato, then recombine small parts together based on a heuristic.
Kip Thorne wrote of something that involved an extreme amount of mass in a spinning cylinder. That kind of mass was imagined to be at a huge scale like harnessing a number of stars and compressing them, iirc.
A device theorized or implemented by Salvatore Pais involves use of superconductors and microwaves to create an effective vacuum, like dragging part of spacetime. It could allow FTL relocation without actual speed. This could also create an area of effectively high masses that could allow time travel, even eventually reverse time travel, under theoretical conditions.
It flys!
And some of them completely disappear!
To really throw it off and make it stay underwater or hop around, you must be quick to reduce the points and create negative areas via crossover.
But it’s impressive how it lets you draw beyond the boundaries and reacts reasonably.
Best iceberg simulator I’ve ever used. I had fun playing with it for at least ten minutes. I’d go so far as to recommend it for education.
Also, what is the dependent relationship between stable states and non-stable state systems? Is it more simple than thought before?