laffernandes / gatl

GATL: Geometric Algebra Template Library
GNU General Public License v3.0
56 stars 5 forks source link

Transformation between two multivectors #24

Closed CaseySanchez closed 2 years ago

CaseySanchez commented 2 years ago

In this link at section 2.5 the transformation from a to b is expressed as: a \rightarrow b = \sqrt { b * a^{-1} }. How can I compute the square root of a multivector in GATL?

Also, is it appropriate for me to be using the "Issues" section for asking questions like this?

laffernandes commented 2 years ago

The implementation of a general squared root function is not available in GATL. However, the computation of a \rightarrow b = \sqrt { b * a^{-1} } can be performed using log and exp. More specifically, exp(log(b / a) / 2).

Unfortunately, unlike the general exponential for blades, which is well defined and implemented by GATL, a general definition of the logarithm of versors is unknown. But the logarithm of some versors is known (see "Logarithm of a Rigid Body Motion" and "Logarithm of Versors" in Chapters 10, 13, and 21 of this book: https://www.elsevier.com/books/geometric-algebra-for-computer-science-revised-edition/dorst/978-0-12-374942-0#:~:text=Geometric%20algebra%20(GA)%20is%20a,graphics%2C%20vision%2C%20and%20robotics).

The implementation of those logarithms is on my to-do list. The first version of GATL has all of them. But in the second version (the faster one) I did not implement them yet. So you have to see the kind case of logarithm you have and implement your own function.

Maybe this page https://github.com/laffernandes/gatl/discussions is the most appropriate place for asking questions like this.

CaseySanchez commented 2 years ago

@laffernandes

Enki (maker of Ganja.js) said this in the Bivector Discord:

I usually just go for sqrt(x) = (1 + x).Normalized (actually @tBuLi and me just submitted a paper with optimized implementations of normalisation , sqrt, etc .. for PGA, CGA, etc .. we prove that if you properly deal with normalize this formula is universally valid)
laffernandes commented 2 years ago

This is interesting. I was not aware of this trick. Please tell me later if it worked.

CaseySanchez commented 2 years ago

Can confirm the following does work:

template <typename T, typename CliffordExpression>
auto sqrt(clifford_expression<T, CliffordExpression> const &multivector)
{
    return unit<T>(static_cast<T>(1.0) + multivector);
}

template <typename T, typename FromExpression, typename ToExpression>
auto inv_transform(clifford_expression<T, FromExpression> const &from, clifford_expression<T, ToExpression> const &to)
{
    return sqrt<T>(unit(to) * inv(unit(from)));
}