Converting from Manhattan Directions to Quaternion Rotations.

36 Views Asked by At

I have 3D vectors on the Unit Cube (from (-1,-1,-1) to (1,1,1), with all vectors v satisfying: cmax(abs(v)) == 1). I want to get the opposite vector from one to another. Example 1: A=(1,0, 0), B=(0,1, 0) ==> C=(-1,0,0) - the opposite of A along B Example 2: A=(1,1, 0), B=(1,0.5,0) ==> C=( 1,0,0) Example 3: A=(1,1,-1), B=(0,1 ,0) ==> C=(-1,1,1)

Problem: for example 3, if you naively try to rotate B by the quaternion angle from A to B, you will not get C (nor anywhere close, the difference is over 0.1). I think this is due to the Unit Cube vectors being in Manhattan space? I might be wrong.

Example problem:

    float3 RotateVectorQ(float3 object, float3 center) {
        quaternion between = Quaternion.FromToRotation(object, center);
        return math.rotate(between, center);
    }

        float3 object = (new float3(1,0,0));
        float3 center = (new float3(1,0.5f,0));
        float3 flip_object = RotateVectorQ(object, center);

```