jeremyong/klein

Log of a motor representing a translator

Closed this issue · 4 comments

Testing an example of blending with Motors of PGA and I got nan as a result. Here is a sample code:

	float W[] = {0.2f,0.1f,0.3f};

	kln::motor M0(kln::translator(10.0f,1.0f,0.0f,0.0f)); 
	kln::motor M1(kln::rotor(3.1416, 1.0f, 0.0, 0.0f));
	kln::motor M2(kln::rotor(1.0472, 0.0f, 1.0f, 0.0f));

        // removing W[0]*kln::log(M0) is OK
	kln::line blendedLine = W[0]*kln::log(M0) + W[1]*kln::log(M1) + W[2]*kln::log(M2) ;

	kln::motor blended_Motor = kln::exp(blendedLine); 
        std::cout << blended_Motor(kln::point(0.0f,0.0f,0.0f)).x()<<std::endl;

It might come from the fact that the log of translator results in an ideal line whereas the log of a motor is a real line in general.

Thanks for reporting this!

One thing about the kln::translator is that there is an implicit 1 in its expression that needs to be handled properly when casted to the kln::motor as you've done in the second line. Can you show the entries of M0 here by any chance?

Are you using MSVC by any chance?

From the following line:

https://github.com/jeremyong/klein/blob/master/public/klein/motor.hpp#L117

I see that it's using _mm_set_ss which does not zero upper lanes per a bug in the Visual Studio compiler. This bug has been reported and fixed but not released yet. We can patch this to be _mm_set_ps(0.f, 0.f, 0.f, 1.f) in the meantime and I believe that may help. Whether or not this is your issue, I may do this fix anyways.

Thank you for your very fast answer!

The entries of M0 obtained with the following code

std::cout << M0.scalar() << ", "<< M0.e12() << ", "<< M0.e31() << ", " << M0.e23() << ", "<<M0.e0123() << ", "<<M0.e01() <<", "<< M0.e02() << ", "<<M0.e03() << std::endl; 

are

1, 0, 0, 0, -0, -5, -0, -0

I am using clang 12.0 on macOS. I am going to try also on Linux with gcc and let you know.

I believe this is fixed in 77439b6 now