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

glm::cross should support 2d vector. #621

Closed
zhou13 opened this issue Apr 7, 2017 · 6 comments
Closed

glm::cross should support 2d vector. #621

zhou13 opened this issue Apr 7, 2017 · 6 comments
Assignees
Milestone

Comments

@zhou13
Copy link

zhou13 commented Apr 7, 2017

So I don't need write my own:

double cross(dvec2 const& a, dvec2 const& b)
{
    return a.x * b.y - b.x * a.y;
}
@bcrist
Copy link

bcrist commented Apr 8, 2017

What does that function have to do with the cross product? That looks suspiciously like glm::determinant to me.

@zhou13
Copy link
Author

zhou13 commented Apr 8, 2017

This is often used in computational geometry. You can understand it as the the length of vector a x b if we treat a and b as a 3d vector in z=0 plane..

@bcrist
Copy link

bcrist commented Apr 8, 2017

Sure, length(cross(dvec3(a,0), dvec3(b,0))) and determinant(dmat2(a,b)) are equivalent, and both represent the area of a 2D parallelogram with sides a and b, which is a useful thing. But that doesn't mean it should be called the cross product.

@zhou13
Copy link
Author

zhou13 commented Apr 8, 2017

Well, naming is just a convention. For example, numpy supports such 2d operator in cross product: https://docs.scipy.org/doc/numpy/reference/generated/numpy.cross.html, which may be not a precise name. I could write return glm::determinant(glm::dmat2(a, b)), but that is a little bit awkward.

@Groovounet Groovounet self-assigned this Apr 8, 2017
@Groovounet Groovounet added this to the GLM 0.9.9 milestone Apr 8, 2017
@bcrist
Copy link

bcrist commented Apr 8, 2017

I think this is a good addition to GLM, but I still think it shouldn't be called glm::cross, or at least should be put in an extension header so that people who don't want this overload don't get it. For one thing, GLSL, HLSL, and Cg all define the cross function specifically as a function that both returns and takes 3-component vectors as parameters. Mathematically speaking, the cross product, scalar triple product, and the function described here are all just types of exterior products. Perhaps a new GTX_exterior_product extension would be useful?

Groovounet added a commit that referenced this issue Apr 8, 2017
@Groovounet
Copy link
Member

I added a vec2 implementation of cross in within an GTX_exterior_product extension. :D

Thanks for suggesting and discussing the topic!
Christophe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants