Points&Forces (survey)
Software tools facilitating the task of surveying architecture
a_wrench.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2010-2016 Pierre SMARS (smars@yuntech.edu.tw)
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, either version 2 of the License, or
6 (at your option) any later version.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 //#include <math.h> // math routines
17 
18 #include "a_wrench.h"
19 #include "a_debug.h"
20 
21 const double verysmall=1.e-8;
22 //---------------------------------------------------------------------------
23 // f:(fx, fy, fz) is a force applied in point p:(x, y, z)
24 // m is a moment around f applied in p
25 // p_1 is the equivalent force applied at the origin
26 // p_2 is the equivalent moment applied at the origin
27 //---------------------------------------------------------------------------
28 const std::string a_wrench::help()
29 {
30  std::ostringstream o;
31  o << "*********" << std::endl;
32  o << "a_wrench:" << std::endl;
33  o << "*********" << std::endl;
34  o << "This class is used to model a wrench: force + moment" << std::endl;
35  o << "Commands:" << std::endl;
36  o << "--------" << std::endl;
37  o << "a_wrench W 'p' 'f' ('m'): create a wrench by applying force 'f' at point 'p', possibly with a moment having the same direction of 'f'" << std::endl;
38  o << "a_wrench W 'x' 'y' 'z' 'fx' 'fy' 'fz' ('m'): idem above" << std::endl;
39  o << "a_wrench W 'p1' 'p2' 'p3' 'w1' 'w2': create a wrench at p1 such that m=0 at p1, torque//normal plane (p1,p2,p3)=0 at p2 & p3, w1 applied between p1 and p2, w2 between p2 and p3" << std::endl;
40  o << "" << std::endl;
41  o << "set 'p' 'f' ('m'): apply force 'f' at point 'p', possibly with a moment having the same direction of 'f'" << std::endl;
42  o << "set 'x' 'y' 'z' 'fx' 'fy' 'fz' ('m'): idem above" << std::endl;
43  o << "print: print the six values of the force and moment" << std::endl;
44  o << "F: returns the force (vector)" << std::endl;
45  o << "fx: returns x component of the force" << std::endl;
46  o << "fy: returns y component of the force" << std::endl;
47  o << "fz: returns z component of the force" << std::endl;
48  o << "f: returns norm of the force" << std::endl;
49  o << "M: returns the moment (vector)" << std::endl;
50  o << "mx: returns x component of the moment" << std::endl;
51  o << "my: returns y component of the moment" << std::endl;
52  o << "mz: returns z component of the moment" << std::endl;
53  o << "m: returns norm of the moment" << std::endl;
54  o << "clear: clear the wrench" << std::endl;
55  o << "origin 'a_point': change the origin of the coordinate system" << std::endl;
56  o << "d0: point where wrench reduces to a pure force, return origin if f=0" << std::endl;
57  o << "torque 'p': gets torque at point 'p' (a_point)" << std::endl;
58  o << "torque 'p' 'n': gets torque at 'p', in direction 'n'" << std::endl;
59  o << "pierce 'a_plane': find the point of interesction of the wrench with the plane" << std::endl;
60  o << "" << std::endl;
61  o << "If 'w1' and 'w2' are two wrenches" << std::endl;
62  o << "w1 + w1: returns the sum of the two wrenches" << std::endl;
63  o << "w1 - w1: returns the difference of the two wrenches" << std::endl;
64  o << "-w1: sreturns the inverse of 'w1'" << std::endl;
65  return o.str();
66 }
67 //---------------------------------------------------------------------------
68 void a_wrench::set(const a_point& p, a_point f, double m)
69 {
70  p1_ = f;
71  a_point m0 = f.normalise()*m;
72  p2_ = cross(p,p1_)+m0;
73 }
74 //---------------------------------------------------------------------------
75 void a_wrench::set(double x, double y, double z, double fx, double fy, double fz, double m)
76 {
77  a_point p(x,y,z);
78  a_point f(fx,fy,fz);
79  this->set(p,f,m);
80 }
81 //---------------------------------------------------------------------------
82 a_wrench::a_wrench(const a_point & p, a_point f, double m)
83 {
84  this->set(p,f,m);
85 }
86 //---------------------------------------------------------------------------
87 a_wrench::a_wrench(double x, double y, double z, double fx, double fy, double fz, double m)
88 {
89  a_point p(x,y,z);
90  a_point f(fx,fy,fz);
91  this->set(p,f,m);
92 }
93 //---------------------------------------------------------------------------
94 a_wrench::a_wrench(const a_point& p1, const a_point& p2, const a_point& p3,
95  const a_wrench& f1, const a_wrench& f2)
96 {
97  a_point d2 = p2-p1;
98  a_point d3 = p3-p1;
100  a_point u = d3.normalise();
102  a_point n = cross(u,d2).normalise();
103  a_point v = cross(n,u).normalise();
105  a_wrench ft = f1;
106  ft += f2;
108  double t2n = f1.torque(p2,n);
109 // double t2u = f1.torque(p2,u);
110 // double t2v = f1.torque(p2,v);
111  double t3n = ft.torque(p3,n);
112 // double t3u = ft.torque(p3,u);
113 // a_point tt2 = f1.torque(p2);
114 // a_point tt3 = ft.torque(p3);
115  double du = dist(p1,p3);
117  double fv = t3n/du;
119  double u2 = d2*u;
120  double v2 = d2*v;
122  double fu = -(t2n-u2*fv)/v2;
123  p1_ = u*fu+v*fv;
125  p2_ = cross(p1,p1_);
126 }
127 //---------------------------------------------------------------------------
128 void a_wrench::origin(a_point p)
129 {
130  //force does not change
131  //new moment
132  p2_ -= cross(p,p1_);
133 }
134 //---------------------------------------------------------------------------
135 a_point a_wrench::pierce(const a_plane& p) const
136 {
137  a_point x1 = this->d0();
138  a_point x2 = x1+p1_;
139  a_segment s(x1,x2);
140  a_point x = p.intersect(s);
141  return x;
142 }
143 //---------------------------------------------------------------------------
144 a_point a_wrench::d0() const
145 {
147  //f=0 does not matter where is point of application
148  if (this->f()==0.)
149  return a_point(0.,0.,0.);
150  a_point f = p1_;
151  double m = this->m();
152  a_point dm = p2_;
153  dm.normalise();
154  //component of force along torque axis
155  a_point fl = (dm*f)*dm;
156  //component of force perpendicular to torque, can be used to reduce it
157  a_point fp = f-fl;
158  double fps = fp.norm();
159  //force is parallel to torque (and necessarily passes by origin)
160  if (fps < verysmall)
161  return a_point(0.,0.,0.);
162  fp.normalise();
163  return cross(fp,dm)*(m/fps);
164 }
165 //---------------------------------------------------------------------------
166 a_point a_wrench::torque(const a_point& p) const
167 {
168  return cross(p1_,p)+p2_;
169 }
170 //---------------------------------------------------------------------------
171 double a_wrench::torque(const a_point& p, const a_point& n) const
172 {
173  a_point n2 = n;
174  n2.normalise();
175  return (this->torque(p))*n2;
176 }
177 
const double verysmall
Definition: a_wrench.cxx:21
a_point p1_
Definition: a_plucker.h:63
a_point p2_
Definition: a_plucker.h:64
a_point p2() const
Definition: a_plucker.h:42
a_point p1() const
Definition: a_plucker.h:41
a wrench class
Definition: a_wrench.h:30
void set(const a_point &p, a_point f, double m=0)
apply a force f at p, possibly with a moment having same direction
Definition: a_wrench.cxx:68
double fx() const
force at the origin (x component)
Definition: a_wrench.h:53
double fz() const
force at the origin (z component)
Definition: a_wrench.h:57
double f() const
force at the origin
Definition: a_wrench.h:67
static const std::string help()
get information about the class
Definition: a_wrench.cxx:28
a_point torque(const a_point &p) const
torque at p
Definition: a_wrench.cxx:166
double fy() const
force at the origin (y component)
Definition: a_wrench.h:55
void origin(a_point p)
change origin
Definition: a_wrench.cxx:128
a_point d0() const
point where wrench reduces to a pure force, return origin if f=0
Definition: a_wrench.cxx:144
a_point pierce(const a_plane &p) const
intersection with a plane
Definition: a_wrench.cxx:135
double m() const
torque at the origin
Definition: a_wrench.h:69
a_wrench()
Definition: a_wrench.h:32