gpc_test.c
Go to the documentation of this file.
1 // GPC: A library for the solution of General Point Correspondence problems.
2 // Copyright (C) 2006 Andrea Censi (andrea at censi dot org)
3 
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 
18 #include <stdio.h>
19 #include <math.h>
20 #include "gpc.h"
21 
22 #define deg2rad(x) (x*M_PI/180)
23 
24 int main() {
25  // This is the true roto-translation
26  double theta = deg2rad(4);
27  double t[2] = {0.3,-0.2};
28  printf("x_true = %f %f %f deg\n", t[0], t[1], theta*180/M_PI);
29 
30  double p[5][2] = {{1,0},{0,1},{-1,0},{2,1},{4,2}};
31  double alpha[5] = {deg2rad(0),
32  deg2rad(10), deg2rad(20), deg2rad(50),deg2rad(-20)};
33 
34  struct gpc_corr c[5];
35  int k;
36  for(k=0;k<5;k++) {
37  c[k].p[0] = p[k][0];
38  c[k].p[1] = p[k][1];
39  c[k].q[0] = t[0] + p[k][0]*cos(theta) - p[k][1]*sin(theta);
40  c[k].q[1] = t[1] + p[k][0]*sin(theta) + p[k][1]*cos(theta);
41  c[k].C[0][0] = cos(alpha[k])*cos(alpha[k]);
42  c[k].C[0][1] = c[k].C[1][0] = cos(alpha[k])*sin(alpha[k]);
43  c[k].C[1][1] = sin(alpha[k])*sin(alpha[k]);
44  }
45 
46  double x[3];
47  gpc_solve(5,c,x);
48 
49  printf("estimated x = %f %f %f deg\n", x[0], x[1],x[2]*180/M_PI);
50  return 0;
51 }
52 
#define deg2rad(x)
Definition: gpc_test.c:22
double C[2][2]
Definition: gpc.h:27
double p[2]
Definition: gpc.h:24
Definition: gpc.h:23
#define M_PI
Definition: math_utils.h:7
struct @0 p
double q[2]
Definition: gpc.h:25
int main()
Definition: gpc_test.c:24
int gpc_solve(int K, const struct gpc_corr *c, const double *x0, const double *cov_x0, double *x_out)
Definition: gpc.c:29


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23