Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Topology and complex analysis for the unsuspecting game dev (gamedevnotesblog.wordpress.com)
81 points by atomlib on Dec 28, 2019 | hide | past | favorite | 10 comments


That's an awfully complicated explanation for what seems a simple process.

The idea here is that you have a unit vector represented by three numbers, and you want to represent it as two numbers to save space. Since it's a unit vector, it obeys

   x^2 + y^2 + z^2 = 1
so if you have any two of x,y,z, you can get the third, except you need to store its sign somewhere. Their scheme for storing the sign loses some precision, since it maps the sphere into half the disk, costing one bit of precision. This isn't lossless. So you could do equally well with some other encoding to store that one sign bit.

I've seen this done for quaternions, where you have a 4-value unit vector. Same idea.


I mean, the point was probably to teach some complex analysis and topology along the way.

You could just x += 2*sgn(x) if z < 0, sacrificing the least significant bit of x in a way that doesn't require any bit hacks (so on restoration, z < 0 iff abs(x) >= 2, and the excess +/-2 is easy to remove from x since the real x <= 1).


If we are using floats, couldn't we just store the sign of z in the sign bit of the exponent of x with no loss of precision since it should always be negative for a number in [-1, 1].

Which is only possible because storing a number in [-1, 1] in a float is wasting a bit of space, but everyone does it.


>I've seen this done for quaternions, where you have a 4-value unit vector.

Which has an additional benefit, namely that the unit quaternions q and -q represent the same rotation, so there's no need to store the sign bit.


complex analysis means to me ... analysis. cauchy-riemann, laurent series, residue theorem, etc. i only skimmed but this looks like just complex numbers.

on the other hand here's a cool use of holomorphic maps (analytic in the plane or entire or differentiable at every point) to construct barycentric coordinates

https://onlinelibrary.wiley.com/doi/full/10.1111/j.1467-8659...


Having done a lot of real analysis as an undergrad, my one complex analysis course was fairly different. We spent most of the semester proving stuff that didn’t have any analogue in real analysis. But sure the basics are the same and a lot of tricks from real analysis still apply.


> I didn’t work out whether this bijection is a homeomorphism or not

It can't be a homeomorphism as one space is Hausdorff and the other very much isn't.


Complex analysis is why I quit maths at college and focused on software engineering :D


Complex analysis is why I stopped taking so many software engineering courses and turned to math.


I enjoyed my complex analysis course quite a bit, but I was lacking motivation a bit because the applications in CS were not as obvious to me, compared to real analysis. Maybe I lacked imagination however :D




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: