question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: methods for fractional add of vector and fractional application of quaternion

See original GitHub issue

Related to (but not the same as) slerp, I need a method for scaling just the angle of a quaternion by a given factor, allowing for a single (non-slerp) quaternion to be applied to a given fractional amount. The code I have to do this is:

private static Quaterniond scaleQuatRotation(Quaterniond quat, double frac) {
    AxisAngle4d axisAngle = new AxisAngle4d(quat);
    double angle = axisAngle.angle;
    if (angle > Math.PI) {
        angle -= 2.0 * Math.PI;
    }
    return new Quaterniond(new AxisAngle4d(angle * frac, axisAngle.x, axisAngle.y, axisAngle.z));
}

However it would be more efficient to compute this internally to JOML, supplying a “fractional multiplication” method that scales the angle of a second quaternion when multiplying by a first quaternion, e.g.

prevRotation.mul(newRotation, frac, new Quaterniond())

Similarly I need a method that adds a fractionally scaled vector:

private static Vector3d addScaledVector(Vector3d vec1,Vector3d vec2, double frac) {
    return vec1.add(vec2.mul(frac, new Vector3d()), new Vector3d());
}

but it would be more efficient to compute this internally to JOML using an API like

prevVec.add(newVec, frac, new Vector3d())

These methods are important for a range of interpolation tasks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
httpdigestcommented, Nov 13, 2019

I am not sure that approximating sqrt is worth it. Assuming that the JIT lowers a (float) sqrt() to an x86 SQRTSS instruction, then this (on Skylake) has the same operation latency as DIVSS (which would be needed for the approximation itself). In addition, we also need the comparison (which branch prediction can probably predict well when normalizing often).

Latency tables: https://www.agner.org/optimize/instruction_tables.pdf

1reaction
lukehutchcommented, Nov 13, 2019

Thanks for the pointer. I see that sqrt is not yet approximated, and there is no entry in the Math class for inverse sqrt. The inverse sqrt trick I linked above is very useful for quaternions when you normalize after every operation, since it is highly optimal when the magnitude of the result is already close to 1.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A quaternionic fractional Borel-Pompeiu type formula - arXiv
An introduction to fractional derivatives, fractional differential equations, to methods of their solution and some of their applications.
Read more >
Understanding Quaternions | 3D Game Engine Programming
Quaternions are used to represent an orientation in 3D space. This article attempts to demystify the complexities of quaternions.
Read more >
Quaternion algebras - Dartmouth College Mathematics
The book of Maclachlan–Reid [MR2003] gives an introduction to quaternion algebras with application to the geometry of 3-manifolds.
Read more >
An Introduction to Hyperholomorphic Spectral Theories and ...
In the last section of this paper we explain how to treat fractional diffusion problems using the quaternionic spectral theory on the S-spectrum ......
Read more >
(PDF) Fractional powers of higher order vector operators on ...
Using the $H^\infty$-functional calculus for quaternionic operators, we show how to generate the fractional powers of some densely defined ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found