Live data from Hacker News

Draw an iceberg and see how it would float in water

joshdata.me

91–100 of 179 posts

Re: Draw an iceberg and see how it would float in water

#91
post #85

Earlier quoted context omitted.

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 mas…

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 t…

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

#92
post #71
post #9

I get interesting results if I draw a figure 8 (or a figure ∞). I wonder if it's treating one of the lobes as having negative density.

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. https://imgur.com/a/WG6D0RJ

I was able to make sailboats that float if I cross the line over itself so the sail is in "negative space", which keeps it upright. Kinda neat!

https://i.imgur.com/2LZn50v.png

Re: Draw an iceberg and see how it would float in water

#94
post #9

I get interesting results if I draw a figure 8 (or a figure ∞). I wonder if it's treating one of the lobes as having negative density.

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.

Re: Draw an iceberg and see how it would float in water

#95
post #85

Earlier quoted context omitted.

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 t…

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 st…

> 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

#96
post #9

I get interesting results if I draw a figure 8 (or a figure ∞). I wonder if it's treating one of the lobes as having negative density.

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.

It’s very good though.

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.

Re: Draw an iceberg and see how it would float in water

#97
post #71
post #9

I get interesting results if I draw a figure 8 (or a figure ∞). I wonder if it's treating one of the lobes as having negative density.

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. https://imgur.com/a/WG6D0RJ

[deleted]

Re: Draw an iceberg and see how it would float in water

#98
post #95

Earlier quoted context omitted.

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 st…

> 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 wa…

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

Post reply on HN