JOML-CI / JOML

A Java math library for OpenGL rendering calculations
MIT License
728 stars 104 forks source link

JOML needs (x^T A x) method #251

Closed lukehutch closed 3 years ago

lukehutch commented 4 years ago

I can't find a method for calculating (x^T A x) given vector x and matrix A (e.g. for computing a quadratic form).

I think the code for this should be the following -- is this correct?

x.dot(x.mul(A, new Vector3d()))

however this could be computed more efficiently in a single method call.

Related issue: I think I mentioned this once before, but x.mul(A) looks backwards -- I would have preferred this to be called x.premul(A) or something. Even better, it would be great if there were a method A.mul(x) to preserve the order.

lukehutch commented 4 years ago

This would be the code...

            double Axx = A.m00 * x.x + A.m10 * x.y + A.m20 * x.z;
            double Axy = A.m01 * x.x + A.m11 * x.y + A.m21 * x.z;
            double Axz = A.m02 * x.x + A.m12 * x.y + A.m22 * x.z;
            double xTAx = x.x * Axx + x.y * Axy + x.z * Axz; 
lukehutch commented 4 years ago

I have been trying to figure out what x^T A x is actually called -- maybe the "quadratic form product", since it is used in quadratic forms?

pollend commented 4 years ago

It doesn't hurt to create a PR, It would make reviewing the code easier. this doesn't seem too bad.

lukehutch commented 4 years ago

@pollend I just spent an hour trying to build JOML in Eclipse, unsuccessfully. After inserting <?m2e execute?> directives after the <execution> tags of all plugins that do not support lifecycle management in m2e, I get numerous errors about unsupported classes, because the build was defaulting to JDK 1.6 or similar. I manually upgraded the <maven.compiler.source> and <maven.compiler.target> versions to 14 (so that, for example, Math.fma was available). However, classes that use new modularized packages, e.g. java.io.Externalizable, break with the error, The package java.io is accessible from more than one module: <unnamed>, java.base. This seems to indicate that JOML is being built in an unnamed module, so the module descriptor is not being found.

Any tips on building this in Eclipse, please?

pollend commented 4 years ago

hmm, I've found the maven setup to be kind of fiddly. I am using intellij and it seems to work find just importing the project as is. It doesn't quite like intellij either. I don't think I did anything particularly drastic though. can you build it using ./mvnw at least just to verify.

httpdigest commented 4 years ago
  1. File > Import... > "Maven -> Existing Maven Projects" > Choose JOML > "Finish"
  2. Mark all unsupported Maven lifecycles via the popup in the pom.xml "Disable lifecycle in Eclipse settings"
  3. Make sure you have a JDK 9+ jdk as the project JDK.

And that's it. JOML is NOT a Jigsaw Module-enabled project!

pollend commented 4 years ago

@lukehutch @httpdigest what the status on this and is it still relevant to add to JOML?

lukehutch commented 4 years ago

Yes, it's very relevant, this computation is the basis for quadratic forms. However I am extremely busy on my own project right now, and haven't had time to work on this.

httpdigest commented 3 years ago

Hey @lukehutch I've added the method quadraticFormProduct with your implementation to the Matrix3 classes.

lukehutch commented 3 years ago

Thank you!