I think this was patched just now. On my last visit a few minutes ago the bug still worked, now it removes any larger bits where the lines intersect.
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. [...]
I'm having so much fun with the before-the-fix version, you can make it "jump" out of the water, if you draw a figure 8 under water, and when the negative lobe is at the top and around 75% of the size of the positive one
I spent... longer than I should have trying to take advantage of this bug to
recreate a stable version of the stereotypical tall iceberg that the original tweet was complaining about.
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!
Cool, I stand corrected. I tried with a few triangles of my own but they never stayed upright, but maybe I just suck at drawing and they all started too far off-center to remain in the little "valley" of the stability diagram.
You can create pontoons by circling over the same spot repeatedly. It's like you're concentrating more mass into the same area but reducing the density!
The code must somehow compute bouyancy in a way that reflects the object's arbitrarily complex shape. It's likely carving the object up into some number of smaller primitive objects whose equations for bouyancy are known. In order to make the whole object move as one rigid body, though, it's probably computing force vectors for each primitive, and then summing them together based on the overall object's center of mass and moment of inertia.
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.
If you look at the source, you'll see that it doesn't really try to split the path into smaller primitives at all. It uses a simple algorithm (https://stackoverflow.com/a/33852627) to calculate the center of mass, and another algorithm to calculate the area (https://stackoverflow.com/a/33670691).
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.
I annotated a screenshot with winding numbers. You'll see that the filled areas correspond to the parts with non-zero winding numbers, but the physics simulation considers the sign and magnitude.
Thanks for tracking down the actual algorithms! It appears that they work by summing the "signed" areas of half-trapezoids formed between each neighboring pair of vectors and an arbitrary axis line, so I'm going to stand by my claim that the code breaks the polygon up into smaller primitives. :-)
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.
Lol, thanks for the info. I was able to engineer an iceberg-boat. The boat is low mass but high bouyancy. If it were to be fully submerged, it would remain partially sunk.
I knew this was happening, but reading it, hey, maybe that's one way to get anti-gravity. Just loop the topology on itself. Obviously commenting in jest, but now I'm intrigued to see if someone has seriously considered this.
One of the theoretical reverse time travel machines I read about in the past involved stabilizing a wormhole first and then dragging it somewhere else, like to the future relative to current time by traveling near light speed with it, so you could get back to the earlier time.
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.
I draw an ice cream cone. First draw the ice cream like you would a cloud. Once connected then continue to draw the cone , such that you draw a V to connect to the ice cream.
If you extend the infinity sideways (easy with touch, hard with mouse) it seems to depend on how many lobes there are. 3, 5, or 7 is stable, 4, 6, or 8 is very unstable.
Given how much the behaviour varies at different angles and in different positions, we can be fairly sure the algorithm used is incorrect even without these odd cases. You can also see odd orientation-dependent behaviours with non-weird shapes.
Symmetric and asymmetric behavior baffles me. Any progressive papers on the independent relationships between infinite limits, finite quantities, and asymmetric phenomenon would be much appreciated from the homestead.
Also, what is the dependent relationship between stable states and non-stable state systems? Is it more simple than thought before?
I tried with a timeglass-like shape. It flew around the map, going in and out of view and eventually setting on/in the water https://i.imgur.com/kcT9elV.jpg