fu5ha / ultraviolet

A wide linear algebra crate for games and graphics.
https://crates.io/crates/ultraviolet
750 stars 81 forks source link

Implement 3d projective geometric algebra #65

Open fu5ha opened 4 years ago

fu5ha commented 4 years ago

under pga3d module

ten3roberts commented 3 years ago

Hello @termhn

I am using your library for my custom game engine and must say that I love it. The rotors and brevity of the library are amazing, as well as the projection for vulkan.

However, I feel the projective functions like project and project_plane would be well needed. Currently they are living as external functions in a utils module.

If so, would you be interested in me creating it and opening a PR?

If I have understood your code correctly, projection would be implemented by means of a Project trait and a macro. If so, the same trait could be used for both 3d and 2d, under a common pga module.

ten3roberts commented 2 years ago

Would you be interested in a pull request?

fu5ha commented 2 years ago

To be a bit more clear (this issue was originally just written for my own use :P)... See https://www.jeremyong.com/klein/ (and a rust impl in https://github.com/wrnrlr/g3) for what I mean by projective geometric algebra :)

boomshroom commented 1 year ago

You already have Vec4 as a homogenous point, and Isometry as a combination of a Rotor and a translation. Currently Isometries don't support screw motion since they lack an equivalent for e₀₁₂₃, but that shouldn't be too hard to remedy (and would also round out its size from 7 floats to an even 8).

You comment on not bothering to distinguish between a point and a vector for Vec4. With 3D PGA, a Vec4 (technically a trivector) with a 0 w-component is a vector, and a non-zero w-component is a point. Technically they're actually both points, but have a 0 w-component would place the point on the horizon. If you wanted full PGA, you would probably want a separate Plane type.

The biggest hurdle with implementing PGA would probably actually be your previous usage of GA. As I mentioned earlier, points are trivectors (grade 3), and planes also have 4 components, since they're grade 1. Bivectors then are lines, more specifically axes of rotation. Ya. The whole "plane of rotation," while appearing easier to extend to higher dimensions, falls apart the moment you step away from the origin. There are an infinite number of possible rotations for a given plane, and infinitely many parallel planes that would be the same rotation, so PGA brings back axes of rotation. The main thing it changes from traditional axes is that they're not in general lines. Instead they're n-2 surfaces, which just happen to be lines in 3D. In 2D, the axes of rotation are points.