source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/BlueCCal/MultiCamSelfCal/Ransac/rroots.c @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.5 KB
Line 
1#include <math.h>
2#define rr_a (*po)
3#define rr_d (*(po + 3))
4#define eps (2.2204e-016)
5
6#include "mex.h"
7#include "matrix.h"
8
9
10void mexFunction( int dstN, mxArray **aDstP, int aSrcN, const mxArray **aSrcP )
11{
12
13  double *po = mxGetPr(aSrcP[0]);
14
15  double b,c, b2, bt, v, pit, e, *r;
16  double p, q, D, A, cosphi, phit, R, _2R;
17
18  b = *(po + 1) / rr_a;
19  c = *(po + 2) / rr_a;
20  b2 = b*b;
21  bt = b/3;
22
23  p = (3*c - b2)/ 9;
24  q = ((2 * b2 * b)/27 - b*c/3 + rr_d/rr_a) / 2;
25
26  D = q*q + p*p*p;
27
28  if (D > 0)
29  {
30    aDstP[0] = mxCreateDoubleMatrix( 1, 1, mxREAL );
31    r = mxGetPr(aDstP[0]);
32
33    A = sqrt(D) - q;
34    if (A > 0)
35    {
36      v = pow(A,1.0/3);
37      *r = v - p/v - bt;
38    } else
39    {
40      v = pow(-A,1.0/3);
41      *r = p/v - v - bt;
42    }
43  } else
44  {
45 /*    if (p > -eps)
46      {
47         printf("%.17f\n", p);
48        aDstP[0] = mxCreateDoubleMatrix( 1, 1, mxREAL );
49        r = mxGetPr(aDstP[0]);
50        *r = pow(q,1.0/3) - bt;
51      }
52      else */
53      {
54
55       aDstP[0] = mxCreateDoubleMatrix( 3, 1, mxREAL );
56       r = mxGetPr(aDstP[0]);
57       if (q > 0) e = 1; else e = -1;
58       R = e * sqrt(-p);
59       _2R = R *2;
60       cosphi = q / (R*R*R);
61       if (cosphi > 1) cosphi = 1; else
62         if (cosphi < -1) cosphi = -1;
63       phit = acos(cosphi) /3;
64       pit = 3.14159265358979/3;
65 
66       r[0] = -_2R * cos(phit) -bt;
67       r[1] =  _2R * cos(pit - phit) -bt;
68       r[2] =  _2R * cos(pit + phit) -bt;
69      }
70  }
71}
Note: See TracBrowser for help on using the repository browser.