NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AppLineInsertionCheck.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
26 #include "tgcreator/tgUtil.h"
27 
28 // The Bullet Physics Library
29 #include "LinearMath/btScalar.h"
30 #include "LinearMath/btVector3.h"
31 #include "LinearMath/btQuaternion.h"
32 // The C++ Standard Library
33 #include <iostream>
34 #include <cmath>
35 
42 int main(int argc, char** argv)
43 {
44  btVector3 point1(atof(argv[1]), atof(argv[2]), atof(argv[3]));
45  btVector3 point2(atof(argv[4]), atof(argv[5]), atof(argv[6]));
46 
47  btVector3 point3(atof(argv[7]), atof(argv[8]), atof(argv[9]));
48 #if (1)
49  btVector3 normal(atof(argv[10]), atof(argv[11]), atof(argv[12]));
50 #else
51  btVector3 point4(0.0, 0.0, 0.0);
52 #endif
53  std::cout << point1 << " " << point2 << " " << point3 << std::endl;
54 
55  std::cout << "new point " << (point3 - point1).dot(point2) << std::endl;
56  std::cout << "old point " << (point3 - point1).dot(point3) << std::endl;
57 
58  btVector3 lineA = point3 - point2;
59  btVector3 lineB = point1 - point2;
60 
61  normal.normalize();
62 
63 #if (1)
64  btVector3 tangentDir =( (lineB - lineA).cross(normal)).normalize();
65  btVector3 tangentMove = (lineB + lineA).dot(tangentDir) * tangentDir / 2.0;
66  btVector3 newPos = point2 + tangentMove;
67 
68  std::cout << "tangentDir " << tangentDir << std::endl;
69  std::cout << "tangentMove " << tangentMove << std::endl;
70  std::cout << "newPos " << newPos << std::endl;
71 #else
72  btQuaternion q1 = tgUtil::getQuaternionBetween(lineA, normal);
73  btQuaternion q2 = tgUtil::getQuaternionBetween(normal, lineB);
74  btQuaternion q3 = tgUtil::getQuaternionBetween(lineB, lineA);
75 
76  btVector3 lineACopy = lineA;
77  btVector3 lineBCopy = lineB;
78  btVector3 ab = lineA + lineB;
79  btVector3 abNorm = (lineACopy.normalize() + lineBCopy.normalize()).normalize();
80 
81  // Project normal into AB plane
82  btVector3 AN = lineA.dot(normal) * lineACopy.normalize();
83  btVector3 BN = lineB.dot(normal) * lineBCopy.normalize();
84  btVector3 normalProjection = abNorm.dot(normal) * abNorm;
85 
86  normalProjection.normalize();
87 
88  std::cout << "lineA Norm: " << lineACopy << std::endl;
89  std::cout << "lineB Norm: " << lineBCopy << std::endl;
90  std::cout << "Normal: " << normal << std::endl;
91  std::cout << "Projection: " << normalProjection << std::endl;
92  std::cout << "Angle AN: " << lineA.angle(normalProjection) << std::endl;
93  std::cout << "Angle BN " << lineB.angle(normalProjection) << std::endl;
94  std::cout << "Sum AN + BN " << lineA.angle(normalProjection) + lineB.angle(normalProjection) << std::endl;
95  std::cout << "Angle AB " << lineA.angle(lineB) << std::endl;
96 
97  std::cout << "Angle normal w/ x axis " << btVector3(1.0, 0.0, 0.0).angle(normal) << std::endl;
98  std::cout << "Angle lineA w/ x axis " << btVector3(1.0, 0.0, 0.0).angle(lineA) << std::endl;
99  std::cout << "Angle lineB w/ x axis " << btVector3(1.0, 0.0, 0.0).angle(lineB) << std::endl;
100 
101  std::cout << "Traditional: " << lineA.dot(normal) << " " << lineB.dot(normal) << std::endl;
102 
103 #endif
104  return 0;
105 }
int main(int argc, char **argv)
static btQuaternion getQuaternionBetween(btVector3 a, btVector3 b)
Definition: tgUtil.h:196
Contains the definition of class tgUtil and overloaded operator<<() free functions.