rotate.cc

 1 const char *help = "\
 2 progname: rotation.cc\n\
 3 code2html: This program tests rotation.\n\
 4 version: Torch3 vision2.0, 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 "Vector2D.h"
11 #include "Rectangle2D.h"
12 #include "CmdLine.h"
13 
14 using namespace Torch;
15 
16 int main(int argc, char **argv)
17 {
18  	int x, y, w, h;
19 	int xc, yc;
20 	real angle;
21 	bool verbose;
22 
23 	// Construct the command line
24   	CmdLine cmd;
25 	cmd.setBOption("write log", false);
26 	
27   	// Put the help line at the beginning
28   	cmd.info(help);
29 
30   	cmd.addText("\nArguments:");
31   	cmd.addICmdArg("x", &x, "x");
32   	cmd.addICmdArg("y", &y, "y");
33   	cmd.addICmdArg("w", &w, "w");
34   	cmd.addICmdArg("h", &h, "h");
35   	cmd.addICmdArg("xc", &xc, "xc");
36   	cmd.addICmdArg("yc", &yc, "yc");
37   	cmd.addRCmdArg("angle", &angle, "ccw angle in degree");
38   	cmd.addText("\nOptions:");
39   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
40 
41 	cmd.read(argc, argv);
42 
43 
44 	//
45 	RotationMatrix2D rot(angle);
46 	print("rotation matrix (M) = %s\n", rot.sprint());
47 	
48 	//
49 	Vector2D v(xc, yc);
50 	print("center of rotation (T) = %s\n", v.sprint());
51 
52 	//
53 	Affine2D affine(rot, v);
54 
55 	//
56 	Rectangle2D r(x, y, w, h);
57 	print("rectangle (R) = %s\n", r.sprint());
58 
59 	Rectangle2D r2;
60 	
61 	r2 = affine * r + v;
62 	print("rotated rectangle R * (M-T) + T = %s\n\n", r2.sprint());
63 
64 }