Live data from Hacker News

Draw an iceberg and see how it would float in water

joshdata.me

121–130 of 179 posts

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

#121

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

The site's algorithm generates negative masses when you cross the lines. There's a discussion about it in another thread.

This is a very obvious in retrospect flaw for anybody that has experience in graphic computing, but it's a common gotcha even there.

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

#122

What a cool idea. Drawing a star is fun. If you draw something in the basic shape of a Y, with two thick arms and one thin arm, my instinct tells me that the two thick arms should end up on the top, with the thin one pointing down into the water. Is that accurate? There's not much jostling in the demo; any of the arms might end up pointing down. EDIT: You can also pretty easily get something to float in either an M o…

Hum... The most stable position is with the thin arm down, but all three have meta-stability, so what position it ends up on is path-dependent (until you go there and poke it so it rotates really fast).

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

#123
post #95

Earlier quoted context omitted.

> 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

That's brilliant!

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

#124
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 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. [...]

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

#125
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 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 p…

You may want to revert the (tedious) patch about intersections. Here is a simple workaround:

> turf.unkinkPolygon=(x)=>x;

Press F12, click 'Console', copy-paste the above one and press Enter.

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

#126
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 don't think there is a stable "vertical" configuration without the negative mass trick from crossing lines: https://en.wikipedia.org/wiki/Metacentric_height

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"

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

#127
I had never considered that "ice cone shaped" icebergs wouldn't be stable. It's obvious in hindsight, if you gave me an ice cube shaped like that I'd never expect it to float upright.

Now every time I'll encounter one of those I'll feel mildly irritated. Sometimes ignorance is bliss.

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

#128

So without any further knowledge about how icebergs should orient and how scientists draw them: Icebergs in 3D will generally have different mass distributions than the corresponding 2D projections that we are drawing here. For example, there will generally be higher "2D mass density" in the center. Consequently, it is possible that the scientists "drawing icebergs wrong" are actually right and it just looks/"behaves…

I concur! In addition to that, icebergs also probably don't have a unified mass just based on the proportions. Some parts of the iceberg will be snow, others will be very tightly packed snow while others will be just ice, also with different densities.

So the iceberg could very likely float like that when taking into considering 3d space + the random distribution of mass that is different in different parts of the iceberg.

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

#129

Earlier quoted context omitted.

It’s interesting that proponents of a simpler web argue in favor of Jquery for a use case where jquery is in fact very easy to live without. One would almost think dogmatic thinking is involved.

> It’s interesting that proponents of a simpler web argue in favor of Jquery for a use case where jquery is in fact very easy to live without. One would almost think dogmatic thinking is involved. But to do without it, you will end up rewriting the shortcuts and utility functions that JQuery provides, effectively recreating a project-specific, less-tested and less-supported JQuery.

Are still talking about the jQuery usage in https://joshdata.me/iceberger.html or in general? If the former, then I agree that jQuery was unnecessary here, all API functions used by the author now has appropriate functions shipped natively in the browser runtimes, so using jQuery was actually more work than not (unless the author never used the vanilla API but have used the jQuery API).

Otherwise I agree with you in general.

Post reply on HN