drawLineArea.cpp
00001
00002
00003
00004
00005
00006
00007 #include "vmonitor.h"
00008
00009
00010 int main(int argc, char *argv[]) {
00011 try {
00012 vmonitor::show();
00013 vmonitor::setViewMagnify(1.0);
00014
00015 VXV::Grid p0(0, 0);
00016 VXV::Grid p1(100, 0);
00017 enum { Error = 30 };
00018
00019 std::vector<VXV::Grid3D> points;
00020 points.push_back(p0);
00021 points.push_back(p1);
00022
00023
00024 vmonitor::drawPoints(points, Red);
00025
00026
00027 vmonitor::drawCircle(p0, Error, Blue);
00028 vmonitor::drawCircle(p1, Error, Blue);
00029
00030
00031
00032 VXV::Grid c = p0 + p1;
00033 c.x >>= 1;
00034 c.y >>= 1;
00035 vmonitor::printf("center: %d, %d\n", c.x, c.y);
00036
00037
00038 VXV::Grid diff = p1 - p0;
00039 int l = static_cast<int>(sqrt(diff.x * diff.x + diff.y * diff.y));
00040 vmonitor::printf("length: %d\n", l);
00041
00042 int base = static_cast<int>(sqrt((l/2) * (l/2) - Error * Error));
00043 vmonitor::printf("base: %d\n", base);
00044
00045 double theta = atan2(Error, base);
00046 vmonitor::printf("theta: %d [deg]\n", static_cast<int>(theta /M_PI*180.0));
00047
00048
00049 enum { LineLength = 200 };
00050
00051 VXV::Grid p(c.x + LineLength * cos(theta), c.y + LineLength * sin(theta));
00052 vmonitor::drawLine(c, p, Red);
00053
00054 p = VXV::Grid(c.x + LineLength * cos(-theta),
00055 c.y + LineLength * sin(-theta));
00056 vmonitor::drawLine(c, p, Red);
00057
00058 getchar();
00059 } catch (std::exception& e) {
00060 printf("exception: %s\n", e.what());
00061 }
00062 return 0;
00063 }
00064