Live data from Hacker News

Draw an iceberg and see how it would float in water

joshdata.me

81–90 of 179 posts

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

#82

Draw a horizontal line under the water, then return back to its start with a wavy line crossing over the first line repeatedly. Very strange things happen. The first time i tried, it leapt out of the water then flapped around..

To trigger the behavior, it seems the waves need to be "asymmetric" in that if the leftest one is up, the rightest one needs to be down. Otherwise, it seems to behave normally.

Yeah, I noticed that, so it turns around rapidly. Maybe the "righting arm" torque overflows when it's much bigger than it ever would be in reality.

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

#85
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.

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

#86
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

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!

https://ibb.co/VmXShfY

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

#87
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…

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

#89
The algorithm doesn't seem to be complete, it can't handle concave shapes with trapped water or trapped air. But that's probably too much to ask.

Edit: to illustrate the point, this iceberg had trapped air before it stabilized and removed all air, which is physically impossible: https://imgur.com/a/uiaW1qN

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

#90
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.

If you draw death, it often flies intimidatingly across the screen. https://imgur.com/a/bVh5iAt Start drawing at trapeze vertex left to the head.
Post reply on HN