wolftype / versor

Versor Geometric Algebra Library
wolftype.github.io/versor/devel/html/
291 stars 47 forks source link

Add bivector decomposition #21

Open porky11 opened 7 years ago

porky11 commented 7 years ago

It should be possible to decompose a general bivector into D/2 (rounded downwards) components, where D is the number of dimensions. Would be nice if a function for doing this would be added to this library, or at least an example. I don't find, how this can be done, anywhere. The reason for this is, that I want to experiment with at least 4 dimensional rotations, also torques.

wolftype commented 7 years ago

i have an implementation for conformal GA: https://github.com/wolftype/versor/blob/devel/src/space/vsr_cga3D_op.cpp#L312

a generalization of this would be most welcome. post ideas here!

porky11 commented 7 years ago

I'll look at it, and when I find a way to generalize it, I'll tell you or try to implement it.

porky11 commented 7 years ago

It seems to be pretty simple to generate a rotor from a bivector in even 4d, like this: http://www.liquisearch.com/bivector/four_dimensions/rotations_in_%E2%84%9D4 I just need the e function. Is this implemented? I cannot find it.

porky11 commented 7 years ago

I tired to implement the exponential function myself, but I don't understand how the e function in geometric algebra works.

exp(biv) = sin(norm(biv)) + cos(norm(biv))*biv but following seems not to be true: exp(biv0+biv1) = exp(biv0)*exp(biv1) = exp(biv1)*exp(biv0) I wonder why

wolftype commented 7 years ago

As I understand it, the above is true iff biv0 and biv1 commute (biv0biv1 = biv1biv0). I believe the Gen::bst function in vsr_generic_op.h could be repurposed into a generic exp function.

wolftype commented 7 years ago

the above Gen::bst is defined on line 459 and takes a Pair, though it should work for any 2-blade. If you have a general bivector, and are unsure whether it is a 2-blade, you would decompose it into two commuting 2-blades, and exponentialize each separately, then multiply the results to get a more general rotor.

     /*!
          Generate Boost as exponential of a Point Pair
          Implemented from "Square Root and Logarithm of Rotors. . ." by Dorst and Valkenburg, 2011
          e^-B/2 = cosh(B/2) - sinh(B/2)
          @param Point Pair generator
      */
      template<class A>
      static auto bst(const GAPar<A>& tp) -> decltype( tp + 1 ) {

          VSR_PRECISION norm; VSR_PRECISION sn; VSR_PRECISION cn;

          VSR_PRECISION td = tp.wt();

          if (td < 0) { norm =  sqrt( - td );  sn = sin(norm) / norm; cn = cos(norm);  } //note, changed to sin from -sin
          else if (td > 0) { norm = sqrt(td);  sn = sinh(norm) / norm; cn = cosh(norm); }
          else if (td == 0) { norm = 0; sn = 1; cn = 1; }

          return (tp * sn) + cn;
    }