Geometry.h
Go to the documentation of this file.
1 /*
2 * ==========================================================================
3 * This file is part of the implementation of
4 *
5 * <FrameFab: Robotic Fabrication of Frame Shapes>
6 * Yijiang Huang, Juyong Zhang, Xin Hu, Guoxian Song, Zhongyuan Liu, Lei Yu, Ligang Liu
7 * In ACM Transactions on Graphics (Proc. SIGGRAPH Asia 2016)
8 ----------------------------------------------------------------------------
9 * class: Geometry
10 *
11 * Description: this file defines some basic geomerty data structure and operation.
12 *
13 * Version: 2.0
14 * Created: Oct/20/2015
15 *
16 * Author: Xin Hu, Yijiang Huang, Guoxian Song
17 * Company: GCL@USTC
18 * Citation: This file use some geometric API and objects from
19 * Title: Geometric Tools Engine
20 * a library of source code for computing in the fields of
21 * mathematics, graphics, image analysis, and physics.
22 * Code Version: 3.2.6
23 * Availability: http://www.geometrictools.com/index.html
24 ----------------------------------------------------------------------------
25 * Copyright (C) 2016 Yijiang Huang, Xin Hu, Guoxian Song, Juyong Zhang
26 * and Ligang Liu.
27 *
28 * FrameFab is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
32 *
33 * FrameFab is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 *
38 * You should have received a copy of the GNU General Public License
39 * along with FrameFab. If not, see <http://www.gnu.org/licenses/>.
40 * ==========================================================================
41 */
42 
43 #pragma once
44 
45 #include <cmath>
46 #include <iostream>
49 
50 using std::cout;
51 
52 namespace Geometry
53 {
54  //basic geomertical settings
55  // the toleration of error
56 
57  /* upper bound */
58  static double inf = 10000000;
59 
60  /* lower bound */
61  static double ninf = -10000000;
62 
63  /* Vector class in 3 dimension euclidean space */
64  class Vector3d
65  {
66  public:
67  Vector3d(double x = 0, double y = 0, double z = 0)
68  {
69  data_[0] = x;
70  data_[1] = y;
71  data_[2] = z;
72  }
73 
75  {
76  data_[0] = o.x();
77  data_[1] = o.y();
78  data_[2] = o.z();
79  }
80 
82  {
83  data_[0] = end.x()-start.x();
84  data_[1] = end.y()-start.y();
85  data_[2] = end.z()-start.z();
86  }
88 
89  public:
90  double getX(){ return data_[0]; }
91  double getY(){ return data_[1]; }
92  double getZ(){ return data_[2]; }
93  double *data(){ return data_; }
94 
95  public:
97  {
98  return Vector3d(data_[0] + b.data_[0], data_[1] + b.data_[1], data_[2] + b.data_[2]);
99  }
100 
102  {
103  return Vector3d(data_[0] - b.data_[0], data_[1] - b.data_[1], data_[2] - b.data_[2]);
104  }
105 
107  {
108  return Vector3d(data_[0] * k, data_[1] * k, data_[2] * k);
109  }
110 
111  double operator[] (int k)
112  {
113  if (0 <= k && k < 3)
114  return data_[k];
115  else
116  return 0;
117  }
118 
119  public:
120  double norm()
121  {
122  return sqrt(data_[0] * data_[0] + data_[1] * data_[1] + data_[2] * data_[2]);
123  }
124  void normalize()
125  {
126  double length = norm();
127  if (length > GEO_EPS)
128  {
129  for (int i = 0; i < 3; i++)
130  data_[i] /= length;
131  }
132  else
133  {
134  cout << "error:zero vector cannnot be normalized";
135  }
136  }
137 
138  private:
139  double data_[3];
140  };
141 
142  /* For Vector3d(dot product) */
144  {
145  double u[3] = { vec1.getX(), vec1.getY(), vec1.getZ() };
146  double v[3] = { vec2.getX(), vec2.getY(), vec2.getZ() };
147  return Vector3d(u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]);
148  }
149 
150  /* For Vector3d(cross product) */
151  static double dot(Vector3d vec1, Vector3d vec2)
152  {
153  double u[3] = { vec1.getX(), vec1.getY(), vec1.getZ() };
154  double v[3] = { vec2.getX(), vec2.getY(), vec2.getZ() };
155  return u[0] * v[0] + u[1] * v[1] + u[2] * v[2];
156  }
157 
158  static double angle(Vector3d vec1, Vector3d vec2)
159  {
160  double temp = 0;
161  temp = dot(vec1, vec2) / (vec1.norm()*vec2.norm());
162  //--------------------------
163  if (abs(temp - 1) < GEO_EPS)
164  return 0;
165  if (abs(temp + 1) < GEO_EPS)
166  return 3.1415;
167 
168  return acos(temp);
169  }
170 
171  /* For Vector3d
172  * suppose i = (1,0,0), j = (0,1,0),k = (0,0,1),O =(0,0,0)
173  * and point is in the coordinate system E1={O;i,j,k}
174  * and we have another coordinate system E2={O;coord[1],coord[2],coord[3]};
175  * then we can use the point's coordination in E1 to compute the point's coordination in the E2
176  */
177 
179  {
180  double result[3] = { 0, 0, 0 };
181  for (int i = 0; i < 3; i++)
182  {
183  for (int j = 0; j < 3; j++)
184  {
185  result[i] += point[j] * (coord[i])[j];
186  }
187  }
188  point = Geometry::Vector3d(result[0], result[1], result[2]);
189  }
190 
192  {
193  double result[3] = { 0, 0, 0 };
194  for (int i = 0; i < 3; i++)
195  {
196  for (int j = 0; j < 3; j++)
197  {
198  result[i] += point[j] * (coord[i])[j];
199  }
200  }
201  point = Geometry::Vector3d(result[0], result[1], result[2]);
202  point = point - origin;
203  }
204 }
#define GEO_EPS
Definition: GCommon.h:62
Vector3d operator-(const Vector3d &b)
Definition: Geometry.h:101
double getY()
Definition: Geometry.h:91
GLuint start
Vec< 2, float > vec2
Definition: Vec.h:555
static double angle(Vector3d vec1, Vector3d vec2)
Definition: Geometry.h:158
reference x()
Definition: Vec.h:194
GLuint coord
GLint GLenum GLint x
Vector3d(point start, point end)
Definition: Geometry.h:81
double data_[3]
Definition: Geometry.h:139
static double inf
Definition: Geometry.h:58
GLuint GLuint end
Vector3d operator*(double k)
Definition: Geometry.h:106
Vector3d(point o)
Definition: Geometry.h:74
Vector3d operator+(const Vector3d &b)
Definition: Geometry.h:96
reference y()
Definition: Vec.h:203
GLboolean GLboolean GLboolean b
static void changeCoordinate(Vector3d &point, Vector3d coord[3])
Definition: Geometry.h:178
static trimesh::Vec< D, T > abs(const trimesh::Vec< D, T > &v)
Definition: Vec.h:1193
GLuint GLsizei GLsizei * length
GLdouble GLdouble GLdouble z
Vector3d(double x=0, double y=0, double z=0)
Definition: Geometry.h:67
double getX()
Definition: Geometry.h:90
const GLdouble * v
double getZ()
Definition: Geometry.h:92
double operator[](int k)
Definition: Geometry.h:111
static double ninf
Definition: Geometry.h:61
static double dot(Vector3d vec1, Vector3d vec2)
Definition: Geometry.h:151
reference z()
Definition: Vec.h:212
static Vector3d cross(Vector3d vec1, Vector3d vec2)
Definition: Geometry.h:143
GLuint64EXT * result
GLint y
double * data()
Definition: Geometry.h:93


choreo_task_sequence_planner
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:03:14