Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] provide a method to project Vec4 and Vec3 from homogeneous space #366

Open
seichter opened this issue Dec 11, 2022 · 3 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@seichter
Copy link

What problem does this solve or what need does it fill?

Currently Vec3 provides extend(w) to unproject into homogeneous coordinates (hence Vec4 with euclidean hyperspace w - maybe I missed it, but there is no inverse to extend() or the documentation misses to mention it.

What solution would you like?

I would prefer to write something like this

transform.translation = view.w_axis.project()

rather than

transform.translation = view.w_axis.xyz() / view.w_axis.w;

My example is now for Vec4 ... same applies to homogeneous representations of Vec2 in vectorspace R3 using Vec3

What alternative(s) have you considered?

Keep writing rather obvious code

This was originally a request in bevy bevyengine/bevy#6916

@bitshifter
Copy link
Owner

Naming wise it would be good to make sure there is a clear distinction between this and the existing vector project_onto method.

@seichter
Copy link
Author

Agreed, here my 2ct

Eigen is using homogeneous() and hnormalized() which is rather meh and it doesn't allow for w=0

Armadillo has a reshape() and resize() but seems quite dated anyway. Numpy has pythonic syntax-sugar to deal with this. GLM only does projection/unprojection through constructors.

So, I guess there is no common agreement. Maybe shrink() or contract() would work.

@bitshifter
Copy link
Owner

Still mulling over what to call this. The operation is simple, naming is hard. It seems like this operation is "perspective divide" or "homogeneous divide" or "homogeneous normalization" are common names for this operation. Thus the "hnormalize" in Eigen. Vek calls it "homogenize(d)".

I'm thinking of adding Vec3::from_homogeneous(Vec4) -> Vec3 which performs the divide by w. It would be up to the user to make sure the input was valid (w != 0). Also Vec3::to_homogeneous(self) -> Vec4 which is like Vec3::extend(1.,0). This is what cgmath currently does https://docs.rs/cgmath/latest/cgmath/struct.Point3.html#method.from_homogeneous.

Might also add a Vec4::homogenize() -> Vec4 which returns a Vec4 divided by w.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants