angles2D.cc

 1 const char *help = "\
 2 progname: angles2D.cc\n\
 3 code2html: This program tests angle 2D functions.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "general.h"
 8 #include "Point2D.h"
 9 #include "Vector2D.h"
10 #include "Triangle2D.h"
11 #include "CmdLine.h"
12 
13 using namespace Torch;
14 
15 int main(int argc, char **argv)
16 {
17  	real x1, y1;
18  	real x2, y2;
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("x1", &x1, "x1");
30   	cmd.addRCmdArg("y1", &y1, "y1");
31   	cmd.addRCmdArg("x2", &x2, "x2");
32   	cmd.addRCmdArg("y2", &y2, "y2");
33   	cmd.addText("\nOptions:");
34   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
35 
36 	cmd.read(argc, argv);
37 
38 	Point2D X(x1, y1);
39 	Point2D Y(x2, y2);
40 
41 	// output preset coords of v and w
42 	print("X = %s\n", X.sprint());
43 	print("Y = %s\n", Y.sprint());
44 	print("\n");
45 
46 	///
47 	Vector2D VX(X.x, X.y);
48 	print("VX = %s\n", VX.sprint());
49 	double angleVrad = VX.angle();
50 	double angleVdeg = radian2degree(angleVrad);
51 	print("angle VX = %g radians (%g degrees)\n", angleVrad, angleVdeg);
52 
53 	Vector2D VY(Y.x, Y.y);
54 	print("VY = %s\n", VY.sprint());
55 	angleVrad = VY.angle();
56 	angleVdeg = radian2degree(angleVrad);
57 	print("angle VY = %g radians (%g degrees)\n\n", angleVrad, angleVdeg);
58 
59 	///
60 	double angleXYrad = angle(X, Y);
61 	double angleXYdeg = radian2degree(angleXYrad);
62 	print("angle XY = %g radians (%g degrees)\n", angleXYrad, angleXYdeg);
63 	
64 	angleXYrad = angle(Y, X);
65 	angleXYdeg = radian2degree(angleXYrad);
66 	print("angle YX = %g radians (%g degrees)\n\n", angleXYrad, angleXYdeg);
67 	
68 	//
69 	Point2D O(0, 0);
70 	Triangle2D T1(O, X, Y);
71 	print("T = {%s, %s, %s}\n", O.sprint(), X.sprint(), Y.sprint());
72 	double angleTrad = T1.angle();
73 	double angleTdeg = radian2degree(angleTrad);
74 	int ccw_ = T1.ccw();
75 	char orientation[100];
76 
77 	if(ccw_ == 0) sprintf(orientation, "none");
78 	else if(ccw_ > 0) sprintf(orientation, "ccw");
79 	else sprintf(orientation, "cw");
80 
81 	print("angle T = %g radians (%g degrees) with %s orientation\n", angleTrad, angleTdeg, orientation);
82 	
83 	Triangle2D T2(O, Y, X);
84 	print("T = {%s, %s, %s}\n", O.sprint(), Y.sprint(), X.sprint());
85 	angleTrad = T2.angle();
86 	angleTdeg = radian2degree(angleTrad);
87 	ccw_ = T2.ccw();
88 
89 	if(ccw_ == 0) sprintf(orientation, "none");
90 	else if(ccw_ > 0) sprintf(orientation, "ccw");
91 	else sprintf(orientation, "cw");
92 
93 	print("angle T = %g radians (%g degrees) with %s orientation\n\n", angleTrad, angleTdeg, orientation);
94 	
95 }