I'm trying to solve for the distance from Obj1 to Obj2 relative to Obj1, because I do not know their global positions, rotations, or the difference between their local spaces.

Thankfully, they are locked to each-other, so their relationship relative to Obj1 is constant across time.

I believe that the following is true, assuming A and B represent discrete samples at different times where the objects moved between A and B:
Obj1.positionB + Obj1.rotationB * relationship = Obj1.positionA + Obj1.rotationA * relationship + (Obj2.positionB - Obj2.positionA)

Given that, we can solve for relationship, right? First, move all instances of relationship to the left side...
Obj1.rotationB * relationship - Obj1.rotationA * relationship = Obj1.positionA + (Obj2.positionB - Obj2.positionA) - Obj1.positionB

From here, the AB+AC = A(B+C) rule tells me to do this: (Obj1.rotationB - Obj1.rotationA) * relationship = Obj1.positionA + (Obj2.positionB - Obj2.positionA) - Obj1.positionB

But I know that QuaternionAVector+QuaternionBVector does NOT equal (QuaternionA*QuaternionB)*Vector.

So, given QuaternionA*VectorA+QuaternionB*Vector = VectorB, is it possible to solve for VectorA? How? I'm using Unity, if that's any help.

(Note that the above assumes that the two coordinate spaces are oriented consistently even though they don't share the same origin. Solving for difference in parent space orientation, if ever necessary, is a different problem.)


1 Answer 1


There are some issues you might want to clear up in your question, perhaps with some drawings. In any case, here are some things to note:

  • If you just need to find the distance from Obj1 to Obj2, why don't you just calculate it as the difference between their positions?

  • What is relationship? If it is a matrix transform, you may be able to decompose it to find the translation vector. Or even better, apply it to (0, 0, 0).

  • If you are 100% sure your math is right, how about you convert your quaternions to rotation matrices? Matrices are much easier to operate with.

  • \$\begingroup\$ "I do not know their global positions, rotations, or the difference between their local spaces" <- This is why I can't just calculate the difference between their positions. This data is being passed in through an API, so there's no transform.position available. Relationship is a vector. I'll take a look into converting the quaternions to rotation matricies. It does look as if they support distributive property: hotmath.com/hotmath_help/topics/… \$\endgroup\$
    – M-Pixel
    Sep 29, 2015 at 5:44
  • \$\begingroup\$ I was able to confirm that ((Matrix4x4(rot1)-Matrix4x4(rot2))*Matrix4x4(vec1)).GetPosition does yield the same result as rot1*vec1-rot2*vec1, but I've hit another wall. To isolate vec1, we must divide both sides of the equation by (rot1-rot2). From what I understand, this is the same as multiplying both sides by the inverse of that matrix. Unfortunately, because (rot1-rot2) as a matrix equation results in an end row and end column of 0s, the inverse is always all 0s. I think perhaps that I'm either subtracting them incorrectly, or isolating vec1 incorrectly. \$\endgroup\$
    – M-Pixel
    Sep 29, 2015 at 17:28
  • 1
    \$\begingroup\$ +1 panda. In unity the '' operator for quaternion * vector isn't really a multiplication. Associativity won't apply for * and + here. If you convert to matrices than +/ associativity follows the usual rules. \$\endgroup\$ Oct 29, 2015 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .