Hacker News new | ask | show | jobs
by stephantul 156 days ago
Amazing post, I didn’t think this through a lot, but since you are normalizing the vectors and calculating the euclidean distance, you will get the same results using a simple matmul, because euclidean distance over normalized vectors is a linear transform of the cosine distance.

Since you are just interested in the ranking, not the actual distance, you could also consider skipping the sqrt. This gives the same ranking, but will be a little faster.

3 comments

It's stuff like this I would have loved to know when I was doing game engine dev in the 90s.
I want to do game programming again like it's 1999. No more `npm i` or "accept all cookies" :/ rant off :)
Go make a game for the Sega Genesis https://mdengine.dev/

Or, the GameBoy Advance https://github.com/GValiente/butano

I was seriously looking into the GameBoy Advance, but the real hardware has gotten quite expensive these days.

I wonder how the latest and greatest Wonderswan is doing in terms of price.

One uses emulator while developing anyways. Try with C64 and VICE and join us at https://csdb.dk/
> One uses emulator while developing anyways.

Yes, but part of the joy is the anticipation of playing on a real device at the end.

> Try with C64 and VICE and join us at https://csdb.dk/

Thanks for the invitation! I used a C64 as my only computer in the late 1990s long past its prime, because my mother got a really good deal on a whole set with printer and disk drives and plenty of disks with software (mostly games, from magazines). However, I was still a bit annoyed by the limitations of the system. I guess, if I had had a forth disk, I might have felt different.

In any case, for personal reasons I don't want to explore the C64 more.

But I never had a GameBoy Advance nor a Wonderswan.

Or an alternative for the Sega Genesis https://github.com/Stephane-D/SGDK

Or the Super Nintendo Entertainment System https://github.com/alekmaul/pvsneslib

Or the Gameboy / GBC, Sega Master System, Gamegear, Nintendo Entertainment System https://github.com/gbdk-2020/gbdk-2020

Or the TurboGrafx-16 / PC Engine, Nintendo Entertainment System (alt), Commodore 64, Vic-20, Atari 2600, Atari 7800, Apple II/IIe, or Pet 2001 https://github.com/cc65/cc65

Or the ZX Spectrum, TRS-80, Apple II (alt), Gameboy (alt), Sega Master System (alt), and Game Gear (alt) https://github.com/z88dk/z88dk

Or the Fairchild Channel F https://channelf.se/veswiki/index.php?title=Main_Page

Note: Some are slightly pre-1999 (all these, I have at least successfully made a "Hello World" with)

----------------

If they're really wanting 1999, that's the 5th to 6th generation console range with Sega Saturn, PlayStation, Nintendo 64, and Dreamcast. (on these, only recommendations, no successful compiled software)

Playstation is really challenging and remains so even in 2026. Lots of Modchip and disk swap issues on real hardware. Possibilities: https://www.psx.dev/getting-started and https://github.com/Lameguy64/PSn00bSDK

N64 is less horrible, and there's quite a few resources: https://github.com/DragonMinded/libdragon and https://github.com/command-tab/awesome-n64-development

Sega Saturn is still pretty difficult. However, there is: https://github.com/yaul-org/libyaul?tab=readme-ov-file and https://github.com/ReyeMe/SaturnRingLib plus the old development kits from the 90's are still around https://techdocs.exodusemulator.com/Console/SegaSaturn/Softw...

Dreamcast is similar to the Saturn situation, yet strangely, a little better. There's https://github.com/dreamsdk/dreamsdk/releases and https://github.com/KallistiOS/KallistiOS along with the official SDKs that are still around https://www.sega-dreamcast-info-games-preservation.com/en/re...

I mean we used dist^2 all the time for comparisons in our game engine back in the 90s (multiple different engines actually).

So it was a known thing...

>you will get the same results using a simple matmul, because euclidean distance over normalized vectors is a linear transform of the cosine distance.

Squared euclidean distance of normalized vectors is an affine transform of their cosine similarity (the cosine of the angle between them).

  EuclideanDistance(x, y) = sqrt(dot(x - y, x - y)) = sqrt(dot(x, x) - 2dot(x, y) + dot(y, y)) = sqrt(2 - 2dot(x, y))
yes, you are right. I realized my mistake afterwards but it was after the edit window.
> you could also consider skipping the sqrt.

This is a trick I reach for all the time: it’s cheaper to compare squared distances than completing the Euclidean calculation. For example, to determine whether to stop calculating lerp: x*x+y*y <= epsilon.