News for hackers. Stuff that matters.
Re:Draw an iceberg and see how it would float in water by sgtnoodle on Saturday February 20, 2021 @02:20AM (#26202295)
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.

Re:Draw an iceberg and see how it would float in water by yarcob on Saturday February 20, 2021 @03:54AM (#26202751)
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.

Re:Draw an iceberg and see how it would float in water by yarcob on Saturday February 20, 2021 @04:15AM (#26202862)
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.

https://i.imgur.com/3OLflHc.png

Re:Draw an iceberg and see how it would float in water by sgtnoodle on Saturday February 20, 2021 @04:58AM (#26203022)
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.

Re:Draw an iceberg and see how it would float in water by yarcob on Saturday February 20, 2021 @05:16AM (#26203086)
> Do you have a notion of how the code actually computes bouyancy?

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.

Re:Draw an iceberg and see how it would float in water by sgtnoodle on Saturday February 20, 2021 @05:53AM (#26203224)
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.

https://ibb.co/T1KG5DM

Re:Draw an iceberg and see how it would float in water by yarcob on Saturday February 20, 2021 @08:58AM (#26204106)
That's brilliant!
Re:Draw an iceberg and see how it would float in water by sillysaurusx on Saturday February 20, 2021 @02:48AM (#26202407)
If anyone wants to do this, you're looking for "approximate convex decomposition": http://codesuppository.blogspot.com/2006/04/approximate-conv...

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.

Re:Draw an iceberg and see how it would float in water by arithma on Saturday February 20, 2021 @02:48AM (#26202409)
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.
Re:Draw an iceberg and see how it would float in water by 5600k on Saturday February 20, 2021 @06:19AM (#26203352)
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.