Log in or register to post comments

Direction to the Marker

June 13, 2011 - 10:26pm #1

Hi!

I want to calculate the direction to an marker(in time, e.g. marker on 11 o'clock). I have already the cameraPosition and the LookAtVector from the Camera to the marker :

QCAR::Matrix44F inverseModelView = SampleMath::Matrix44FTranspose(SampleMath::Matrix44FInverse(modelViewMatrix));
           //    CameraPosition/LookAtVector
           QCAR::Vec3F direction(inverseModelView.data[8], inverseModelView.data[9], inverseModelView.data[10]);
           QCAR::Vec3F positioncam(inverseModelView.data[12], inverseModelView.data[13], inverseModelView.data[14]);
           //LOG("camLookAt: %f, %f, %f", direction.data[0], direction.data[1], direction.data[2]);
           LOG("camPosition: %f, %f, %f", positioncam.data[0], positioncam.data[1], positioncam.data[2]);

Anybody an idea how to calculate an angle to get the MarkerPosition (in time) or has an other idea to get this information in time very easy?

Stephan

Direction to the Marker

September 16, 2016 - 1:52am #9

Hi kim ,

How can get angle of camera respect to Marker reference frame, in all X,Y,Z direction?

Direction to the Marker

July 14, 2013 - 4:18pm #8

Thanks for the video, very helpful.
I'm using sdk version 2.5.

Direction to the Marker

July 14, 2013 - 2:52pm #7

Here's an article explaining how 3D rotation matrices are defined - http://en.wikipedia.org/wiki/Rotation_matrix

and this video might be helpful - https://www.khanacademy.org/math/linear-algebra/matrix_transformations/lin_trans_examples/v/rotation-in-r3-around-the-x-axis

 

Which SDK version are you using?

Direction to the Marker

July 14, 2013 - 2:10pm #6

I read the doc but I still have some trouble finding the value of this angle. And couldn't find any additional resources than this article. 

Would really appreciate some additional resources or some code. Thanks :)

Direction to the Marker

July 14, 2013 - 12:56pm #5

Hi, obtaining the angle around an axis is something that can be done by processing the pose matrix with some trigonometric (math) functions;

but you need to have a clear understanding of how the pose matrix is defined, for which I recommend reading this article:

https://developer.vuforia.com/forum/faq/technical-how-pose-matrix-defined

 

Direction to the Marker

July 14, 2013 - 7:40am #4

Hi,

How can I get the angle around the X axis of the image target only ?

Thanks for your help,
Lukas

Re: Direction to the Marker

June 15, 2011 - 8:51am #3

Hi Kim!

The code works fine!

Thanks a lot, Stephan

Re: Direction to the Marker

June 14, 2011 - 2:23pm #2

Here is one approach. I may be able to think of something simpler later :)

// take the inverse of the modelview matrix to find the camera orientation in relation to a target at the origin
QCAR::Matrix44F inverseModelView = SampleMath::Matrix44FTranspose(SampleMath::Matrix44FInverse(modelViewMatrix));

// pull the camera position and look at vectors from this matrix
QCAR::Vec3F cameraPosition(inverseModelView.data[12], inverseModelView.data[13], inverseModelView.data[14]);
QCAR::Vec3F cameraLookAt(inverseModelView.data[8], inverseModelView.data[9], inverseModelView.data[10]);

// project both vectors to the X/Y plane
// reverse the camera position to get a vector pointing to the target
QCAR::Vec3F projectedDirectionToTarget(-cameraPosition.data[0], -cameraPosition.data[1], 0);
QCAR::Vec3F projectedCameraLookAt(cameraLookAt.data[0], cameraLookAt.data[1], 0);

// normalize the projected vectors
projectedDirectionToTarget = SampleMath::Vec3FNormalize(projectedDirectionToTarget);
projectedCameraLookAt = SampleMath::Vec3FNormalize(projectedCameraLookAt);

// find the dot and cross products of the normalized vectors
float dot = SampleMath::Vec3FDot(projectedDirectionToTarget, projectedCameraLookAt);
QCAR::Vec3F cross = SampleMath::Vec3FCross(projectedDirectionToTarget, projectedCameraLookAt);

// the angle between two vectors is the acos of the dot product
float angle = acos(dot);

// acos returns an angle in radians, convert to degrees
angle *= 180.0f / M_PI;

// our angle is now between 0 and 180, use the cross product to make it between 0 and 360
if (cross.data[2] < 0)
    angle = 360.0f - angle;

LOG("angle: %f", angle);

Note that this gets you an angle between 0 and 360, with 0 being 12 o'clock in your terms. This is just to give you a starting point on the sort of math involved, you'll have to adapt it to your needs!

- Kim

Log in or register to post comments