affine2D.cc

 1 const char *help = "\
 2 progname: affine2D.cc\n\
 3 code2html: This program tests Affine2D class methods.\n\
 4 version: Torch3 vision2.0, 2003-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "general.h"
 8 #include "RotationMatrix2D.h"
 9 #include "Affine2D.h"
10 #include "CmdLine.h"
11 
12 using namespace Torch;
13 
14 int main(int argc, char **argv)
15 {
16  	real x, y;
17  	real xc, yc;
18 	real angle;
19 	bool verbose;
20 
21 	// Construct the command line
22   	CmdLine cmd;
23 	cmd.setBOption("write log", false);
24 	
25   	// Put the help line at the beginning
26   	cmd.info(help);
27 
28   	cmd.addText("\nArguments:");
29   	cmd.addRCmdArg("x", &x, "x");
30   	cmd.addRCmdArg("y", &y, "y");
31   	cmd.addRCmdArg("xc", &xc, "xc");
32   	cmd.addRCmdArg("yc", &yc, "yc");
33   	cmd.addRCmdArg("angle", &angle, "ccw angle in degree");
34   	cmd.addText("\nOptions:");
35   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
36 
37 	cmd.read(argc, argv);
38 
39 	//
40 	RotationMatrix2D r(angle);
41 	print("rotation matrix = %s\n", r.sprint());
42 
43 	//
44 	Vector2D v(xc, yc);
45 	print("translation vector = %s\n", v.sprint());
46 
47 	//
48 	Affine2D affine(r, v);
49 
50 	//
51 	Vector2D X(x, y);
52 	print("X = %s\n", X.sprint());
53 
54 	Vector2D X_(0, 0);
55 
56 	//
57 	X_ = affine * X;
58 	print("X' = %s\n", X_.sprint());
59 
60 	//
61 	Vector2D w(xc, xc);
62 	print("translation vector = %s\n", w.sprint());
63 
64 	//
65 	X_ = X_ + w;
66 	print("X' + w = %s\n", X_.sprint());
67 
68 
69 	//
70 	RotationMatrix2D r_1(-angle);
71 	print("rotation matrix inverse = %s\n", r_1.sprint());
72 	
73 	//
74 	Affine2D affine_1(r_1, w);
75 
76 	print("X' + w = %s\n", X_.sprint());
77 	
78 	Vector2D X_1(0, 0);
79 	X_1 = affine_1 * X_;
80 	print("X_1 = %s\n", X_1.sprint());
81 	X_1 += v;
82 	print("X-1 + v = %s == %s\n", X_1.sprint(), X.sprint());
83 }