1

I am developing one application using http://structure.io/. In that application when scanning object will complete 360 degree rotation then it will complete scanning..

From scanner we are getting starting point and ending point as GLKMatrix4. We want to check if angle between starting and ending point. We are using below code but it's not the right ways to do it . Can anyone know how to do it..I am very new to opengles?

case ScannerStateScanning:
        {
            // First try to estimate the 3D pose of the new frame.
            NSError* trackingError = nil;
            NSString *currentPoseStringMatrix = NSStringFromGLKMatrix4([self lastFrameCameraPose]);
            NSString *initialPoseStringMatrix = NSStringFromGLKMatrix4([self initialCameraPose]);
            if ([currentPoseStringMatrix isEqualToString:initialPoseStringMatrix]) {
                // stop scanning

            }
Susim Samanta
  • 1,605
  • 1
  • 14
  • 30

1 Answers1

3

Following this answer you need to get the 3rd row out of your 2 matrices to find out the direction they are facing in vector form. use GLKMatrix4GetRow to get the 3rd row, then convert it to a Vector3 by ignoring the last element of the vec4 (refer to diagram). then you can try out this method for finding the angle between two vectors, otherwise just google around for some sample code if you dont feel like coding that math yourself.

Community
  • 1
  • 1
Fonix
  • 11,447
  • 3
  • 45
  • 74
  • so @Fonix from 3rd Matrix I will get vector A (x1,y1,z1) and B(x2,y2,z2) . Then from Cos(angle) = A.B/AB and A = |A| = √(x12 + y12 +z12). Am I going to right direction? – Susim Samanta Apr 14 '16 at 05:10
  • yep, if you convert A and B to unit vectors first then you can use `let angle:Double = acos(A·B)` (replacing A·B with the appropriate dot product function) – Fonix Apr 14 '16 at 05:19
  • class func angleBetween2Vector(a :GLKVector4, b :GLKVector4)-> Double { let dotProduct = GLKVector4DotProduct(a,b) let angle:Double = acos(Double(dotProduct)) return angle*(180.0 / M_PI) } – Susim Samanta May 08 '16 at 10:12
  • I created above method Cos(angle) = A.B/AB . but we are not dividing AB. How would we get magnitude of A? – Susim Samanta May 08 '16 at 10:13
  • im not sure if i follow... dont you already know the magnitude of A (as per your first comment)? if you are not dividing by AB, then AB need to be unit vectors firs (can use [this method](http://www.algebralab.org/lessons/lesson.aspx?file=Trigonometry_TrigVectorUnits.xml) to do it) – Fonix May 09 '16 at 02:55