📄 testvector2d.cc
字号:
const char *help = "\progname: testVector2D.cc\n\code2html: This program tests Vector2D class methods.\n\version: Torch3 vision2.0, 2004-2005\n\(c) Dan Sunday (http:www.softsurfer.com) and Sebastien Marcel (marcel@idiap.ch)\n";#include "general.h"#include "Point2D.h"#include "Vector2D.h"#include "CmdLine.h"using namespace Torch;int main(int argc, char **argv){ real x1, y1; real x2, y2; bool verbose; // Construct the command line CmdLine cmd; cmd.setBOption("write log", false); // Put the help line at the beginning cmd.info(help); cmd.addText("\nArguments:"); cmd.addRCmdArg("x1", &x1, "x1"); cmd.addRCmdArg("y1", &y1, "y1"); cmd.addRCmdArg("x2", &x2, "x2"); cmd.addRCmdArg("y2", &y2, "y2"); cmd.addText("\nOptions:"); cmd.addBCmdOption("-verbose", &verbose, false, "verbose"); cmd.read(argc, argv); double a, c[3]; Vector2D u, v(1, 0), w(0,1); Vector2D vx[3]; // output preset coords of v and w print("Initial v = %s\n", v.sprint()); print("Initial w = %s\n", w.sprint()); // input new values v.x = x1; v.y = y1; w.x = x2; w.y = y2; print("v = %s\n", v.sprint()); print("w = %s\n", w.sprint()); // test operators u = -v; print("-v = %s\n", u.sprint()); u = ~v; print("~v = %s\n", u.sprint()); u = 2*v; print("2*v = %s\n", u.sprint()); u = v + w; print("v + w = %s\n", u.sprint()); u = (v + w)/2; print("(v + w)/2 = %s\n", u.sprint()); u = v - w; print("v - w = %s\n", u.sprint()); u = (v - w)*0.5; print("(v - w)*0.5 = %s\n", u.sprint()); a = v * w; print("v * w = %g\n", a); a = v | w; print("v | w = %g\n", a); a = ~v * w; print("~v * w = %g\n", a); print("\n"); // test functions c[0]= 0.5; c[1]= 0.5; print("c[]= {%g, %g}\n", c[0], c[1]); vx[0]= v; vx[1]= w; print("vx[]= {%s, %s}\n", vx[0].sprint(), vx[1].sprint()); u = sum(2,c,vx); print("sum(2,c,vx) = %s\n", u.sprint()); u = v.len2(); print("v.len2() = %s\n", u.sprint()); u = v.len(); print("v.len() = %s\n", u.sprint()); v.normalize(); print("v.normalize() = %s\n", v.sprint()); w.normalize(); print("w.normalize() = %s\n", w.sprint()); print("\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -