Author Topic: Get Vector's Axis Angle [Solved]  (Read 582 times)

what is the most efficient way for me to get the axis angle of a vector?
« Last Edit: July 15, 2015, 04:01:20 PM by Swollow »

These are from Boodals, are any of these functions good for your needs?

function eulerToVector(%ang)
{
   if(getWordCount(%ang) == 2) //Support for giving pitch and yaw, but not roll.
      %ang = getWord(%ang, 0) SPC "0" SPC getWord(%ang, 1);

   %yaw = mDegToRad(getWord(%ang, 2));
   %pitch = mDegToRad(getWord(%ang, 0));
   %x = mSin(%yaw) * mCos(%pitch) * -1;
   %y = mCos(%yaw) * mCos(%pitch);
   %z = mSin(%pitch);
   return %x SPC %y SPC %z;
}

function axisToVector(%ang)
{
   return eulerToVector(axisToEuler(%ang));
}

function vectorToEuler(%vec)
{
   %vec = vectorNormalize(%vec);
   %yaw   = mRadToDeg(mATan(getWord(%vec, 0) * -1, getWord(%vec, 1)));
   %pitch = mFloatLength(mRadToDeg(mATan(getWord(%vec, 2), vectorLen(getWords(%vec, 0, 1)))), 3);
   return %pitch SPC "0" SPC %yaw;
}

function vectorToAxis(%vec)
{
   return eulerToAxis(vectorToEuler(%vec));
}

function vectorRotateVector(%vec1, %vec2)
{
   return vectorRotateAxis(%vec1, vectorToAxis(%vec2));
}

function vectorRotateEuler(%vec, %euler)
{
   return vectorRotateAxis(%vec, eulerToAxis(%euler));
}

function vectorRotateAxis(%vec, %axis)
{
   %u["x"] = getword(%axis,0);
   %u["y"] = getword(%axis,1);
   %u["z"] = getword(%axis,2);

   %angl = getword(%axis,3) * -1;
   %cos = mcos(%angl);
   %sin = msin(%angl);

   %a[1,1] = %cos + (%u["x"] * %u["x"] * (1 - %cos));
   %a[1,2] = (%u["x"] * %u["y"] * (1 - %cos)) - (%u["z"] * %sin);
   %a[1,3] = (%u["x"] * %u["z"] * (1 - %cos)) + (%u["y"] * %sin);

   %a[2,1] = (%u["y"] * %u["x"] * (1 - %cos)) + (%u["z"] * %sin);
   %a[2,2] = %cos + (%u["y"] * %u["y"] * (1 - %cos));
   %a[2,3] = (%u["y"] * %u["z"] * (1 - %cos)) - (%u["x"] * %sin);

   %a[3,1] = (%u["z"] * %u["x"] * (1 - %cos)) - (%u["y"] * %sin);
   %a[3,2] = (%u["z"] * %u["y"] * (1 - %cos)) + (%u["x"] * %sin);
   %a[3,3] = %cos + (%u["z"] * %u["z"] * (1 - %cos));

   %x = getWord(%vec, 0);
   %y = getWord(%vec, 1);
   %z = getWord(%vec, 2);

   %newx = (%a[1,1] * %x) + (%a[1,2] * %y) + (%a[1,3] * %z);
   %newy = (%a[2,1] * %x) + (%a[2,2] * %y) + (%a[2,3] * %z);
   %newz = (%a[3,1] * %x) + (%a[3,2] * %y) + (%a[3,3] * %z);

   %pos = %newx SPC %newy SPC %newz;
   return %pos;
}


Topic is here: http://forum.blockland.us/index.php?topic=259991.msg7598994#msg7598994

thank you for the resource it worked very well